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: Wed, 10 Mar 2021 04:06:11 +0200 [thread overview]
Message-ID: <f67db58d-09ee-132a-1370-03e6cdddd8dc@yandex.ru> (raw)
In-Reply-To: <5cca8644-f111-57b6-442d-e39f21090fea@yandex.ru>
[-- Attachment #1: Type: text/plain, Size: 728 bytes --]
On 08.03.2021 04:56, Dmitry Gutov wrote:
> If you still get lines that are loo long in these cases, even with all
> extra text snipped away, hiding parts of the summary using text
> properties should be possible. I just tried putting 'invisible' on the
> whole line after column 600, and scrolling became instantaneous again.
>
> As long as we undo these properties (or, perhaps, scroll the visible
> part?) when xref-next-line is called, the user would still be able to
> visit all matches.
Here's an experimental patch that does this.
As long as there are no matches near the end of the long string,
everything seems snappy. If we do end up scrolling to near its end,
though, moving around that line becomes slower.
[-- Attachment #2: xref-long-line-visibility-truncation.diff --]
[-- Type: text/x-patch, Size: 2689 bytes --]
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index c066d9dc02..8decfcbb6c 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -891,6 +891,39 @@ xref--mouse-2
(xref--search-property 'xref-item))
(xref-show-location-at-point))
+(defcustom xref-truncate-to-width 400
+ "The column to visually \"truncate\" an Xref buffer line."
+ :type 'integer)
+
+(defun xref--apply-truncation ()
+ (add-to-invisibility-spec '(ellipsis . t))
+ (let (;; FIXME: Treat the line number prefix specially.
+ (bol (line-beginning-position))
+ (eol (line-end-position))
+ (inhibit-read-only t)
+ pos)
+ (when (and (> (- eol bol)
+ xref-truncate-to-width)
+ ;; Either truncation not applied yet, or it hides the current
+ ;; position: need to refresh.
+ (or (and (null (get-text-property (1- eol) 'invisible))
+ (null (get-text-property bol 'invisible)))
+ (get-text-property (point) 'invisible)))
+ (cond
+ ((< (- (point) bol) xref-truncate-to-width)
+ (setq pos (+ bol xref-truncate-to-width))
+ (remove-text-properties bol pos '(invisible))
+ (put-text-property pos eol 'invisible 'ellipsis))
+ ((< (- eol (point)) xref-truncate-to-width)
+ (setq pos (- eol xref-truncate-to-width))
+ (remove-text-properties pos eol '(invisible))
+ (put-text-property bol pos 'invisible 'ellipsis))
+ (t
+ (setq pos (- (point) (/ xref-truncate-to-width 2)))
+ (put-text-property bol pos 'invisible 'ellipsis)
+ (remove-text-properties pos (+ pos xref-truncate-to-width) '(invisible))
+ (put-text-property (+ pos xref-truncate-to-width) eol 'invisible 'ellipsis))))))
+
(defun xref--insert-xrefs (xref-alist)
"Insert XREF-ALIST in the current-buffer.
XREF-ALIST is of the form ((GROUP . (XREF ...)) ...), where
@@ -934,6 +967,11 @@ xref--insert-xrefs
(setq prev-line line
prev-group group))))
(insert "\n"))
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (forward-line 1)
+ (xref--apply-truncation)))
(run-hooks 'xref-after-update-hook))
(defun xref--analyze (xrefs)
@@ -971,6 +1009,7 @@ xref--show-common-initialize
(buffer-undo-list t))
(erase-buffer)
(xref--insert-xrefs xref-alist)
+ (add-hook 'post-command-hook 'xref--apply-truncation nil t)
(goto-char (point-min))
(setq xref--original-window (assoc-default 'window alist)
xref--original-window-intent (assoc-default 'display-action alist))
next prev parent reply other threads:[~2021-03-10 2:06 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
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 [this message]
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=f67db58d-09ee-132a-1370-03e6cdddd8dc@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.