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

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

[elpa] externals/denote 92f9cb8cb9 318/355: Use xref instead of relying


From: ELPA Syncer
Subject: [elpa] externals/denote 92f9cb8cb9 318/355: Use xref instead of relying on find+grep
Date: Sun, 26 Jun 2022 23:58:35 -0400 (EDT)

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

    Use xref instead of relying on find+grep
    
    With xref we delegate to a built-in facility instead of passing a
    hard-coded list of arguments to 'process-lines'.
    
    The old method is prone to errors, such as not working on builds of
    Emacs for macOS, as reported by Colin McLear in issue 18 over at the
    GitHub mirror: <https://github.com/protesilaos/denote/issues/18>.
    
    Users of Emacs 28 or higher can configure 'xref-search-program' to
    change from the default 'grep' to 'ripgrep', 'ugrep', or a user-defined
    alternative.
    
    THIS CHANGE IS PROVISIONAL and subject to further edits.
---
 denote-retrieve.el | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/denote-retrieve.el b/denote-retrieve.el
index fbd55347c5..75724f3ac0 100644
--- a/denote-retrieve.el
+++ b/denote-retrieve.el
@@ -96,33 +96,30 @@ Optional GROUP is a regexp construct for
                       (when (denote--only-note-p f) f))
                     files)))
 
-;; TODO 2022-06-15: Maybe we can do the same in a more standard way?
-;; Perhaps with `xref-matches-in-files'?
-;;
-;; (xref-matches-in-files IDENTIFIER (denote--directory-files :absolute))
+(autoload 'xref--analyze "xref")
+
+(defun denote-retrieve--xrefs (identifier)
+  "Return xrefs of IDENTIFIER in variable `denote-directory'."
+  (xref--analyze
+   (xref-matches-in-files identifier (denote--directory-files :absolute))))
+
+(defun denote-retrieve--files-in-xrefs (xrefs)
+  "Return sorted file names sans directory from XREFS.
+Parse `denote-retrieve--xrefs'."
+  (sort
+   (mapcar (lambda (x)
+             (file-name-nondirectory (car x)))
+           xrefs)
+   #'string-lessp))
+
 (defun denote-retrieve--proces-grep (identifier)
   "Process lines matching IDENTIFIER and return list of files."
   (let* ((default-directory (denote-directory))
          (file (file-name-nondirectory (buffer-file-name))))
     (denote-retrieve--files-in-output
-     (sort
-      (process-lines
-       "find"
-       default-directory
-       "-maxdepth" "1"
-       "-type" "f"
-       "!" "-name" file
-       "-exec"
-       grep-program
-       "--color=never"
-       "-m"
-       "1"
-       "-e"
-       identifier
-       "{}"
-       ";"
-       "-print")
-      #'string-lessp))))
+     (delete file
+             (denote-retrieve--files-in-xrefs
+              (denote-retrieve--xrefs identifier))))))
 
 (provide 'denote-retrieve)
 ;;; denote-retrieve.el ends here



reply via email to

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