mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(minor)capture: avoid surprises when STUFF contains the same key twice (#1961)
See also the discussion in #1961. The summary is that if STUFF contained the same key twice, `org-roam-capture--put' would favor the last setting in STUFF while normally `plist-get' and `plist-put' use the first key/value pair of a plist: (let ((org-capture-plist nil) (stuff (list :z 26 :z "ignored"))) (apply 'org-roam-capture--put stuff) (list (plist-get stuff :z) (org-roam-capture--get :z))) ; old implementation => (26 "ignored") ; new implementation => Lisp error: wrong-number-of-arguments In elisp, plists are defined as having no duplicate keys, but there are no (costly?) runtime checks against this happening by accident. OTOH, `org-roam-capture--put' is only ever called with one key/value pair: we can afford to restrict its interface to accept only one key/value pair and then there can never be duplicate keys in its input.
This commit is contained in:
@ -445,13 +445,13 @@ the capture)."
|
||||
"Get the value for KEYWORD from the `org-roam-capture-template'."
|
||||
(plist-get (plist-get org-capture-plist :org-roam) keyword))
|
||||
|
||||
(defun org-roam-capture--put (&rest stuff)
|
||||
"Put properties from STUFF into the `org-roam-capture-template'."
|
||||
(defun org-roam-capture--put (prop value)
|
||||
"Set property PROP to VALUE in the `org-roam-capture-template'."
|
||||
(let ((p (plist-get org-capture-plist :org-roam)))
|
||||
(while stuff
|
||||
(setq p (plist-put p (pop stuff) (pop stuff))))
|
||||
(setq org-capture-plist
|
||||
(plist-put org-capture-plist :org-roam p))))
|
||||
(plist-put org-capture-plist
|
||||
:org-roam
|
||||
(plist-put p prop value)))))
|
||||
|
||||
;;;; Capture target
|
||||
(defun org-roam-capture--prepare-buffer ()
|
||||
|
Reference in New Issue
Block a user