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 21:40:50 +0100 Message-ID: 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="30284"; 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 21:42:34 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 1lGpNB-0007lV-9n for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Mar 2021 21:42:33 +0100 Original-Received: from localhost ([::1]:40198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGpNA-0007aC-CT for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Mar 2021 15:42:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGpMg-0007Jt-BO for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 15:42:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39464) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGpMg-0007Ox-2J for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 15:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lGpMg-0006Oi-0X for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 15:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 01 Mar 2021 20:42:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 46859 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161463126924529 (code B ref -1); Mon, 01 Mar 2021 20:42:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Mar 2021 20:41:09 +0000 Original-Received: from localhost ([127.0.0.1]:51010 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGpLp-0006NY-1D for submit@debbugs.gnu.org; Mon, 01 Mar 2021 15:41:09 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:39218) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lGpLn-0006NR-FR for submit@debbugs.gnu.org; Mon, 01 Mar 2021 15:41:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGpLm-0006Ne-3X for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 15:41:07 -0500 Original-Received: from out2.migadu.com ([2001:41d0:2:aacc::]:18389) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGpLe-0006xU-Ed for bug-gnu-emacs@gnu.org; Mon, 01 Mar 2021 15:41:05 -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 Received-SPF: pass client-ip=2001:41d0:2:aacc::; envelope-from=theo@thornhill.no; helo=out2.migadu.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:201170 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi! When using the xref buffer, especially in combination with 'project-find-regexp', sometimes my projects has huge one-line files. The simplest example of these kind of files are the minified ".js" files that are compiled. Right now I have one at 500 000 columns, which admittedly is a lot. However, when 'project-find-regexp' searches these files and finds a hit in one of them, the search takes a long time. In addition, navigating the xref buffer when the results show up also takes a long time, because of the troubles emacs has with long lines. Before the supplied patch, one search with 'project-find-regexp' with ripgrep enabled takes around 3-4 seconds. With the supplied patch, the search is almost instantaneous. The added functionality is created to not kick in before a certain threshold, where 500 columns seems reasonably long. Anything above that will be truncated, but xref will still show that there was a hit. I'm sure the patch can be improved, so please, don't hesitate to tell me. I consider this a great improvement, and I hope you will to=C2=A7 Have a nice day, -- Theodor Thornhill --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-option-to-truncate-long-lines.patch >From dcc2078c20d8edd32407498c16d65ea46d44a3a0 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Mon, 1 Mar 2021 21:26:44 +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..98dacef94f 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) --=-=-=--