From 91aae058105d5547b905a6e32b5115a934444a77 Mon Sep 17 00:00:00 2001 From: Philippe Crama Date: Mon, 22 Nov 2021 09:01:02 +0100 Subject: [PATCH] (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. --- org-roam-capture.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/org-roam-capture.el b/org-roam-capture.el index 5fb79bb..77a35fd 100644 --- a/org-roam-capture.el +++ b/org-roam-capture.el @@ -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 ()