From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 36967@debbugs.gnu.org
Subject: bug#36967: 27.0.50; Duplicate lines in xref output
Date: Wed, 02 Dec 2020 23:30:18 +0200 [thread overview]
Message-ID: <87wnxz6glx.fsf@mail.linkov.net> (raw)
In-Reply-To: <950a9da4-4081-fe80-598f-eeb3931e24ad@yandex.ru> (Dmitry Gutov's message of "Thu, 8 Aug 2019 01:13:07 +0300")
[-- Attachment #1: Type: text/plain, Size: 630 bytes --]
>> I tried to use project-find-regexp more often than rgrep,
>> but unfortunately xref still has a fundamental flaw:
>> 0. emacs -Q
>> 1. M-x project-find-regexp RET regexp RET
>> 2. The output buffer *xref* contains duplicate lines
>> when regexp is found on the same line several times,
>> each duplicate output line has separate highlighting
>> for every regexp occurrence.
>
> I don't know how "fundamental" it is, but indeed, it's somewhat of
> a drawback. Suggestions for improving it (API change and/or implementation
> change) are welcome.
Here is the patch that makes the broken project-find-regexp usable:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: xref-usable.patch --]
[-- Type: text/x-diff, Size: 1522 bytes --]
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 3b19debb79..1f5e45f20d 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1461,11 +1461,10 @@ xref--collect-matches
syntax-needed)))))
(defun xref--collect-matches-1 (regexp file line line-beg line-end syntax-needed)
- (let (matches)
+ (let ((summary (buffer-substring line-beg line-end))
+ matches)
(when syntax-needed
(syntax-propertize line-end))
- ;; FIXME: This results in several lines with the same
- ;; summary. Solve with composite pattern?
(while (and
;; REGEXP might match an empty string. Or line.
(or (null matches)
@@ -1473,12 +1472,12 @@ xref--collect-matches-1
(re-search-forward regexp line-end t))
(let* ((beg-column (- (match-beginning 0) line-beg))
(end-column (- (match-end 0) line-beg))
- (loc (xref-make-file-location file line beg-column))
- (summary (buffer-substring line-beg line-end)))
+ (loc (xref-make-file-location file line beg-column)))
(add-face-text-property beg-column end-column 'xref-match
t summary)
- (push (xref-make-match summary loc (- end-column beg-column))
- matches)))
+ (unless matches
+ (push (xref-make-match summary loc (- end-column beg-column))
+ matches))))
(nreverse matches)))
(defun xref--find-file-buffer (file)
next prev parent reply other threads:[~2020-12-02 21:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-07 21:52 bug#36967: 27.0.50; Duplicate lines in xref output Juri Linkov
2019-08-07 22:13 ` Dmitry Gutov
2020-12-02 21:30 ` Juri Linkov [this message]
2020-12-03 1:35 ` Dmitry Gutov
2020-12-03 21:30 ` Juri Linkov
2020-12-03 23:44 ` Dmitry Gutov
2020-12-06 20:31 ` Juri Linkov
2020-12-09 3:53 ` Dmitry Gutov
2020-12-09 13:57 ` Dmitry Gutov
2020-12-21 1:42 ` 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=87wnxz6glx.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=36967@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
/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).