branch: externals/denote
commit 807395fcb1ac79dbcbaa61112622354a53aaa9bc
Author: Protesilaos Stavrou <i...@protesilaos.com>
Commit: Protesilaos Stavrou <i...@protesilaos.com>

    Add command denote-find-backlink-with-location
    
    This is in response to issue 471 as reported by johkneisl:
    <https://github.com/protesilaos/denote/issues/471>.
---
 README.org | 24 +++++++++++++++++++-----
 denote.el  | 14 ++++++++++++++
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/README.org b/README.org
index 659168df3f..bb6c443209 100644
--- a/README.org
+++ b/README.org
@@ -3042,7 +3042,8 @@ the current window.
 
 Backlinks to the current file can also be visited by using the
 minibuffer completion interface with the ~denote-find-backlink~
-command ([[#h:1bc2adad-dca3-4878-b9f0-b105d5dec6f4][Visiting linked files via 
the minibuffer]]).
+command or the more powerful ~denote-find-backlink-with-location~
+([[#h:1bc2adad-dca3-4878-b9f0-b105d5dec6f4][Visiting linked files via the 
minibuffer]]). [ The command ~denote-find-backlink-with-location~ is part of 
{{{development-version}}}. ]
 
 ** Writing metanotes
 :PROPERTIES:
@@ -3104,6 +3105,19 @@ To visit backlinks to the current note via the 
minibuffer, use
 ~denote-find-backlink~.  This is an alternative to placing backlinks
 in a dedicated buffer ([[#h:c73f1f68-e214-49d5-b369-e694f6a5d708][The 
backlinks' buffer]]).
 
+#+findex: denote-find-backlink-with-location
+As an alternative to ~denote-find-backlink~, the command
+~denote-find-backlink-with-location~ shows the complete results of all
+backlinks in their context, grouped by file. It prompts to pick one
+among them, using minibuffer completion, and then jumps to the
+corresponding file at that exact location where the link is.
+
+Think of the ~denote-find-backlink-with-location~ as the
+minibuffer-centric variant of the backlinks buffer: the backlinks
+buffer sticks around, whereas this one is only available for the
+duration of the command. Depending on the scenario, one is more
+appropriate than the other. [ The command ~denote-find-backlink-with-location~ 
is part of {{{development-version}}}. ]
+
 ** Fontify links in non-Org buffers
 :PROPERTIES:
 :CUSTOM_ID: h:156c5ea3-147b-4f9d-a404-86a00558c60a
@@ -6315,10 +6329,10 @@ Denote is meant to be a collective effort.  Every bit 
of help matters.
   Summer Emacs, Sven Seebeck, Taoufik, TJ Stankus, Vick (VicZz),
   Viktor Haag, Vineet C. Kulkarni, Wade Mealing, Wilf, Yi Liu, Ypot,
   atanasj, azegas, babusri, bdillahu, coherentstate, doolio, duli,
-  drcxd, elge70, elliottw, fingerknight, hpgisler, hyperfocus1337,
-  jtpavlock, juh, leafarbelm, mentalisttraceur, pRot0ta1p, rbenit68,
-  relict007, sarcom-sar, sienic, skissue, sundar bp,
-  yetanotherfossman, zadca123
+  drcxd, elge70, elliottw, fingerknight, hpgisler,
+  hyperfocus1337,johkneisl, jtpavlock, juh, leafarbelm,
+  mentalisttraceur, pRot0ta1p, rbenit68, relict007, sarcom-sar,
+  sienic, skissue, sundar bp, yetanotherfossman, zadca123
 
 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 280bcc71eb..03d2c8acf9 100644
--- a/denote.el
+++ b/denote.el
@@ -5516,6 +5516,9 @@ Also see `denote-link-return-links'."
 ;;;###autoload
 (defun denote-find-backlink ()
   "Use minibuffer completion to visit backlink to current file.
+Visit the file itself, not the location where the link is.  For a
+context-sensitive operation, use `denote-find-backlink-with-location'.
+
 Alo see `denote-find-link'."
   (declare (interactive-only t))
   (interactive)
@@ -5524,6 +5527,17 @@ Alo see `denote-find-link'."
               (selected (denote-select-from-files-prompt links "Select among 
BACKLINKS")))
     (find-file selected)))
 
+;;;###autoload
+(defun denote-find-backlink-with-location ()
+  "Like `denote-find-backlink' but jump to the exact location of the link."
+  (declare (interactive-only t))
+  (interactive)
+  (when-let* ((current-file buffer-file-name)
+              (id (denote-retrieve-filename-identifier-with-error 
current-file))
+              (files (denote-directory-files nil :omit-current :text-only))
+              (fetcher (lambda () (xref-matches-in-files id files))))
+    (xref-show-definitions-completing-read fetcher nil)))
+
 ;;;;;; Query links
 
 (defvar denote-query-link-history nil

Reply via email to