From 9c4497d7d592307d8b4d8cf21679bc1c5b380ef0 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 13 Feb 2024 22:10:12 +0100 Subject: [PATCH] Support bookmarking 'dired-do-find-regexp' results buffer * 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 | 26 +++++++------------------- lisp/progmodes/xref.el | 9 +++++++++ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index a2ce3083cfe..0b2e4e43c64 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -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) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 2742cc56ea1..5d694183c54 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -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)) + ;;; misc utilities (defun xref--alistify (list key) -- 2.39.5