1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-28 19:42:02 +00:00

New option etags-xref-prefer-current-file

* lisp/progmodes/etags.el (etags-xref-prefer-current-file):
New user option (bug#2544).
(xref-backend-definitions): Use it.
This commit is contained in:
Dmitry Gutov 2021-08-06 03:12:40 +03:00
parent f65958a94d
commit d5a2fdeefb
2 changed files with 23 additions and 1 deletions

View File

@ -3689,6 +3689,9 @@ Emacs constructs the nondirectory part of the auto-save file name by
applying that 'secure-hash' to the buffer file name. This avoids any
risk of excessively long file names.
** New variable 'etags-xref-prefer-current-file' to change the order
of definitions returned by the etags Xref backend.
* Changes in Emacs 28.1 on Non-Free Operating Systems

View File

@ -2059,6 +2059,11 @@ for \\[find-tag] (which see)."
If you want `xref-find-definitions' to find the tagged files by their
file name, add `tag-partial-file-name-match-p' to the list value.")
(defcustom etags-xref-prefer-current-file nil
"Non-nil to show the matches in the current file first."
:type 'boolean
:version "28.1")
;;;###autoload
(defun etags--xref-backend () 'etags)
@ -2074,7 +2079,21 @@ file name, add `tag-partial-file-name-match-p' to the list value.")
(find-tag--completion-ignore-case))
(cl-defmethod xref-backend-definitions ((_backend (eql 'etags)) symbol)
(etags--xref-find-definitions symbol))
(let ((file (and buffer-file-name (expand-file-name buffer-file-name)))
(definitions (etags--xref-find-definitions symbol))
same-file-definitions)
(when (and etags-xref-prefer-current-file file)
(cl-delete-if
(lambda (definition)
(when (equal file
(xref-location-group
(xref-item-location definition)))
(push definition same-file-definitions)
t))
definitions)
(setq definitions (nconc (nreverse same-file-definitions)
definitions)))
definitions))
(cl-defmethod xref-backend-apropos ((_backend (eql 'etags)) pattern)
(etags--xref-find-definitions (xref-apropos-regexp pattern) t))