(fix)completion: minor fixes around completing-read (#1893)

* (fix)org-roam-node-default-sort: Add choice nil

* (fix)Ensure that annotation functions are compiled

* (fix)org-roam-node-read: Preserve sorting if sort-fn is non-nil

If the nodes are sorted by org-roam we don't want the completion UI to change
the order. In order to disable org-roam sorting set org-roam-node-default-sort
to nil. Then the sorting of the completion UI is used.

* (fix)org-roam-graph--build: Use ephermeral buffer name

Ephemeral buffers are hidden by default in the completion lists,
which is usually desired for background processes.

* (fix)capfs: Do not use completion-table-dynamic

completion-table-dynamic serves a different purpose. it should only be used if
the candidates are dynamically generated based on the input. This is not the
case for org-roam where we the list of nodes is already available right at the
beginning of the completion. This change should improve performance.
This commit is contained in:
Daniel Mendler
2021-10-10 13:37:57 +02:00
committed by GitHub
parent 34243a0a90
commit 3a54182bb1
2 changed files with 20 additions and 18 deletions

View File

@@ -147,8 +147,8 @@ CALLBACK is passed the graph file as its sole argument."
(temp-graph (make-temp-file "graph." nil (concat "." org-roam-graph-filetype)))) (temp-graph (make-temp-file "graph." nil (concat "." org-roam-graph-filetype))))
(org-roam-message "building graph") (org-roam-message "building graph")
(make-process (make-process
:name "*org-roam-graph--build-process*" :name "*org-roam-graph*"
:buffer "*org-roam-graph--build-process*" :buffer " *org-roam-graph*"
:command `(,org-roam-graph-executable ,temp-dot "-T" ,org-roam-graph-filetype "-o" ,temp-graph) :command `(,org-roam-graph-executable ,temp-dot "-T" ,org-roam-graph-filetype "-o" ,temp-graph)
:sentinel (when callback :sentinel (when callback
(lambda (process _event) (lambda (process _event)

View File

@@ -76,7 +76,9 @@ It takes a single argument NODE, which is an `org-roam-node' construct."
(defcustom org-roam-node-default-sort 'file-mtime (defcustom org-roam-node-default-sort 'file-mtime
"Default sort order for Org-roam node completions." "Default sort order for Org-roam node completions."
:type '(choice (const :tag "file-mtime" file-mtime) :type '(choice
(const :tag "none" nil)
(const :tag "file-mtime" file-mtime)
(const :tag "file-atime" file-atime)) (const :tag "file-atime" file-atime))
:group 'org-roam) :group 'org-roam)
@@ -460,8 +462,13 @@ If REQUIRE-MATCH, the minibuffer prompt will require a match."
"Node: " "Node: "
(lambda (string pred action) (lambda (string pred action)
(if (eq action 'metadata) (if (eq action 'metadata)
'(metadata `(metadata
(annotation-function . (lambda (title) ;; Preserve sorting in the completion UI if a sort-fn is used
,@(when sort-fn
'((display-sort-function . identity)
(cycle-sort-function . identity)))
(annotation-function
. ,(lambda (title)
(funcall org-roam-node-annotation-function (funcall org-roam-node-annotation-function
(get-text-property 0 'node title)))) (get-text-property 0 'node title))))
(category . org-roam-node)) (category . org-roam-node))
@@ -695,9 +702,7 @@ We use this as a substitute for `org-link-bracket-re', because
start (match-beginning 2) start (match-beginning 2)
end (match-end 2)) end (match-end 2))
(list start end (list start end
(completion-table-dynamic (org-roam--get-titles)
(lambda (_)
(funcall #'org-roam--get-titles)))
:exit-function :exit-function
(lambda (str &rest _) (lambda (str &rest _)
(delete-char (- 0 (length str))) (delete-char (- 0 (length str)))
@@ -718,9 +723,7 @@ hence \"everywhere\"."
(not (save-match-data (org-in-regexp org-link-any-re)))) (not (save-match-data (org-in-regexp org-link-any-re))))
(let ((bounds (bounds-of-thing-at-point 'word))) (let ((bounds (bounds-of-thing-at-point 'word)))
(list (car bounds) (cdr bounds) (list (car bounds) (cdr bounds)
(completion-table-dynamic (org-roam--get-titles)
(lambda (_)
(funcall #'org-roam--get-titles)))
:exit-function :exit-function
(lambda (str _status) (lambda (str _status)
(delete-char (- (length str))) (delete-char (- (length str)))
@@ -915,10 +918,9 @@ filtered out."
(ref (completing-read "Ref: " (ref (completing-read "Ref: "
(lambda (string pred action) (lambda (string pred action)
(if (eq action 'metadata) (if (eq action 'metadata)
'(metadata `(metadata
(annotation-function . (lambda (ref) (annotation-function
(funcall org-roam-ref-annotation-function . ,org-roam-ref-annotation-function)
ref)))
(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)))