branch: externals/denote
commit 8ea5ac5cd9cc08125b5eb78f2933ed93fcc53b0b
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>

    Expand the completion metadata of the denote-file-prompt
---
 denote.el | 38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/denote.el b/denote.el
index f3f1e6addc..f077217c4b 100644
--- a/denote.el
+++ b/denote.el
@@ -1542,7 +1542,7 @@ there.")
   "Retun group of FILE if TRANSFORM is non-nil, per `completion-metadata'."
   (cond
    (transform
-    file)
+    (or (denote-retrieve-filename-title file) file))
    ((string-match-p (regexp-opt denote-encryption-file-extensions) file)
     "Encrypted")
    ((string-match-p (regexp-opt (denote-file-type-extensions)) file)
@@ -1551,10 +1551,38 @@ there.")
     "Documents")
    (t "Other files")))
 
+(defun denote-file-prompt-affixate (files)
+  "Affixate FILES.
+Use the identifier as a prefix and the keywords as a suffix."
+  (mapcar
+   (lambda (file)
+     (list
+      file
+      (format "%s " (propertize (denote-id-to-date 
(denote-retrieve-filename-identifier file)) 'face 'completions-annotations))
+      (format " %s%s"
+              (if (eq completions-format 'one-column)
+                  (propertize " " 'display '(space :align-to 90))
+                " ")
+              (propertize (or (denote-retrieve-filename-keywords file) "") 
'face 'completions-annotations))))
+   files))
+
 (defun denote-file-prompt-sort (files)
   "Sort FILES for `denote-file-prompt', per `completion-metadata'."
   (sort files #'denote-sort-modified-time-greaterp))
 
+(defvar denote-file-prompt-extra-metadata
+  (list
+   ;; NOTE 2025-12-15: If we use the `file' category, then we are
+   ;; subject to the `completion-category-overrides'.  This is a
+   ;; problem because the user will want to, for example, sort
+   ;; directories before files, but then we cannot have our sort here.
+   (cons 'category 'file)
+   (cons 'group-function #'denote-file-prompt-group)
+   (cons 'affixation-function #'denote-file-prompt-affixate)
+   (cons 'display-sort-function #'denote-file-prompt-sort))
+  "Extra `completion-metadata' for the `denote-file-prompt'.
+This is in addition to the completion category, which is constant.")
+
 (defun denote-file-prompt (&optional files-matching-regexp prompt-text 
no-require-match has-identifier)
   "Prompt for file in variable `denote-directory'.
 Files that match `denote-excluded-files-regexp' are excluded from the
@@ -1591,12 +1619,8 @@ Return the absolute path to the matching file."
                              (propertize default-directory 'face 
'denote-faces-prompt-current-name))))
          (input (completing-read
                  prompt
-                 (denote-get-completion-table
-                  relative-files
-                  '(category . file)
-                  '(group-function . denote-file-prompt-group)
-                  '(display-sort-function . denote-file-prompt-sort))
-                 nil (unless no-require-match :require-match)
+                 (apply 'denote-get-completion-table relative-files 
denote-file-prompt-extra-metadata)
+                 nil (unless no-require-match t)
                  nil 'denote-file-history))
          (absolute-file (if single-dir-p
                             (expand-file-name input default-directory)

Reply via email to