mirror of
https://github.com/org-roam/org-roam
synced 2025-08-19 13:43:31 -05:00
[?] add ref...?
This commit is contained in:
@@ -65,11 +65,11 @@ TODO: Document this"
|
|||||||
)
|
)
|
||||||
|
|
||||||
(defcustom org-roam-capture-ref-templates
|
(defcustom org-roam-capture-ref-templates
|
||||||
'(list (list :key "r"
|
(list (list :key "r"
|
||||||
:desc "ref"
|
:desc "ref"
|
||||||
:body "%?"
|
:body "%?"
|
||||||
:file-path "${slug}.org"
|
:file-path "${slug}.org"
|
||||||
:head "#+title: ${title}\n#+roam_key: ${ref}" ;TODO: auto insert ref instead
|
:head "#+title: ${title}"
|
||||||
:unnarrowed t))
|
:unnarrowed t))
|
||||||
"The Org-roam templates used during a capture from the roam-ref protocol.
|
"The Org-roam templates used during a capture from the roam-ref protocol.
|
||||||
Details on how to specify for the template is given in `org-roam-capture-templates'."
|
Details on how to specify for the template is given in `org-roam-capture-templates'."
|
||||||
@@ -145,6 +145,16 @@ This function is to be called in the Org-capture finalization process."
|
|||||||
(org-with-point-at pos
|
(org-with-point-at pos
|
||||||
(org-id-get-create)))))
|
(org-id-get-create)))))
|
||||||
|
|
||||||
|
(defun org-roam-capture--add-ref (ref)
|
||||||
|
"Add REF to the newly captured item."
|
||||||
|
(let ((buf (org-capture-get :buffer))
|
||||||
|
(pos (org-capture-get :exact-position))
|
||||||
|
orig-ref)
|
||||||
|
(with-current-buffer buf
|
||||||
|
(org-with-point-at pos
|
||||||
|
(setq orig-ref (split-string-and-unquote (org-entry-get (point) "ROAM_REFS")))
|
||||||
|
(org-set-property "ROAM_REFS" (combine-and-quote-strings (cl-pushnew orig-ref ref)))))))
|
||||||
|
|
||||||
(defun org-roam-capture--finalize ()
|
(defun org-roam-capture--finalize ()
|
||||||
"Finalize the `org-roam-capture' process."
|
"Finalize the `org-roam-capture' process."
|
||||||
(let ((region (org-roam-capture--get :region))
|
(let ((region (org-roam-capture--get :region))
|
||||||
@@ -153,6 +163,8 @@ This function is to be called in the Org-capture finalization process."
|
|||||||
(org-roam-unshield-region (car region) (cdr region)))
|
(org-roam-unshield-region (car region) (cdr region)))
|
||||||
(unless org-note-abort
|
(unless org-note-abort
|
||||||
(setq id (org-roam-capture--finalize-create-id))
|
(setq id (org-roam-capture--finalize-create-id))
|
||||||
|
(when-let ((ref (org-roam-capture--get :ref)))
|
||||||
|
(org-roam-capture--add-ref ref))
|
||||||
(when-let ((finalize (org-roam-capture--get :finalize)))
|
(when-let ((finalize (org-roam-capture--get :finalize)))
|
||||||
(funcall (intern (concat "org-roam-capture--finalize-"
|
(funcall (intern (concat "org-roam-capture--finalize-"
|
||||||
(symbol-name (org-roam-capture--get :finalize))))
|
(symbol-name (org-roam-capture--get :finalize))))
|
||||||
@@ -356,18 +368,19 @@ properties to be added to the template."
|
|||||||
options
|
options
|
||||||
(list :org-roam org-roam-plist))))
|
(list :org-roam org-roam-plist))))
|
||||||
|
|
||||||
(cl-defun org-roam-capture--capture (&key goto keys info props)
|
(cl-defun org-roam-capture--capture (&key goto keys info props templates)
|
||||||
"Main entry point.
|
"Main entry point.
|
||||||
GOTO and KEYS correspond to `org-capture' arguments.
|
GOTO and KEYS correspond to `org-capture' arguments.
|
||||||
INFO is an alist for filling up Org-roam's capture templates.
|
INFO is an alist for filling up Org-roam's capture templates.
|
||||||
PROPS is a plist containing additional Org-roam properties for each template."
|
PROPS is a plist containing additional Org-roam properties for each template.
|
||||||
(let* ((org-capture-templates
|
TEMPLATES is a list of org-roam templates."
|
||||||
|
(let ((org-capture-templates
|
||||||
(mapcar (lambda (t)
|
(mapcar (lambda (t)
|
||||||
(org-roam-capture--convert-template t props))
|
(org-roam-capture--convert-template t props))
|
||||||
org-roam-capture-templates))
|
(or templates org-roam-capture-templates)))
|
||||||
(org-roam-capture--info info)
|
(org-roam-capture--info info))
|
||||||
(one-template-p (= (length org-capture-templates) 1)))
|
(when (and (not keys)
|
||||||
(when one-template-p
|
(= (length org-capture-templates) 1))
|
||||||
(setq keys (caar org-capture-templates)))
|
(setq keys (caar org-capture-templates)))
|
||||||
(org-capture goto keys)))
|
(org-capture goto keys)))
|
||||||
|
|
||||||
|
@@ -70,21 +70,20 @@ It opens or creates a note with the given ref.
|
|||||||
(title (or .title ""))
|
(title (or .title ""))
|
||||||
(body (or .body ""))
|
(body (or .body ""))
|
||||||
(orglink
|
(orglink
|
||||||
(org-link-make-string ref (or (org-string-nw-p title) ref))))
|
(org-link-make-string ref (or (org-string-nw-p title) ref)))
|
||||||
|
(org-capture-link-is-already-stored t))
|
||||||
(when org-roam-protocol-store-links
|
(when org-roam-protocol-store-links
|
||||||
(push (list ref title) org-stored-links))
|
(push (list ref title) org-stored-links))
|
||||||
(org-link-store-props :type type
|
(org-link-store-props :type type
|
||||||
:link ref
|
:link ref
|
||||||
:annotation orglink
|
:annotation orglink
|
||||||
:initial body)))
|
:initial body))
|
||||||
(let* ((org-roam-capture-templates org-roam-capture-ref-templates)
|
|
||||||
(org-roam-capture--info decoded-alist)
|
|
||||||
(org-capture-link-is-already-stored t)
|
|
||||||
(template (cdr (assoc 'template decoded-alist))))
|
|
||||||
(raise-frame)
|
(raise-frame)
|
||||||
;; TODO: FIX
|
(org-roam-capture--capture
|
||||||
(org-roam-capture--capture nil template)
|
:keys (cdr (assoc 'template decoded-alist))
|
||||||
(org-roam-message "Item captured.")))
|
:info decoded-alist
|
||||||
|
:props (list :ref ref)
|
||||||
|
:templates org-roam-capture-ref-templates)))
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
(defun org-roam-protocol-open-file (info)
|
(defun org-roam-protocol-open-file (info)
|
||||||
|
Reference in New Issue
Block a user