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

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

[elpa] externals/denote f2ccc4cb6d 1/2: Simplify "open or create" retrie


From: ELPA Syncer
Subject: [elpa] externals/denote f2ccc4cb6d 1/2: Simplify "open or create" retrieval of default value; fix regressions
Date: Wed, 13 Dec 2023 06:57:47 -0500 (EST)

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

    Simplify "open or create" retrieval of default value; fix regressions
    
    I recently refactored the denote-title-prompt to use 'completing-read'
    and missed the part of setting the 'denote-title-prompt-current-default'.
    This is now restored.
    
    I am also simplifying how we are working with the minibuffer histories
    to (i) not pollute the denote--file-history with unrelated strings
    and (ii) to not have to deal with 'let' bound values in places where I
    would rather not have them.
    
    I delved into this in response to the message sent by Aleksandr
    Vityazev on the mailing list:
    <https://lists.sr.ht/~protesilaos/denote/%3C87a5qevq8i.fsf%40gmail.com%3E>.
---
 README.org | 23 ++++++++++++-----------
 denote.el  | 45 +++++++++++++++------------------------------
 2 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/README.org b/README.org
index 6809b28ea0..0597b0801c 100644
--- a/README.org
+++ b/README.org
@@ -4887,17 +4887,18 @@ Denote is meant to be a collective effort.  Every bit 
of help matters.
   Manerikar, ezchi, leinfink (Henrik), mentalisttraceur, relict007.
 
 + Ideas and/or user feedback :: Abin Simon, Aditya Yadav, Alan
-  Schmitt, Alfredo Borrás, Ashton Wiersdorf, Benjamin Kästner, Claudiu
-  Tănăselia, Colin McLear, Damien Cassou, Elias Storms, Federico
-  Stilman, Florian, Frédéric Willem Frank Ehmsen, Glenna D., Guo Yong,
-  Hanspeter Gisler, Jack Baty, Jay Rajput, Jean-Charles Bagneris, Jens
-  Östlund, Jeremy Friesen, Jonathan Sahar, Johan Bolmsjö, Jousimies,
-  Juanjo Presa, Kai von Fintel, Kaushal Modi, M. Hadi Timachi, Mark
-  Olson, Mirko Hernandez, Niall Dooley, Paul van Gelder, Peter Prevos,
-  Peter Smith, Suhail Singh, Shreyas Ragavan, Stefan Thesing, Summer
-  Emacs, Sven Seebeck, Taoufik, TJ Stankus, Viktor Haag, Wade Mealing,
-  Yi Liu, Ypot, atanasj, babusri, doolio, drcxd, hpgisler, pRot0ta1p,
-  rbenit68, relict007, sienic, sundar bp.
+  Schmitt, Aleksandr Vityazev, Alfredo Borrás, Ashton Wiersdorf,
+  Benjamin Kästner, Claudiu Tănăselia, Colin McLear, Damien Cassou,
+  Elias Storms, Federico Stilman, Florian, Frédéric Willem Frank
+  Ehmsen, Glenna D., Guo Yong, Hanspeter Gisler, Jack Baty, Jay
+  Rajput, Jean-Charles Bagneris, Jens Östlund, Jeremy Friesen,
+  Jonathan Sahar, Johan Bolmsjö, Jousimies, Juanjo Presa, Kai von
+  Fintel, Kaushal Modi, M. Hadi Timachi, Mark Olson, Mirko Hernandez,
+  Niall Dooley, Paul van Gelder, Peter Prevos, Peter Smith, Suhail
+  Singh, Shreyas Ragavan, Stefan Thesing, Summer Emacs, Sven Seebeck,
+  Taoufik, TJ Stankus, Viktor Haag, Wade Mealing, Yi Liu, Ypot,
+  atanasj, babusri, doolio, drcxd, hpgisler, pRot0ta1p, rbenit68,
+  relict007, sienic, sundar bp.
 
 Special thanks to Peter Povinec who helped refine the file-naming
 scheme, which is the cornerstone of this project.
diff --git a/denote.el b/denote.el
index bca6a6040c..26be95f008 100644
--- a/denote.el
+++ b/denote.el
@@ -6,7 +6,7 @@
 ;; Maintainer: Denote Development <~protesilaos/denote@lists.sr.ht>
 ;; URL: https://git.sr.ht/~protesilaos/denote
 ;; Mailing-List: https://lists.sr.ht/~protesilaos/denote
-;; Version: 2.2.2
+;; Version: 2.2.3
 ;; Package-Requires: ((emacs "28.1"))
 
 ;; This file is NOT part of GNU Emacs.
@@ -1867,10 +1867,11 @@ histories between sessions."
                      nil (current-local-map))))
            (define-key map (kbd "SPC") nil)
            map)))
-    (completing-read
-     (format-prompt (or prompt-text "File title") nil)
-     denote--title-history
-     nil nil default-title 'denote--title-history nil)))
+    (let ((current-def (or denote-title-prompt-current-default nil)))
+      (completing-read
+       (format-prompt (or prompt-text "File title") current-def)
+       denote--title-history
+       nil nil default-title 'denote--title-history current-def))))
 
 (defvar denote--file-type-history nil
   "Minibuffer history of `denote-file-type-prompt'.")
@@ -2097,33 +2098,17 @@ technicalities)."
 
 ;;;;; Other convenience commands
 
-(defun denote--extract-title-from-file-history ()
-  "Extract last file title input from `file-name-history'."
-  (when-let ((file (car denote--file-history))
-             (title (expand-file-name file)))
-    (string-match (denote-directory) title)
-    (substring title (match-end 0))))
-
-(defun denote--append-extracted-string-to-history (history)
-  "Append `denote--extract-title-from-file-history' to HISTORY."
-  (append
-   (list (denote--extract-title-from-file-history))
-   history))
-
-(defun denote--command-with-title-history (command)
-  "Call COMMAND with modified title history.
-
-Set the `denote-title-prompt-current-default' to the value of the
-last user input of a file title search (per `denote-file-prompt').
-
+(defun denote--command-with-default-title (command)
+  "Call COMMAND with last input at the `denote-file-prompt'.
+Set the `denote-title-prompt-current-default' to the last input.
 This is what makes commands such as `denote-open-or-create' or
 `denote-link-or-create' get what the user initially typed as the
 default value for the title of the new note to be created."
-  (let ((denote--title-history
-         (denote--append-extracted-string-to-history denote--title-history)))
+  (let ((last-input (when denote--file-history
+                      (pop denote--file-history))))
     (unwind-protect
         (progn
-          (setq denote-title-prompt-current-default (car 
denote--title-history))
+          (setq denote-title-prompt-current-default last-input)
           (call-interactively command))
       (setq denote-title-prompt-current-default nil))))
 
@@ -2141,7 +2126,7 @@ note's actual title.  At the `denote-file-prompt' type
   (interactive (list (denote-file-prompt)))
   (if (and target (file-exists-p target))
       (find-file target)
-    (denote--command-with-title-history #'denote)))
+    (denote--command-with-default-title #'denote)))
 
 ;;;###autoload
 (defun denote-open-or-create-with-command ()
@@ -2159,7 +2144,7 @@ note's actual title.  At the `denote-file-prompt' type
   (let ((target (denote-file-prompt)))
     (if (and target (file-exists-p target))
         (find-file target)
-      (denote--command-with-title-history (denote-command-prompt)))))
+      (denote--command-with-default-title (denote-command-prompt)))))
 
 ;;;###autoload
 (defun denote-keywords-add (keywords)
@@ -3373,7 +3358,7 @@ file's title.  This has the same meaning as in 
`denote-link'."
          type
          (denote--link-get-description target type)
          id-only))
-    (denote--command-with-title-history #'denote-link-after-creating)))
+    (denote--command-with-default-title #'denote-link-after-creating)))
 
 (defalias 'denote-link-to-existing-or-new-note 'denote-link-or-create
   "Alias for `denote-link-or-create' command.")



reply via email to

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