emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 50d1bbdf1e 2/2: Simplify denote-file-prompt, fi


From: ELPA Syncer
Subject: [elpa] externals/denote 50d1bbdf1e 2/2: Simplify denote-file-prompt, fixing its two minor bugs
Date: Tue, 7 Nov 2023 00:57:42 -0500 (EST)

branch: externals/denote
commit 50d1bbdf1e8ffe0f449f2f5da02f9b70322fff7d
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Simplify denote-file-prompt, fixing its two minor bugs
    
    The two bugs:
    
    1. The minibuffer history does not work because the project.el function
       that was being called checks for an abbreviated file path (like
       ~/path) whereas we always use absolute file paths (like /home/prot/path).
    
    2. The prompt would ask for confirmation if the file did not exist.
       This was creating friction for commands such as 'denote-open-or-create',
       'denote-link-or-create', and their variants. I consider this a bug
       because we want to have the equivalent of the NO-CONFIRM behaviour
       that 'completing-read' gives us.
    
    This change undoes part of what Noboru Ota (nobiot) did in commit
    6bb6da088211324cdd1ad35396c2988ccb2eccb7. From the commit message, the
    relevant part is this:
    
        (denote-file-prompt): Refactored
    
        - To use the same completion function as 'project-find-file' does.
    
        - The main benefit is that it can let you search notes under all
          sub-directories of 'denote-directory'.  The original 'read-file-name'
          could only search within only single 'denote-directory'
    
        - Note the impact on commands that use 'denote-file-prompt';
          i.e. 'denote-open-or-create', 'denote-link', 'denote-link-or-create',
          and 'denote-link-ol-complete'
    
        - One minor annoyance may be that the prompt now requires a confirmation
          if the user enters text that does not match any of the candidate and
          tries to exit
    
        - 'denote--title-history' is directly updated from the minibuffer
          completion function.  This eliminates the need for
          'denote--push-extracted-title-to-history'.  The original used
          'file-name-history' as the intermediate storage of titles, which are
          not really file names, thus resulted in polluting the history for file
          names
    
    What I am doing with this change is to retain the spirit of Noboru's
    change with regard to the flat listing of files. I agree that the old
    tree-based prompt (per 'read-file-name') was not suitable for our
    needs. The "impact" mentioned in the commit above should now no longer
    be relevant, given what I wrote about NO-CONFIRM. The "minor
    annoyance" is gone for the same reason. The title history has since
    been fixed in other commits and also in this one given what I covered
    above about abbreviated file paths in the project.el functions.
---
 denote.el | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/denote.el b/denote.el
index 795964d481..b9e3264fea 100644
--- a/denote.el
+++ b/denote.el
@@ -919,10 +919,7 @@ The path is relative to DIRECTORY (default: 
‘default-directory’)."
   "Return the list of Denote files in variable `denote-directory'.
 With optional OMIT-CURRENT, do not include the current Denote
 file in the returned list."
-  (let* ((project-find-functions #'denote-project-find)
-         (project (project-current nil (denote-directory)))
-         (dirs (list (project-root project)))
-         (files (project-files project dirs)))
+  (let ((files (denote-directory-files)))
     (if (and omit-current (denote-file-has-identifier-p buffer-file-name))
         (delete buffer-file-name files)
       files)))
@@ -934,23 +931,10 @@ file in the returned list."
   "Prompt for file with identifier in variable `denote-directory'.
 With optional FILES-MATCHING-REGEXP, filter the candidates per
 the given regular expression."
-  (when-let ((files (if files-matching-regexp
-                        (denote-directory-files-matching-regexp 
files-matching-regexp)
-                      (denote-all-files :omit-current)))
-             (file (funcall project-read-file-name-function
-                            ;; FIXME 2023-10-15: Why do I get an empty history 
at the prompt even
-                            ;; though it is given as an argument and it is not 
empty?
-                            ;;
-                            ;; UPDATE 2023-11-07 05:11 +0200: The history 
breaks because the
-                            ;; function does a `string-prefix-p' for an 
abbreviated file path.  We
-                            ;; could abbreviate the history items, though I am 
not happy with this
-                            ;; because it may have implications in other 
places where we expect a
-                            ;; full path.  We could also make a copy of the 
history and abbreviate
-                            ;; that, but it seems expensive.
-                            "Select note: " files nil 'denote--file-history)))
-    (let ((completion-ignore-case read-file-name-completion-ignore-case))
-      (add-to-history 'denote--file-history file)
-      file)))
+  (let ((files (if files-matching-regexp
+                   (denote-directory-files-matching-regexp 
files-matching-regexp)
+                 (denote-all-files :omit-current))))
+    (completing-read "Select note: " files nil nil nil 'denote--file-history)))
 
 ;;;; Keywords
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]