From 09b0d743594acd79a377000ae3f95f72c65ac21a Mon Sep 17 00:00:00 2001 From: Jethro Kuan Date: Sat, 10 Apr 2021 00:32:55 +0800 Subject: [PATCH] add ref --- org-roam-capture.el | 42 +++++++++++++++++++++--------------------- org-roam-protocol.el | 16 ++++++++-------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/org-roam-capture.el b/org-roam-capture.el index eaefdc8..8f4a096 100644 --- a/org-roam-capture.el +++ b/org-roam-capture.el @@ -149,11 +149,14 @@ This function is to be called in the Org-capture finalization process." "Add REF to the newly captured item." (let ((buf (org-capture-get :buffer)) (pos (org-capture-get :exact-position)) - orig-ref) + ref-lst) (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))))))) + (setq ref-lst (org-entry-get (point) "ROAM_REFS")) + (setq ref-lst (if ref-lst + (cl-pushnew ref-lst ref) + (list ref))) + (org-set-property "ROAM_REFS" (combine-and-quote-strings ref-lst)))))) (defun org-roam-capture--finalize () "Finalize the `org-roam-capture' process." @@ -305,23 +308,20 @@ you can catch it with `condition-case'." "Return exact point to file for org-capture-template. This function is used solely in Org-roam's capture templates: see `org-roam-capture-templates'." - (let* ((file-path - (cond ((assoc 'file org-roam-capture--info) - (cdr (assoc 'file org-roam-capture--info))) - ((assoc 'ref org-roam-capture--info) - (let ((ref (cdr (assoc 'ref org-roam-capture--info)))) - (if-let ((file ((caar (org-roam-db-query - [:select [file] - :from refs - :where (= ref $s1) - :limit 1] - ref))))) - file - (user-error "No such ref \"%s\"" ref)))) - (t - (when-let ((time (cdr (assoc 'time org-roam-capture--info)))) - (org-capture-put :default-time time)) - (org-roam-capture--new-file))))) + (when-let ((time (cdr (assoc 'time org-roam-capture--info)))) + (org-capture-put :default-time time)) + (let ((file-path + (cond ((assoc 'file org-roam-capture--info) + (cdr (assoc 'file org-roam-capture--info))) + ((assoc 'ref org-roam-capture--info) + (let ((ref (cdr (assoc 'ref org-roam-capture--info)))) + (or (caar (org-roam-db-query [:select [file] + :from refs + :where (= ref $s1) + :limit 1] ref)) + (org-roam-capture--new-file)))) + (t + (org-roam-capture--new-file))))) (org-capture-put :template (org-roam-capture--fill-template (org-capture-get :template))) (org-roam-capture--put :file-path file-path @@ -330,7 +330,7 @@ This function is used solely in Org-roam's capture templates: see (set-buffer (org-capture-target-buffer file-path)) (widen) (if-let* ((olp (org-roam-capture--get :olp))) - (condition-case errg + (condition-case err (when-let ((marker (org-roam-capture-find-or-create-olp olp))) (goto-char marker) (set-marker marker nil)) diff --git a/org-roam-protocol.el b/org-roam-protocol.el index 41a6038..2f1b329 100644 --- a/org-roam-protocol.el +++ b/org-roam-protocol.el @@ -77,14 +77,14 @@ It opens or creates a note with the given ref. (org-link-store-props :type type :link ref :annotation orglink - :initial body)) - (raise-frame) - (org-roam-capture--capture - :keys (cdr (assoc 'template decoded-alist)) - :info decoded-alist - :props (list :ref ref) - :templates org-roam-capture-ref-templates))) - nil) + :initial body) + (raise-frame) + (org-roam-capture--capture + :keys (cdr (assoc 'template decoded-alist)) + :info decoded-alist + :props (list :ref ref) + :templates org-roam-capture-ref-templates))) + nil)) (defun org-roam-protocol-open-file (info) "This handler simply opens the file with emacsclient.