]> git.eshelyaron.com Git - emacs.git/commitdiff
Support bookmarking 'dired-do-find-regexp' results buffer
authorEshel Yaron <me@eshelyaron.com>
Tue, 13 Feb 2024 21:10:12 +0000 (22:10 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 13 Feb 2024 21:10:12 +0000 (22:10 +0100)
* lisp/progmodes/xref.el: New simple 'files' backend.
(xref-backend-apropos, xref-backend-context)
(xref-backend-restore): Implement for 'files' backend.

* lisp/dired-aux.el (dired-do-find-regexp): Use 'xref-make-fetcher'.

lisp/dired-aux.el
lisp/progmodes/xref.el

index a2ce3083cfec596403a31db74590f5510f0303ae..0b2e4e43c64794242320e0b28bcfc99592d9e736 100644 (file)
@@ -3804,26 +3804,14 @@ REGEXP should use constructs supported by your local `grep' command."
                           #'file-name-as-directory
                           (rgrep-find-ignored-directories default-directory))
                          grep-find-ignored-files))
-         (fetcher
-          (lambda ()
-            (let (files xrefs)
-              (mapc
-               (lambda (mark)
-                 (if (file-directory-p mark)
-                     (setq files (nconc
-                                  (project--files-in-directory mark ignores "*")
-                                  files))
-                   (push mark files)))
-               (reverse marks))
-              (message "Searching...")
-              (setq xrefs
-                    (xref-matches-in-files regexp files))
-              (unless xrefs
-                (user-error "No matches for: %s" regexp))
-              (message "Searching...done")
-              xrefs))))
+         (files nil))
+    (dolist (mark (reverse marks))
+      (if (file-directory-p mark)
+          (setq files (nconc (project--files-in-directory mark ignores "*") files))
+        (push mark files)))
     (dired-post-do-command)
-    (xref-show-xrefs fetcher nil)))
+    (xref-show-xrefs
+     (xref-make-fetcher (cons 'files files) regexp 'apropos regexp))))
 
 ;;;###autoload
 (defun dired-do-find-regexp-and-replace (from to)
index 2742cc56ea1f1f95c4b772b2740110f3c5184148..5d694183c540a286d9870103dfab7f0de8ae8a2d 100644 (file)
@@ -293,6 +293,11 @@ The second argument has the same meaning as in `apropos'.
 If BACKEND is implemented in Lisp, it can use
 `xref-apropos-regexp' to convert the pattern to regexp.")
 
+(cl-defmethod xref-backend-apropos ((backend (head files)) pattern)
+  "Find matches for PATTERN in files that BACKEND specifies."
+  (or (xref-matches-in-files pattern (cdr backend))
+      (user-error "No matches for: %s" pattern)))
+
 (cl-defgeneric xref-backend-identifier-at-point (_backend)
   "Return the relevant identifier at point.
 
@@ -325,10 +330,14 @@ recognize and then delegate the work to an external process."
   "Return BACKEND-specific context for finding references to IDENTIFIER."
   (bookmark-make-record))
 
+(cl-defmethod xref-backend-context ((_backend (head files)) _id _kind))
+
 (cl-defgeneric xref-backend-restore (_backend context)
   "Restore BACKEND-specific CONTEXT."
   (bookmark-handle-bookmark context))
 
+(cl-defmethod xref-backend-restore ((_backend (head files)) _context))
+
 \f
 ;;; misc utilities
 (defun xref--alistify (list key)