From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#46859: 28.0.50; [PATCH]: Add option to truncate long lines in xref.el Date: Mon, 01 Mar 2021 23:07:36 +0100 Message-ID: References: Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4513"; mail-complaints-to="usenet@ciao.gmane.io" To: 46859@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 01 23:12:47 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 1lGqmV-00015l-DP for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Mar 2021 23:12:47 +0100 Original-Received: from localhost ([::1]:36052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGqmU-0000YG-Ex for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Mar 2021 17:12:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGqhu-0003mq-4F for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 17:08:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGqht-0003N4-T7 for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 17:08:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lGqht-0002LR-Mo for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 17:08:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 01 Mar 2021 22:08:01 +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.16146364628982 (code B ref 46859); Mon, 01 Mar 2021 22:08:01 +0000 Original-Received: (at 46859) by debbugs.gnu.org; 1 Mar 2021 22:07:42 +0000 Original-Received: from localhost ([127.0.0.1]:51100 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGqha-0002Ko-1O for submit@debbugs.gnu.org; Mon, 01 Mar 2021 17:07:42 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:19569) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGqhX-0002Kf-Nm for 46859@debbugs.gnu.org; Mon, 01 Mar 2021 17:07:40 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: theo@thornhill.no 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:201172 Archived-At: --=-=-= Content-Type: text/plain There was a typo in the previous patch, sorry about that! -- Theo --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-option-to-truncate-long-lines.patch >From 1697033f216a9792e374bda20816ff91491aa38e Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Mon, 1 Mar 2021 23:05:32 +0100 Subject: [PATCH] Add option to truncate long lines * (xref-truncate-line-to): New option. Set cut-off point for long lines in xref buffer * (xref--truncate-long-lines-p): Helper function for xref--insert-xrefs. * (xref--insert-xrefs): By truncating long lines we get a huge speedup both when invoking xref, and while navigating the xref buffer. --- lisp/progmodes/xref.el | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 18fdd963fb..c893137973 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -872,6 +872,19 @@ beginning of the line." (xref--search-property 'xref-item)) (xref-show-location-at-point)) +(defcustom xref-truncate-line-to 500 + "Max number of columns to display in xref buffer." + :type '(choice + (fixnum :tag "Number of lines") + (null :tag "Don't truncate")) + :version "28.1" + :package-version '(xref . "1.0.5")) + +(defun xref--truncate-long-lines-p (summary) + (cl-check-type summary xref-item) + (and (numberp xref-truncate-line-to) + (> (length summary) xref-truncate-line-to))) + (defun xref--insert-xrefs (xref-alist) "Insert XREF-ALIST in the current-buffer. XREF-ALIST is of the form ((GROUP . (XREF ...)) ...), where @@ -902,14 +915,24 @@ GROUP is a string for decoration purposes and XREF is an " "))) ;; 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)) + ;; Overwrite if we want to truncate long lines. + (if (xref--truncate-long-lines-p new-summary) + (delete-region + (save-excursion (forward-line -1) (point)) + (point)) + (when-let ((column (xref-location-column location))) + (delete-region + (save-excursion + (forward-line -1) + (move-to-column (+ (length prefix) column)) + (point)) (point)) - (point)) - (setq new-summary (substring summary column) prefix ""))) + (setq new-summary (substring summary column) prefix "")))) + ;; Truncate + (when (xref--truncate-long-lines-p new-summary) + (setq new-summary + (concat (substring new-summary 0 xref-truncate-line-to) + " (...truncated)"))) (xref--insert-propertized (list 'xref-item xref 'mouse-face 'highlight -- 2.24.3 (Apple Git-128) --=-=-=--