(feat)completions: separate completion history (#1901)

* (fix) Use read-from-minibuffer instead of completing-read where appropriate

* (feat) Add separate node and ref completion histories

Using separate histories has the advantage that the history only contains node
names and no other strings from other unrelated minibuffer completions.
This commit is contained in:
Daniel Mendler
2021-10-13 06:47:19 +02:00
committed by GitHub
parent 4af5ff662e
commit f80515ab5f
2 changed files with 10 additions and 4 deletions

View File

@ -741,7 +741,7 @@ also run Org-capture's template expansion."
(funcall node-fn org-roam-capture--node)) (funcall node-fn org-roam-capture--node))
((plist-get org-roam-capture--info ksym) ((plist-get org-roam-capture--info ksym)
(plist-get org-roam-capture--info ksym)) (plist-get org-roam-capture--info ksym))
(t (let ((r (completing-read (format "%s: " key) nil nil nil default-val))) (t (let ((r (read-from-minibuffer (format "%s: " key) default-val)))
(plist-put org-roam-capture--info ksym r) (plist-put org-roam-capture--info ksym r)
r)))))))) r))))))))

View File

@ -124,6 +124,12 @@ It takes a single argument REF, which is a propertized string.")
:group 'org-roam :group 'org-roam
:type 'string) :type 'string)
(defvar org-roam-node-history nil
"Minibuffer history of nodes.")
(defvar org-roam-ref-history nil
"Minibuffer history of refs.")
;;; Definition ;;; Definition
(cl-defstruct (org-roam-node (:constructor org-roam-node-create) (cl-defstruct (org-roam-node (:constructor org-roam-node-create)
(:copier nil)) (:copier nil))
@ -473,7 +479,7 @@ If REQUIRE-MATCH, the minibuffer prompt will require a match."
(get-text-property 0 'node title)))) (get-text-property 0 'node title))))
(category . org-roam-node)) (category . org-roam-node))
(complete-with-action action nodes string pred))) (complete-with-action action nodes string pred)))
nil require-match initial-input))) nil require-match initial-input 'org-roam-node-history)))
(or (cdr (assoc node nodes)) (or (cdr (assoc node nodes))
(org-roam-node-create :title node)))) (org-roam-node-create :title node))))
@ -855,7 +861,7 @@ If region is active, then use it instead of the node at point."
(funcall fn node)) (funcall fn node))
((fboundp node-fn) ((fboundp node-fn)
(funcall node-fn node)) (funcall node-fn node))
(t (let ((r (completing-read (format "%s: " key) nil nil nil default-val))) (t (let ((r (read-from-minibuffer (format "%s: " key) default-val)))
(plist-put template-info ksym r) (plist-put template-info ksym r)
r))))))) r)))))))
(file-path (read-file-name "Extract node to: " (file-path (read-file-name "Extract node to: "
@ -924,7 +930,7 @@ filtered out."
. ,org-roam-ref-annotation-function) . ,org-roam-ref-annotation-function)
(category . org-roam-ref)) (category . org-roam-ref))
(complete-with-action action refs string pred))) (complete-with-action action refs string pred)))
nil t initial-input))) nil t initial-input 'org-roam-ref-history)))
(cdr (assoc ref refs)))) (cdr (assoc ref refs))))
(defun org-roam-ref-read--completions () (defun org-roam-ref-read--completions ()