From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#44983: Truncate long lines of grep output Date: Sun, 06 Dec 2020 23:54:53 +0200 Organization: LINKOV.NET Message-ID: <87zh2q61n6.fsf@mail.linkov.net> References: <87v9dlc3ti.fsf_-_@mail.linkov.net> <83ft4pik35.fsf@gnu.org> <87sg8p5kw0.fsf@mail.linkov.net> <83eek8hoyx.fsf@gnu.org> <87h7p4r1n9.fsf@mail.linkov.net> <62EB4762-278D-43E7-8699-BBDC47818A50@gnu.org> <87zh2w7ww1.fsf@mail.linkov.net> <83pn3reyjs.fsf@gnu.org> <87y2ie7for.fsf@mail.linkov.net> <87h7p0f611.fsf@mail.linkov.net> <87a6uqafmk.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12671"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: 44983@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 06 22:56:13 2020 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 1km20r-0003Cj-IE for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 06 Dec 2020 22:56:13 +0100 Original-Received: from localhost ([::1]:58668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1km20q-0007yS-9i for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 06 Dec 2020 16:56:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1km20g-0007yI-OH for bug-gnu-emacs@gnu.org; Sun, 06 Dec 2020 16:56:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1km20g-0000Xm-Gq for bug-gnu-emacs@gnu.org; Sun, 06 Dec 2020 16:56:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1km20g-0006Ak-FZ for bug-gnu-emacs@gnu.org; Sun, 06 Dec 2020 16:56:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 06 Dec 2020 21:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44983 X-GNU-PR-Package: emacs Original-Received: via spool by 44983-submit@debbugs.gnu.org id=B44983.160729174723702 (code B ref 44983); Sun, 06 Dec 2020 21:56:02 +0000 Original-Received: (at 44983) by debbugs.gnu.org; 6 Dec 2020 21:55:47 +0000 Original-Received: from localhost ([127.0.0.1]:51548 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1km20Q-0006AE-Qz for submit@debbugs.gnu.org; Sun, 06 Dec 2020 16:55:47 -0500 Original-Received: from relay10.mail.gandi.net ([217.70.178.230]:54261) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1km20P-0006A2-Oo for 44983@debbugs.gnu.org; Sun, 06 Dec 2020 16:55:46 -0500 Original-Received: from mail.gandi.net (m91-129-99-98.cust.tele2.ee [91.129.99.98]) (Authenticated sender: juri@linkov.net) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 26418240002; Sun, 6 Dec 2020 21:55:37 +0000 (UTC) In-Reply-To: (Dmitry Gutov's message of "Sun, 6 Dec 2020 23:37:11 +0200") 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:195179 Archived-At: >> OTOH, ripgrep has the suitable options: >> -M, --max-columns NUM >> Don’t print lines longer than this limit in bytes. Longer lines are omitted, >> and only the number of matches in that line is printed. >> --max-columns-preview >> When the --max-columns flag is used, ripgrep will by default completely >> replace any line that is too long with a message indicating that a matching >> line was removed. When this flag is combined with --max-columns, a preview >> of the line (corresponding to the limit size) is shown instead, where the >> part of the line exceeding the limit is not shown. > > You can experiment with these Right Now(tm) by customizing > xref-search-program-alist (as well as xref-search-program). They'll only > affect commands that use xref-matches-in-files, though. You mean adding "-M 200 --max-columns-preview" to xref-search-program-alist? It works nice, thanks. Should this be added by default? >> Wouldn't it be unthinkable to add support of ripgrep to grep.el? >> This will allow switching to ripgrep when there is a need to >> search in files with long lines. > > I'm fairly sure nothing in terms of politics is stopping us here, but if we > wanted to update grep.el's abstractions to use different search programs, > it looks like a bigger job to me. > > Though maybe you can get away with customizing a select number of > variables? Like grep-template, grep-find-template, etc. I customized grep-find-template to "find -type f -print0 | sort -z | xargs -0 -e rg -inH --color always --no-heading -M 200 --max-columns-preview -e " But this also requires customizing grep-match-regexp to the value "\033\\[[0-9]*m\033\\[[0-9]*1m\033\\[[0-9]*1m\\(.*?\\)\033\\[[0-9]*0m" provided by Simon in bug#41766. And also required a small fix in grep.el: diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index dafba22f77..0a5fd6bf5d 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -412,7 +412,7 @@ grep-regexp-alist (- mend beg)))))) nil nil (3 '(face nil display ":"))) - ("^Binary file \\(.+\\) matches$" 1 nil nil 0 1)) + ("^Binary file \\(.+\\) matches" 1 nil nil 0 1)) "Regexp used to match grep hits. See `compilation-error-regexp-alist' for format details.")