emacs-citar / citar-org-roam

citar/org-roam integration
GNU General Public License v3.0
101 stars 9 forks source link

better way to add citekey when creating note #8

Closed qingshuizheng closed 2 years ago

qingshuizheng commented 2 years ago

https://github.com/emacs-citar/citar-org-roam/blob/7920084d53087b1dff26a6664bcafc4841271579/citar-org-roam.el#L187-L190

Hi Bruce, thanks for the great package.

I found that the templates hardcodes "@{citekey}" in property drawers, which might cause bad alignment if users already have other configs related to property drawers:

image

Would it better to use the function 'org-roam-ref-add' at the end of the (let-form) instead?

From:

(defun citar-org-roam--create-capture-note (citekey entry)
    "Open or create org-roam node for CITEKEY and ENTRY."
   ;; adapted from https://jethrokuan.github.io/org-roam-guide/#orgc48eb0d
    (let ((title (citar-format--entry
                   citar-org-roam-note-title-template entry)))
     (org-roam-capture-
      :templates
      '(("r" "reference" plain "%?" :if-new
         (file+head
          ;; REVIEW not sure the file name shoud be citekey alone.
          "%(concat
 (when citar-org-roam-subdir (concat citar-org-roam-subdir \"/\")) \"${citekey}.org\")"
          ":PROPERTIES:
:ROAM_REFS: @${citekey}
:END:
 #+title: ${title}\n")
         :immediate-finish t
         :unnarrowed t))
      :info (list :citekey citekey)
      :node (org-roam-node-create :title title)
      :props '(:finalize find-file))))

To

(defun citar-org-roam--create-capture-note (citekey entry)
    "Open or create org-roam node for CITEKEY and ENTRY."
    ;; adapted from https://jethrokuan.github.io/org-roam-guide/#orgc48eb0d
    (let ((title (citar-format--entry
                  citar-org-roam-note-title-template entry)))
      (org-roam-capture-
       :templates
       '(("r" "reference" plain "%?" :if-new
          (file+head
           ;; REVIEW not sure the file name shoud be citekey alone.
           "%(concat
 (when citar-org-roam-subdir (concat citar-org-roam-subdir \"/\")) \"${citekey}.org\")"
           "#+title: ${title}\n")
          :immediate-finish t
          :unnarrowed t))
       :info (list :citekey citekey)
       :node (org-roam-node-create :title title)
       :props '(:finalize find-file))
      ;; add citekey with builtin function for better alignment
      (org-roam-ref-add (concat "@" citekey))))

Turns out better alignment: image

Edit 1: rewording.

Best, Zheng

bdarcus commented 2 years ago

Sure; care to submit a PR?

qingshuizheng commented 2 years ago

Sure; care to submit a PR?

I just did a PR, please have a check. Thanks!