unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: matzikratzi@gmail.com, 2544@debbugs.gnu.org
Subject: bug#2544: 23.0.60; Could etags please try find a local tag first?
Date: Tue, 27 Jul 2021 02:15:30 +0300	[thread overview]
Message-ID: <a6510aa6-23a1-ca2b-a2ce-16b710bec08d@yandex.ru> (raw)
In-Reply-To: <87mtqglzlu.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 333 bytes --]

On 21.07.2021 13:39, Lars Ingebrigtsen wrote:
> The problem is definitely much more noticeable in the etags backend, so
> if your judgement is that that's where the option (and sorting) should
> go, then please go ahead.:-)

Here's a rough patch.

Please test and send feedback (how well it works, variable naming, 
docstring, etc).

[-- Attachment #2: etags-xref-prioritize-same-file.diff --]
[-- Type: text/x-patch, Size: 1530 bytes --]

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index f0180ceeec..2af160be74 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -2059,6 +2059,10 @@ etags-xref-find-definitions-tag-order
 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-prioritize-same-file nil
+  "Non-nil to show the matches in the same file first."
+  :type 'boolean)
+
 ;;;###autoload
 (defun etags--xref-backend () 'etags)
 
@@ -2072,7 +2076,21 @@ xref-backend-identifier-completion-ignore-case
   (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-prioritize-same-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))

  reply	other threads:[~2021-07-26 23:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-02 21:36 bug#2544: 23.0.60; Could etags please try find a local tag first? Matzi Kratzi
2021-07-19 14:48 ` Lars Ingebrigtsen
2021-07-19 15:56   ` Eli Zaretskii
2021-07-19 23:00     ` Dmitry Gutov
2021-07-20 11:51       ` Lars Ingebrigtsen
2021-07-20 16:15         ` Dmitry Gutov
2021-07-20 11:54       ` Eli Zaretskii
2021-07-20 16:22         ` Dmitry Gutov
2021-07-20 16:56           ` Eli Zaretskii
2021-07-20 22:36             ` Dmitry Gutov
2021-07-21 10:39               ` Lars Ingebrigtsen
2021-07-26 23:15                 ` Dmitry Gutov [this message]
2021-07-28 15:49                   ` Lars Ingebrigtsen
2021-08-02  2:11                     ` Dmitry Gutov
2021-08-02 11:36                       ` Eli Zaretskii
2021-08-06  0:17                         ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6510aa6-23a1-ca2b-a2ce-16b710bec08d@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=2544@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=matzikratzi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).