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: Sun, 7 Mar 2021 05:22:29 +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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------B63986FBEFE02685EE38A73F" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31519"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 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 Sun Mar 07 04:23:21 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 1lIk0n-000855-Dh for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 07 Mar 2021 04:23:21 +0100 Original-Received: from localhost ([::1]:54996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIk0m-0006Sb-0v for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Mar 2021 22:23:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIk0U-0006SG-T0 for bug-gnu-emacs@gnu.org; Sat, 06 Mar 2021 22:23:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lIk0U-0000bs-L7 for bug-gnu-emacs@gnu.org; Sat, 06 Mar 2021 22:23:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lIk0U-0005NV-HC for bug-gnu-emacs@gnu.org; Sat, 06 Mar 2021 22:23: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: Sun, 07 Mar 2021 03:23: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.161508736120629 (code B ref 46859); Sun, 07 Mar 2021 03:23:02 +0000 Original-Received: (at 46859) by debbugs.gnu.org; 7 Mar 2021 03:22:41 +0000 Original-Received: from localhost ([127.0.0.1]:38699 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lIk08-0005Mf-Lh for submit@debbugs.gnu.org; Sat, 06 Mar 2021 22:22:40 -0500 Original-Received: from mail-wm1-f54.google.com ([209.85.128.54]:50375) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lIk07-0005MT-H6 for 46859@debbugs.gnu.org; Sat, 06 Mar 2021 22:22:40 -0500 Original-Received: by mail-wm1-f54.google.com with SMTP id i9so3974736wml.0 for <46859@debbugs.gnu.org>; Sat, 06 Mar 2021 19:22:39 -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=altuaoKsVg9y0CPzLztm7Yu6oldIGeNZw8vCI4U3ihk=; b=pIm6dCGhPRQl75ScgpbvQhxT4r/VJiaYVIN4+rqnroZRL3TdebzVq5ErfNgmRkB1nw IaLuPpVgpXYt9TSNq4nCwQ67VelVPpUKUaDM0+nNdCsy5zBxxAgMzIIUv35gICl/vVBt DcH+gZ9pNsqB1ndSM+aQ3KIqrIohrtuscK0CNLG4LATf9XdMbiU1xnkPDpaDbUjrD/gd hsJf7HhgTGGlEm1Xpsd9ShKgskdyjdPe7C0hZBj5DJ1lDbI4MuwyrTnNXw1+6EMIIa5Q 5jeoDEW3JenLEkpK0+8NYPfZ16JOwHvE78e2FLaett0KztvAtY6ASnYu5SLG64JNUlmE MZfQ== 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=altuaoKsVg9y0CPzLztm7Yu6oldIGeNZw8vCI4U3ihk=; b=tpaJd3CHPUNIJ+4ujoZpApzlscbKwes8qt0NkusYjKyv/2nXO3IA3j7J7GDMqa8rlv iEhjeCbTaCqW8ow9oUofj1Tl9YQt4E87FoMfj+nYgAbDov5ycE1CRSMY5i0bFefNcDPM npoCtMtiG2oFWg2ZyM3T2TiDx9il1vFLJvoO2f4+xWOi5xgzEP7AQn2TedtZzWKfHrmi MxWLuy0Fjz8n9T75plaK2GdDW8c3czfRPFbGFUplBF6H23Zg96BVnq2zyrik6sU1guER PG67iHyzciqA7bDHT6oRsasEm1A43lEhEih4WPhRVnNFem6W8DXVtLOb2rjHXcsVbxwk 2l9g== X-Gm-Message-State: AOAM531IvjdTItR6xVwN0QAY7bCVwK7dMJaW2fm98zvj2rXqI//EnhLu KROeCTsJSb0SbhkU3NmFOWyNNF8ymlw= X-Google-Smtp-Source: ABdhPJwbMBpBwQE5mN0r26XT1GNVx7VgnDMO2fZgxhm95Mc/282PbLmqVW1wyo3iAw5gUynXZzImAQ== X-Received: by 2002:a1c:4e0e:: with SMTP id g14mr15475435wmh.160.1615087353723; Sat, 06 Mar 2021 19:22:33 -0800 (PST) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id u4sm12187509wrm.24.2021.03.06.19.22.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Mar 2021 19:22:33 -0800 (PST) In-Reply-To: <92f18de5-6dae-8041-2da0-e4b782f9003e@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:201712 Archived-At: This is a multi-part message in MIME format. --------------B63986FBEFE02685EE38A73F Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------B63986FBEFE02685EE38A73F Content-Type: text/x-patch; charset=UTF-8; name="xref-insert-xrefs-sparingly.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="xref-insert-xrefs-sparingly.diff" 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)) --------------B63986FBEFE02685EE38A73F--