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

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

[elpa] externals/denote 3e7273953a 2/2: Reinstate denote-project-find fu


From: ELPA Syncer
Subject: [elpa] externals/denote 3e7273953a 2/2: Reinstate denote-project-find function for project/xref to work properly
Date: Wed, 13 Mar 2024 03:57:46 -0400 (EDT)

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

    Reinstate denote-project-find function for project/xref to work properly
    
    We had removed this in commit ac0c361, thinking it was not necessary,
    though Alan Schmitt reported a case where we actually needed this
    functionality. This was reported in issue 283:
    <https://github.com/protesilaos/denote/issues/283>.
    
    Thanks to Jean-Philippe Gagné Guay for identifying the regression and
    for taking the initiative to bring back the feature in pull request
    286: <https://github.com/protesilaos/denote/pull/286>. We cannot merge
    that one because it includes other in-development snippets.
---
 denote.el | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/denote.el b/denote.el
index 02bc3f5e0d..f04be59651 100644
--- a/denote.el
+++ b/denote.el
@@ -3963,6 +3963,31 @@ To be assigned to `markdown-follow-link-functions'."
 
 ;;;;; Backlinks' buffer
 
+(cl-defmethod project-root ((project (head denote)))
+  "Denote's implementation of `project-root' method from `project'.
+Return current variable `denote-directory' as the root of the
+current denote PROJECT."
+  (cdr project))
+
+(cl-defmethod project-files ((_project (head denote)) &optional _dirs)
+  "Denote's implementation of `project-files' method from `project'.
+Return all files that have an identifier for the current denote
+PROJECT.  The return value may thus include file types that are
+not implied by `denote-file-type'.  To limit the return value to
+text files, use the function `denote-directory-files' with a
+non-nil `text-only' parameter."
+  (denote-directory-files))
+
+(defun denote-project-find (dir)
+  "Return project instance if DIR is part of variable `denote-directory'.
+The format of project instance is aligned with `project-try-vc'
+defined in `project'."
+  (let ((dir (expand-file-name dir))
+        (root (denote-directory)))
+    (when (or (file-equal-p dir root)
+              (string-prefix-p root dir))
+      (cons 'denote root))))
+
 (define-button-type 'denote-link-backlink-button
   'follow-link t
   'action #'denote-link--backlink-find-file
@@ -4035,7 +4060,8 @@ matching identifiers."
   :interactive nil
   "Major mode for backlinks buffers."
   (unless denote-backlinks-show-context
-    (font-lock-add-keywords nil denote-faces-file-name-keywords t)))
+    (font-lock-add-keywords nil denote-faces-file-name-keywords t))
+  (add-hook 'project-find-functions #'denote-project-find nil t))
 
 (defun denote-link--prepare-backlinks (fetcher _alist)
   "Create backlinks' buffer for the current note.
@@ -4105,7 +4131,8 @@ default, it will show up below the current window."
   (let ((file (buffer-file-name)))
     (when (denote-file-is-writable-and-supported-p file)
       (let* ((id (denote-retrieve-filename-identifier-with-error file))
-             (xref-show-xrefs-function #'denote-link--prepare-backlinks))
+             (xref-show-xrefs-function #'denote-link--prepare-backlinks)
+             (project-find-functions #'denote-project-find))
         (xref--show-xrefs
          (apply-partially #'xref-matches-in-files id
                           (denote-directory-files nil :omit-current 
:text-only))



reply via email to

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