diff options
| author | Dmitry Gutov | 2020-06-01 04:44:33 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2020-06-01 05:28:43 +0300 |
| commit | f92925864613035c2e627862433112b12cf0d6dd (patch) | |
| tree | 6b53171c2e706c7cac34896121bd4a9c5a78fa66 | |
| parent | 43caa9680b0d000014b4b9004389b7b193a51629 (diff) | |
| download | emacs-f92925864613035c2e627862433112b12cf0d6dd.tar.gz emacs-f92925864613035c2e627862433112b12cf0d6dd.zip | |
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.el | 5 | ||||
| -rw-r--r-- | lisp/progmodes/etags.el | 4 | ||||
| -rw-r--r-- | lisp/progmodes/xref.el | 32 |
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 | |||
| 863 | 863 | ||
| 864 | (declare-function project-external-roots "project") | 864 | (declare-function project-external-roots "project") |
| 865 | 865 | ||
| 866 | (cl-defmethod xref-backend-apropos ((_backend (eql elisp)) regexp) | 866 | (cl-defmethod xref-backend-apropos ((_backend (eql elisp)) pattern) |
| 867 | (apply #'nconc | 867 | (apply #'nconc |
| 868 | (let (lst) | 868 | (let ((regexp (xref-apropos-regexp pattern)) |
| 869 | lst) | ||
| 869 | (dolist (sym (apropos-internal regexp)) | 870 | (dolist (sym (apropos-internal regexp)) |
| 870 | (push (elisp--xref-find-definitions sym) lst)) | 871 | (push (elisp--xref-find-definitions sym) lst)) |
| 871 | (nreverse lst)))) | 872 | (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.") | |||
| 2080 | (cl-defmethod xref-backend-definitions ((_backend (eql etags)) symbol) | 2080 | (cl-defmethod xref-backend-definitions ((_backend (eql etags)) symbol) |
| 2081 | (etags--xref-find-definitions symbol)) | 2081 | (etags--xref-find-definitions symbol)) |
| 2082 | 2082 | ||
| 2083 | (cl-defmethod xref-backend-apropos ((_backend (eql etags)) symbol) | 2083 | (cl-defmethod xref-backend-apropos ((_backend (eql etags)) pattern) |
| 2084 | (etags--xref-find-definitions symbol t)) | 2084 | (etags--xref-find-definitions (xref-apropos-regexp pattern) t)) |
| 2085 | 2085 | ||
| 2086 | (defun etags--xref-find-definitions (pattern &optional regexp?) | 2086 | (defun etags--xref-find-definitions (pattern &optional regexp?) |
| 2087 | ;; This emulates the behavior of `find-tag-in-order' but instead of | 2087 | ;; 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 | |||
| 273 | (project-external-roots pr))))) | 273 | (project-external-roots pr))))) |
| 274 | 274 | ||
| 275 | (cl-defgeneric xref-backend-apropos (backend pattern) | 275 | (cl-defgeneric xref-backend-apropos (backend pattern) |
| 276 | "Find all symbols that match regexp PATTERN.") | 276 | "Find all symbols that match PATTERN string. |
| 277 | The second argument has the same meaning as in `apropos'. | ||
| 278 | |||
| 279 | If BACKEND is implemented in Lisp, it can use | ||
| 280 | `xref-apropos-regexp' to convert the pattern to regexp.") | ||
| 277 | 281 | ||
| 278 | (cl-defgeneric xref-backend-identifier-at-point (_backend) | 282 | (cl-defgeneric xref-backend-identifier-at-point (_backend) |
| 279 | "Return the relevant identifier at point. | 283 | "Return the relevant identifier at point. |
| @@ -1098,14 +1102,24 @@ The argument has the same meaning as in `apropos'." | |||
| 1098 | "Search for pattern (word list or regexp): " | 1102 | "Search for pattern (word list or regexp): " |
| 1099 | nil 'xref--read-pattern-history))) | 1103 | nil 'xref--read-pattern-history))) |
| 1100 | (require 'apropos) | 1104 | (require 'apropos) |
| 1101 | (xref--find-xrefs pattern 'apropos | 1105 | (let* ((newpat |
| 1102 | (apropos-parse-pattern | 1106 | (if (and (version< emacs-version "28.0.50") |
| 1103 | (if (string-equal (regexp-quote pattern) pattern) | 1107 | (memq (xref-find-backend) '(elisp etags))) |
| 1104 | ;; Split into words | 1108 | ;; Handle backends in older Emacs. |
| 1105 | (or (split-string pattern "[ \t]+" t) | 1109 | (xref-apropos-regexp pattern) |
| 1106 | (user-error "No word list given")) | 1110 | ;; Delegate pattern handling to the backend fully. |
| 1107 | pattern)) | 1111 | ;; The old way didn't work for "external" backends. |
| 1108 | nil)) | 1112 | pattern))) |
| 1113 | (xref--find-xrefs pattern 'apropos newpat nil))) | ||
| 1114 | |||
| 1115 | (defun xref-apropos-regexp (pattern) | ||
| 1116 | "Return an Emacs regexp from PATTERN similar to `apropos'." | ||
| 1117 | (apropos-parse-pattern | ||
| 1118 | (if (string-equal (regexp-quote pattern) pattern) | ||
| 1119 | ;; Split into words | ||
| 1120 | (or (split-string pattern "[ \t]+" t) | ||
| 1121 | (user-error "No word list given")) | ||
| 1122 | pattern))) | ||
| 1109 | 1123 | ||
| 1110 | 1124 | ||
| 1111 | ;;; Key bindings | 1125 | ;;; Key bindings |