Skip to content

Commit

Permalink
New option etags-xref-prefer-current-file
Browse files Browse the repository at this point in the history
* lisp/progmodes/etags.el (etags-xref-prefer-current-file):
New user option (bug#2544).
(xref-backend-definitions): Use it.
  • Loading branch information
dgutov committed Aug 6, 2021
1 parent f65958a commit d5a2fde
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions etc/NEWS
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion lisp/progmodes/etags.el
Expand Up @@ -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)

Expand All @@ -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))
Expand Down

0 comments on commit d5a2fde

Please sign in to comment.