From 3a54182bb1d637d32331c51eb2fa1a2f32dcb3c8 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Sun, 10 Oct 2021 13:37:57 +0200 Subject: [PATCH] (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. --- extensions/org-roam-graph.el | 4 ++-- org-roam-node.el | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/extensions/org-roam-graph.el b/extensions/org-roam-graph.el index 383e31c..152e620 100644 --- a/extensions/org-roam-graph.el +++ b/extensions/org-roam-graph.el @@ -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)))) (org-roam-message "building graph") (make-process - :name "*org-roam-graph--build-process*" - :buffer "*org-roam-graph--build-process*" + :name "*org-roam-graph*" + :buffer " *org-roam-graph*" :command `(,org-roam-graph-executable ,temp-dot "-T" ,org-roam-graph-filetype "-o" ,temp-graph) :sentinel (when callback (lambda (process _event) diff --git a/org-roam-node.el b/org-roam-node.el index 8f84c04..5700666 100644 --- a/org-roam-node.el +++ b/org-roam-node.el @@ -76,8 +76,10 @@ It takes a single argument NODE, which is an `org-roam-node' construct." (defcustom org-roam-node-default-sort 'file-mtime "Default sort order for Org-roam node completions." - :type '(choice (const :tag "file-mtime" file-mtime) - (const :tag "file-atime" file-atime)) + :type '(choice + (const :tag "none" nil) + (const :tag "file-mtime" file-mtime) + (const :tag "file-atime" file-atime)) :group 'org-roam) (defcustom org-roam-node-template-prefixes @@ -460,10 +462,15 @@ If REQUIRE-MATCH, the minibuffer prompt will require a match." "Node: " (lambda (string pred action) (if (eq action 'metadata) - '(metadata - (annotation-function . (lambda (title) - (funcall org-roam-node-annotation-function - (get-text-property 0 'node title)))) + `(metadata + ;; 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 + (get-text-property 0 'node title)))) (category . org-roam-node)) (complete-with-action action nodes string pred))) nil require-match initial-input))) @@ -695,9 +702,7 @@ We use this as a substitute for `org-link-bracket-re', because start (match-beginning 2) end (match-end 2)) (list start end - (completion-table-dynamic - (lambda (_) - (funcall #'org-roam--get-titles))) + (org-roam--get-titles) :exit-function (lambda (str &rest _) (delete-char (- 0 (length str))) @@ -718,9 +723,7 @@ hence \"everywhere\"." (not (save-match-data (org-in-regexp org-link-any-re)))) (let ((bounds (bounds-of-thing-at-point 'word))) (list (car bounds) (cdr bounds) - (completion-table-dynamic - (lambda (_) - (funcall #'org-roam--get-titles))) + (org-roam--get-titles) :exit-function (lambda (str _status) (delete-char (- (length str))) @@ -915,10 +918,9 @@ filtered out." (ref (completing-read "Ref: " (lambda (string pred action) (if (eq action 'metadata) - '(metadata - (annotation-function . (lambda (ref) - (funcall org-roam-ref-annotation-function - ref))) + `(metadata + (annotation-function + . ,org-roam-ref-annotation-function) (category . org-roam-ref)) (complete-with-action action refs string pred))) nil t initial-input)))