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

    Make denote-file-prompt process its history better
    
    We do not need to have full file system paths there, nor the user's
    raw input. What we want are file names relative to the
    denote-directory.
    
    Thanks to Alan Schmitt for noting that the history was not working
    properly. This was done in issue 339:
    <https://github.com/protesilaos/denote/issues/339>.
---
 denote.el | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/denote.el b/denote.el
index 79e0500a9c..0c01dbfa00 100644
--- a/denote.el
+++ b/denote.el
@@ -1196,13 +1196,17 @@ With optional PROMPT-TEXT, use it instead of the 
default call to
            (_ (when included-cpd
                 (setq substrings (cons "./" substrings))))
            (new-collection (denote--completion-table 'file substrings))
-           (relname (completing-read prompt new-collection nil nil nil 
'denote-file-history))
-           (absname (expand-file-name relname common-parent-directory)))
-      ;; NOTE 2024-02-29: This delete and add feels awkward.  I wish
-      ;; we could tell `completing-read' to just leave this up to us.
-      (setq denote-file-history (delete relname denote-file-history))
-      (add-to-history 'denote-file-history absname)
-      absname)))
+           ;; We populate the history ourselves because we process the input.
+           (input (completing-read prompt new-collection))
+           ;; FIXME 2024-05-08: Is there some elegant way to do this?
+           (filename (with-temp-buffer
+                       (insert input)
+                       (completion-in-region (point-min) (point-max) 
new-collection)
+                       (buffer-string))))
+      (when filename
+        (setq denote-file-history (delete input denote-file-history))
+        (add-to-history 'denote-file-history filename))
+      filename)))
 
 ;;;; Keywords
 

Reply via email to