summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2020-06-01 04:44:33 +0300
committerDmitry Gutov <dgutov@yandex.ru>2020-06-01 05:28:43 +0300
commitf92925864613035c2e627862433112b12cf0d6dd (patch)
tree6b53171c2e706c7cac34896121bd4a9c5a78fa66
parent43caa9680b0d000014b4b9004389b7b193a51629 (diff)
downloademacs-f92925864613035c2e627862433112b12cf0d6dd.tar.gz
Change xref-find-apropos to pass PATTERN to backend verbatim
* lisp/progmodes/xref.el (xref-backend-apropos): Rename this generic's second arg to PATTERN, to clarify that it should be handled entirely in the backend, with no pre-processing by the command. (xref-find-apropos): Update accordingly, but keep compatibility with backends in older Emacs versions. (xref-apropos-regexp): Extract from xref-find-apropos. * lisp/progmodes/etags.el (xref-backend-apropos): Use it here. * lisp/progmodes/elisp-mode.el (xref-backend-apropos): And here.
-rw-r--r--lisp/progmodes/elisp-mode.el5
-rw-r--r--lisp/progmodes/etags.el4
-rw-r--r--lisp/progmodes/xref.el32
3 files changed, 28 insertions, 13 deletions
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index d37eb8c152d..a0a0a0dc6a9 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -863,9 +863,10 @@ non-nil result supercedes the xrefs produced by
(declare-function project-external-roots "project")
-(cl-defmethod xref-backend-apropos ((_backend (eql elisp)) regexp)
+(cl-defmethod xref-backend-apropos ((_backend (eql elisp)) pattern)
(apply #'nconc
- (let (lst)
+ (let ((regexp (xref-apropos-regexp pattern))
+ lst)
(dolist (sym (apropos-internal regexp))
(push (elisp--xref-find-definitions sym) lst))
(nreverse lst))))
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index 897f105019e..edadbbdafc1 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -2080,8 +2080,8 @@ file name, add `tag-partial-file-name-match-p' to the list value.")
(cl-defmethod xref-backend-definitions ((_backend (eql etags)) symbol)
(etags--xref-find-definitions symbol))
-(cl-defmethod xref-backend-apropos ((_backend (eql etags)) symbol)
- (etags--xref-find-definitions symbol t))
+(cl-defmethod xref-backend-apropos ((_backend (eql etags)) pattern)
+ (etags--xref-find-definitions (xref-apropos-regexp pattern) t))
(defun etags--xref-find-definitions (pattern &optional regexp?)
;; This emulates the behavior of `find-tag-in-order' but instead of
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 2477884f1ab..5b5fb4bc47a 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -273,7 +273,11 @@ find a search tool; by default, this uses \"find | grep\" in the
(project-external-roots pr)))))
(cl-defgeneric xref-backend-apropos (backend pattern)
- "Find all symbols that match regexp PATTERN.")
+ "Find all symbols that match PATTERN string.
+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-defgeneric xref-backend-identifier-at-point (_backend)
"Return the relevant identifier at point.
@@ -1098,14 +1102,24 @@ The argument has the same meaning as in `apropos'."
"Search for pattern (word list or regexp): "
nil 'xref--read-pattern-history)))
(require 'apropos)
- (xref--find-xrefs pattern 'apropos
- (apropos-parse-pattern
- (if (string-equal (regexp-quote pattern) pattern)
- ;; Split into words
- (or (split-string pattern "[ \t]+" t)
- (user-error "No word list given"))
- pattern))
- nil))
+ (let* ((newpat
+ (if (and (version< emacs-version "28.0.50")
+ (memq (xref-find-backend) '(elisp etags)))
+ ;; Handle backends in older Emacs.
+ (xref-apropos-regexp pattern)
+ ;; Delegate pattern handling to the backend fully.
+ ;; The old way didn't work for "external" backends.
+ pattern)))
+ (xref--find-xrefs pattern 'apropos newpat nil)))
+
+(defun xref-apropos-regexp (pattern)
+ "Return an Emacs regexp from PATTERN similar to `apropos'."
+ (apropos-parse-pattern
+ (if (string-equal (regexp-quote pattern) pattern)
+ ;; Split into words
+ (or (split-string pattern "[ \t]+" t)
+ (user-error "No word list given"))
+ pattern)))
;;; Key bindings