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

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

[elpa] externals/denote 17dc71f7b5 1/2: Allow denote-link-or-create to l


From: ELPA Syncer
Subject: [elpa] externals/denote 17dc71f7b5 1/2: Allow denote-link-or-create to leverage last input
Date: Mon, 24 Oct 2022 01:57:38 -0400 (EDT)

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

    Allow denote-link-or-create to leverage last input
    
    I am implementing this functionality in response to a request made by
    Guo Yong: 
<https://lists.sr.ht/~protesilaos/denote/%3CNF6pFBq--3-9%40tutanota.com%3E>.
    
    The idea is to enhance the "link or create+link" functionality so that
    when the user searches for a file that does not exit, they can re-use
    the search terms they used initially.
    
    As I explained on the mailing list:
    
        A non-intrusive way of addressing this issue is to leverage the
        minibuffer histories.  This allows us to type 'M-p' (the command is
        'previous-history-element') at Denote's title prompt and get the last
        input.  The diff further below makes this possible, but I am also
        copying the code for your convenience.
    
        Some notes before you check the code:
    
        1. We should not hardcode prompts, such as for file and keywords because
           that will contradict the user option 'denote-prompts'.  Concretely, a
           user may want to create+link to a note that has a specific date, is
           in a given subdirectory, and starts with a certain template.
    
        2. The input we provide at the standard file prompt should not be taken
           literally.  The reason is that it is common for a user to rely on the
           completion style to narrow the list of candidates.  They are not
           necessarily typing the exact title they would like.  For example, I
           use the 'orderless' package (among built-in options) and will often
           type searches out-of-order like "_journal test this" which would
           match a file that is "20221024T062254--this-is-a-test__journal.txt".
    
           By adding the last search to the minibuffer history, we let the user
           edit the title before they submit it.
    
    Thanks to Guo Yong for testing my prototype and confirming it does
    what we need.
---
 README.org | 18 ++++++++++++++----
 denote.el  | 24 ++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/README.org b/README.org
index 75d5896077..451e62b979 100644
--- a/README.org
+++ b/README.org
@@ -1330,6 +1330,15 @@ this end, Denote provides two convenience commands:
   which runs the ~denote~ command interactively to create the file.  The
   established link will then be targeting that new file.
 
+  If =TARGET= file does not exist, add the user input that was used to
+  search for it to the history of the ~denote-title-prompt~.  The user
+  can then retrieve and possibly further edit their last input, using
+  it as the newly created note's actual title.  At the ~denote-title-prompt~
+  type =M-p= with the default key bindings, which calls 
~previous-history-element~.
+
+  [ The above paragraph describes functionality that is part of
+    {{{development-version}}}. ]
+
   With optional =ID-ONLY= as a prefix argument create a link with just
   the file's identifier.  This has the same meaning as in ~denote-link~.
 
@@ -3211,10 +3220,11 @@ Denote is meant to be a collective effort.  Every bit 
of help matters.
 
 + Ideas and/or user feedback :: Abin Simon, Alan Schmitt, Alfredo
   Borrás, Benjamin Kästner, Colin McLear, Damien Cassou, Elias Storms,
-  Federico Stilman, Florian, Frank Ehmsen, Hanspeter Gisler, Jack
-  Baty, Juanjo Presa, Kaushal Modi, M. Hadi Timachi, Paul van Gelder,
-  Peter Prevos, Shreyas Ragavan, Summer Emacs, Sven Seebeck, Taoufik,
-  Yi Liu, Ypot, atanasj, hpgisler, pRot0ta1p, sienic, sundar bp.
+  Federico Stilman, Florian, Frank Ehmsen, Guo Yong, Hanspeter Gisler,
+  Jack Baty, Juanjo Presa, Kaushal Modi, M. Hadi Timachi, Paul van
+  Gelder, Peter Prevos, Shreyas Ragavan, Summer Emacs, Sven Seebeck,
+  Taoufik, Yi Liu, Ypot, atanasj, hpgisler, pRot0ta1p, 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 70e2a3ba9d..47a46672d7 100644
--- a/denote.el
+++ b/denote.el
@@ -1565,6 +1565,22 @@ set to \\='(template title keywords)."
 
 ;;;;; Other convenience commands
 
+(defun denote--extract-title-from-file-history ()
+  "Extract last file title input from `file-name-history'."
+  ;; We do not need to check if `file-name-history' is initialised
+  ;; because it is defined in files.el.  My understanding is that it
+  ;; is always loaded.
+  (when-let ((title (expand-file-name (car file-name-history))))
+    (string-match (denote-directory) title)
+    (substring title (match-end 0))))
+
+(defun denote--push-extracted-title-to-history ()
+  "Add `denote--extract-title-from-file-history' to `denote--title-history'."
+  (when-let* ((last-input (denote--extract-title-from-file-history))
+              ((not (string-empty-p last-input)))
+              ((not (string-blank-p last-input))))
+    (push last-input denote--title-history)))
+
 ;;;###autoload
 (defun denote-open-or-create (target)
   "Visit TARGET file in variable `denote-directory'.
@@ -2459,12 +2475,20 @@ If TARGET file does not exist, call 
`denote-link-after-creating'
 which runs the `denote' command interactively to create the file.
 The established link will then be targeting that new file.
 
+If TARGET file does not exist, add the user input that was used
+to search for it to the minibuffer history of the
+`denote-title-prompt'.  The user can then retrieve and possibly
+further edit their last input, using it as the newly created
+note's actual title.  At the `denote-title-prompt' type
+\\<minibuffer-local-map>\\[previous-history-element].
+
 With optional ID-ONLY as a prefix argument create a link that
 consists of just the identifier.  Else try to also include the
 file's title.  This has the same meaning as in `denote-link'."
   (interactive (list (denote-file-prompt) current-prefix-arg))
   (if (file-exists-p target)
       (denote-link target id-only)
+    (denote--push-extracted-title-to-history)
     (call-interactively #'denote-link-after-creating)))
 
 (defalias 'denote-link-to-existing-or-new-note (symbol-function 
'denote-link-or-create))



reply via email to

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