From: Dmitry Gutov <dgutov@yandex.ru>
To: Theodor Thornhill <theo@thornhill.no>,
juri@linkov.net, 46859@debbugs.gnu.org
Subject: bug#46859: 28.0.50; [PATCH]: Add option to truncate long lines in xref.el
Date: Sun, 7 Mar 2021 05:22:29 +0200 [thread overview]
Message-ID: <da40dd00-e289-186d-b9bc-411dd7a10471@yandex.ru> (raw)
In-Reply-To: <92f18de5-6dae-8041-2da0-e4b782f9003e@yandex.ru>
[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]
On 07.03.2021 00:26, Dmitry Gutov wrote:
> - What do you think about making an effort to actually retain all the
> matches in the output? That would mean interpreting the
> xref-truncate-line-to value (or however the var could be renamed) as the
> maximum number of chars to render on the line *per match*. And if there
> is too much text between them, those parts can become "(truncated...)".
> Your current implementation can cut off valid matches, and we probably
> want to preserve them if feasible. OTOH, the default value could go down
> to 200 with this approach.
Please try out the attached preparation patch.
It improves the performance of the "very long line" case drastically
over here, while not doing any truncation yet. Looks like we regressed
that case when we added rendering of multiple matches on the same line.
We can add the truncation feature on top of it.
Probably also in xref--collect-matches-1 (truncating the value of
SUMMARY just before the xref-make-match call).
Alternatively, we could experiment with hiding parts of the long line
using some display/visibility features (except the truncate-lines
variable, that one keeps things slow). That could be done in
xref--insert-xrefs or somewhere nearby. That is trickier, though, given
that we'll probably want to unhide it (wholly or partially) when
iterating over matches inside.
[-- Attachment #2: xref-insert-xrefs-sparingly.diff --]
[-- Type: text/x-patch, Size: 4839 bytes --]
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 18fdd963fb..5c5a0508de 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -886,30 +886,24 @@ xref--insert-xrefs
(length (and line (format "%d" line)))))
for line-format = (and max-line-width
(format "%%%dd: " max-line-width))
- with prev-line-key = nil
+ with prev-group = nil
+ with prev-line = nil
do
(xref--insert-propertized '(face xref-file-header xref-group t)
group "\n")
(cl-loop for (xref . more2) on xrefs do
(with-slots (summary location) xref
(let* ((line (xref-location-line location))
- (new-summary summary)
- (line-key (list (xref-location-group location) line))
(prefix
- (if line
- (propertize (format line-format line)
- 'face 'xref-line-number)
- " ")))
+ (cond
+ ((not line) " ")
+ ((equal line prev-line) "")
+ (t (propertize (format line-format line)
+ 'face 'xref-line-number)))))
;; Render multiple matches on the same line, together.
- (when (and line (equal prev-line-key line-key))
- (when-let ((column (xref-location-column location)))
- (delete-region
- (save-excursion
- (forward-line -1)
- (move-to-column (+ (length prefix) column))
- (point))
- (point))
- (setq new-summary (substring summary column) prefix "")))
+ (when (and (equal prev-group group)
+ (not (equal prev-line line)))
+ (insert "\n"))
(xref--insert-propertized
(list 'xref-item xref
'mouse-face 'highlight
@@ -917,9 +911,10 @@ xref--insert-xrefs
'help-echo
(concat "mouse-2: display in another window, "
"RET or mouse-1: follow reference"))
- prefix new-summary)
- (setq prev-line-key line-key)))
- (insert "\n"))))
+ prefix summary)
+ (setq prev-line line
+ prev-group group))))
+ (insert "\n")))
(defun xref--analyze (xrefs)
"Find common filenames in XREFS.
@@ -1678,20 +1673,30 @@ xref--collect-matches
syntax-needed)))))
(defun xref--collect-matches-1 (regexp file line line-beg line-end syntax-needed)
- (let (matches)
+ (let (match-pairs 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)
+ (or (null match-pairs)
(> (point) line-beg))
(re-search-forward regexp line-end t))
- (let* ((beg-column (- (match-beginning 0) line-beg))
- (end-column (- (match-end 0) line-beg))
+ (push (cons (match-beginning 0)
+ (match-end 0))
+ match-pairs))
+ (setq match-pairs (nreverse match-pairs))
+ (while match-pairs
+ (let* ((beg-end (pop match-pairs))
+ (beg-column (- (car beg-end) line-beg))
+ (end-column (- (cdr beg-end) line-beg))
(loc (xref-make-file-location file line beg-column))
- (summary (buffer-substring line-beg line-end)))
+ (summary (buffer-substring (if matches (car beg-end) line-beg)
+ (if match-pairs
+ (caar match-pairs)
+ line-end))))
+ (when matches
+ (cl-decf beg-column (- (car beg-end) line-beg))
+ (cl-decf end-column (- (car beg-end) line-beg)))
(add-face-text-property beg-column end-column 'xref-match
t summary)
(push (xref-make-match summary loc (- end-column beg-column))
next prev parent reply other threads:[~2021-03-07 3:22 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 20:40 bug#46859: 28.0.50; [PATCH]: Add option to truncate long lines in xref.el Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-01 22:07 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-02 19:25 ` Juri Linkov
2021-03-02 21:13 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-02 21:37 ` Dmitry Gutov
2021-03-02 21:45 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-02 22:14 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-02 22:37 ` Dmitry Gutov
2021-03-03 16:13 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-03 17:29 ` Dmitry Gutov
2021-03-03 19:54 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-06 22:26 ` Dmitry Gutov
2021-03-07 1:29 ` Dmitry Gutov
2021-03-07 3:22 ` Dmitry Gutov [this message]
2021-03-07 20:03 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-08 2:48 ` Dmitry Gutov
2021-03-07 20:16 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-07 20:26 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-03-08 2:56 ` Dmitry Gutov
2021-03-10 2:06 ` Dmitry Gutov
2021-05-17 15:27 ` Lars Ingebrigtsen
2021-05-17 15:44 ` Dmitry Gutov
2021-05-17 16:57 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-18 0:39 ` Dmitry Gutov
2021-03-03 9:05 ` Juri Linkov
2021-03-03 9:52 ` Gregory Heytings
2021-03-03 12:47 ` Dmitry Gutov
2021-03-03 13:53 ` Gregory Heytings
2021-03-03 14:00 ` Dmitry Gutov
2021-03-03 15:04 ` Gregory Heytings
2021-03-03 17:11 ` Gregory Heytings
2021-03-03 17:26 ` Dmitry Gutov
2021-03-03 17:42 ` Gregory Heytings
2021-03-03 19:14 ` Dmitry Gutov
2021-03-03 19:34 ` Gregory Heytings
2021-03-03 19:52 ` Juri Linkov
2021-03-03 20:34 ` Gregory Heytings
2021-03-04 3:36 ` Eli Zaretskii
2021-03-04 9:19 ` Gregory Heytings
2021-03-04 14:08 ` Eli Zaretskii
2021-03-04 14:39 ` Gregory Heytings
2021-03-04 15:13 ` Eli Zaretskii
2021-03-04 16:47 ` Gregory Heytings
2021-03-04 17:13 ` Eli Zaretskii
2021-03-04 17:35 ` Gregory Heytings
2021-03-04 18:28 ` Eli Zaretskii
2021-03-06 12:31 ` Dmitry Gutov
2021-03-06 12:37 ` Dmitry Gutov
2021-03-06 12:54 ` Gregory Heytings
2021-03-06 14:26 ` Dmitry Gutov
2021-03-06 22:47 ` Gregory Heytings
2021-03-06 23:00 ` Dmitry Gutov
2021-03-06 23:24 ` Gregory Heytings
2021-03-07 3:08 ` Dmitry Gutov
2021-03-07 8:13 ` Gregory Heytings
2021-03-08 3:24 ` Dmitry Gutov
2021-03-08 8:26 ` Gregory Heytings
2021-03-08 11:47 ` Dmitry Gutov
2021-03-06 12:49 ` Gregory Heytings
2021-03-06 14:07 ` Dmitry Gutov
2021-03-03 20:30 ` Dmitry Gutov
2021-03-03 21:06 ` Gregory Heytings
2021-03-06 12:44 ` Dmitry Gutov
2021-03-06 12:58 ` Gregory Heytings
2021-03-06 14:06 ` Dmitry Gutov
2021-03-06 22:55 ` Gregory Heytings
2021-03-03 19:59 ` Juri Linkov
2021-03-04 2:50 ` Dmitry Gutov
2021-03-04 9:24 ` Juri Linkov
2021-03-04 17:20 ` Dmitry Gutov
2021-03-04 17:56 ` Juri Linkov
2021-03-04 18:57 ` Dmitry Gutov
2021-03-06 12:39 ` Dmitry Gutov
2021-03-03 16:14 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=da40dd00-e289-186d-b9bc-411dd7a10471@yandex.ru \
--to=dgutov@yandex.ru \
--cc=46859@debbugs.gnu.org \
--cc=juri@linkov.net \
--cc=theo@thornhill.no \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.