From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs 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 Message-ID: References: <87im69uzlt.fsf@mail.linkov.net> <25782781-4baa-5d44-99a1-2e57552ab3a0@yandex.ru> <666564dc-0252-6bf5-04e1-58c9916cffbe@yandex.ru> <92f18de5-6dae-8041-2da0-e4b782f9003e@yandex.ru> <5cca8644-f111-57b6-442d-e39f21090fea@yandex.ru> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------C48D6F379D558C4D475CE693" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30191"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 To: Theodor Thornhill , juri@linkov.net, 46859@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 10 03:07:27 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lJoFz-0007lW-0X for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Mar 2021 03:07:27 +0100 Original-Received: from localhost ([::1]:34438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJoFy-0007lc-3D for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 09 Mar 2021 21:07:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJoFb-0007lI-SZ for bug-gnu-emacs@gnu.org; Tue, 09 Mar 2021 21:07:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lJoFa-00035T-8l for bug-gnu-emacs@gnu.org; Tue, 09 Mar 2021 21:07:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lJoFa-0006eF-3d for bug-gnu-emacs@gnu.org; Tue, 09 Mar 2021 21:07:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 10 Mar 2021 02:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46859 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 46859-submit@debbugs.gnu.org id=B46859.161534201625542 (code B ref 46859); Wed, 10 Mar 2021 02:07:02 +0000 Original-Received: (at 46859) by debbugs.gnu.org; 10 Mar 2021 02:06:56 +0000 Original-Received: from localhost ([127.0.0.1]:48321 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJoFT-0006du-Q5 for submit@debbugs.gnu.org; Tue, 09 Mar 2021 21:06:56 -0500 Original-Received: from mail-ej1-f53.google.com ([209.85.218.53]:34511) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lJoFR-0006dg-RN for 46859@debbugs.gnu.org; Tue, 09 Mar 2021 21:06:55 -0500 Original-Received: by mail-ej1-f53.google.com with SMTP id hs11so34169546ejc.1 for <46859@debbugs.gnu.org>; Tue, 09 Mar 2021 18:06:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=SLYvQE56+CkTAbcXgMqA+OSmE6ef/mqAmVQDokSUnkI=; b=Sx4OtC/FFDxQvf9trfb49BKSeI2oFGFGwii7kX2G75wqs5W/bZA6CwWYBURvADmwZ+ 0Hx/yC510Xaob3SPA7mjfl+5Gga1pJZhu+8XCw6ZARBTz3bD1TrEd8X7uTr5rYtTL3nB FO+/VJkPBatNc4X/Dy2MIAg2smt2+HPJ0IKt2xuXkkYaJkTWjJkGvAOz+FfH/DwZLmeW Y8a4Ydl9LYJY9zN7C+B2Gu2A9Zlo8a/VKhd1cWwHDPJWMuw15FWvweKkAe1Qd+RLhkxo TmdP5G0WuggL6JONrCAINVgjDVhwegD9hSGvQrBiRNHH7AQHHB8JDiWy4urS7IogpYzq /dwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:references:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=SLYvQE56+CkTAbcXgMqA+OSmE6ef/mqAmVQDokSUnkI=; b=B8IGp6oFBdxHyS4S06Db3Togronq5p46sIvyPGAP5YT/cucCFHoO0L9ILDOEEpeg7G bAm/wGS/JFNtYvSmhIfXvmmVdVBGr0J3FyqyJXLR2z4n2LCFPYxFa462qZ6bRICdKLzV ZBbcOomy2bx+wTsmdboacRvk9QZbur1e++mFgVjuJqnaBbATWqHHFEl6F4r3V7m+yGaj Oe3WZv8OAgc73QnIbk3U16fR9ZLxZbJ4tEXqcUauXGeA/+0pcgVf6Wx9ojZb+Mo6xLAT CJsE+Prh+sl+Apv+SVYuaJsChckDpA+lZMOHSvctqbYagOlS2yugkBTCf3SJM+eRpIDK d+eg== X-Gm-Message-State: AOAM533PWyWM8zlDv94JtRlpK6bF45Omccg54nbf0jMZXhHyAY36jErV fiPu5+6ZfzfF9GRqY6G8NQ03GgOl3qs= X-Google-Smtp-Source: ABdhPJzj8hru0fcnDTYKljWJ6hSSP+ku7DgYnUpDE/kkttbQIy1hOpqla+T52h3232BZ45XVgckpyA== X-Received: by 2002:a17:906:6047:: with SMTP id p7mr1017137ejj.400.1615342007867; Tue, 09 Mar 2021 18:06:47 -0800 (PST) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id l1sm5303999edt.59.2021.03.09.18.06.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Mar 2021 18:06:38 -0800 (PST) In-Reply-To: <5cca8644-f111-57b6-442d-e39f21090fea@yandex.ru> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:201951 Archived-At: This is a multi-part message in MIME format. --------------C48D6F379D558C4D475CE693 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------C48D6F379D558C4D475CE693 Content-Type: text/x-patch; charset=UTF-8; name="xref-long-line-visibility-truncation.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xref-long-line-visibility-truncation.diff" 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)) --------------C48D6F379D558C4D475CE693--