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: Thu, 03 Dec 2020 23:17:08 +0200 Organization: LINKOV.NET Message-ID: <87y2ie7for.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> 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="27182"; 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, dgutov@yandex.ru To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 03 22:40:35 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 1kkwL4-0006xh-RE for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Dec 2020 22:40:34 +0100 Original-Received: from localhost ([::1]:55290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkwL3-0005Xu-Q3 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 03 Dec 2020 16:40:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkwKa-00052P-CB for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2020 16:40:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:58667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kkwKa-0000Nf-4N for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2020 16:40:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kkwKa-0007X7-1P for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2020 16:40:04 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 03 Dec 2020 21:40:03 +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.160703155028805 (code B ref 44983); Thu, 03 Dec 2020 21:40:03 +0000 Original-Received: (at 44983) by debbugs.gnu.org; 3 Dec 2020 21:39:10 +0000 Original-Received: from localhost ([127.0.0.1]:41965 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkwJi-0007UW-Fc for submit@debbugs.gnu.org; Thu, 03 Dec 2020 16:39:10 -0500 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:40223) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kkwJh-0007UK-Ex for 44983@debbugs.gnu.org; Thu, 03 Dec 2020 16:39:09 -0500 X-Originating-IP: 91.129.99.98 Original-Received: from mail.gandi.net (m91-129-99-98.cust.tele2.ee [91.129.99.98]) (Authenticated sender: juri@linkov.net) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 3023BC0002; Thu, 3 Dec 2020 21:39:01 +0000 (UTC) In-Reply-To: <83pn3reyjs.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 03 Dec 2020 16:47:51 +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:194926 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit > And when you say "slow" do you mean slow in receiving Grep output, > slow in displaying the received output, or slow in moving though the > *grep* buffer after everything was displayed? Slow in receiving, slow in displaying, or but not slow in moving though the hidden parts of long lines. >> Then instead of hiding long lines using font-lock, >> I tried to do the same using the process filter: >> >> (defun grep-filter () >> (save-excursion >> (let ((end (point-marker))) >> (goto-char compilation-filter-start) >> (forward-line 0) >> (while (< (point) end) >> (let ((eol (line-end-position))) >> (when (> (- eol (point)) 64) >> (put-text-property (+ 64 (point)) (line-end-position) >> 'display "[…]")) >> (forward-line 1)))))) >> >> Still very slow. > > Same question as above. Slow in receiving and slow in displaying. >> Then tried to delete the excessive parts of long lines: >> >> (defun grep-filter-try () >> (save-excursion >> (let ((end (point-marker))) >> (goto-char compilation-filter-start) >> (forward-line 0) >> (while (< (point) end) >> (let ((eol (line-end-position))) >> (when (> (- eol (point)) 64) >> (delete-region (min (+ 64 (point)) (point-max)) (line-end-position))) >> (forward-line 1)))))) >> >> Now Emacs becomes more responsive. But still output processing >> takes too much time. > > What is "output processing", and how did you measure the time it > takes? Measuring visually, it takes too much time to output the long lines. >> Finally, the last thing to try was the same solution that Richard >> showed in bug#44941: >> >> grep -a "$@" | cut -c -200 >> >> that gives the best possible result. >> >> I doubt that it would be possible to invent something better. >> >> So the question is should this be customizable for adding >> `cut -c` automatically to the end of the grep command line, >> possibly with `stdbuf -oL` suggested by Andreas. > > I suggested to request the equivalent of "cut -c" to be a feature > added to Grep. > > Failing that, I don't think Emacs should do something like that, > especially since 'cut' is not guaranteed to be available. Users who > have such problems can, of course, modify the Grep command to do that. Finally I solved the long-standing problem by customizing grep-find-template to "find -type f -print0 | sort -z | xargs -0 -e grep --color=always -inH -e | cut -c -200" I'm not sure if something like this could be added to grep, but here is an example how such a new option could look: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=gnu-sort-cut.patch diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index dafba22f77..a5a2142a9e 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -534,6 +534,7 @@ grep-find-use-xargs (const :tag "find -exec {} +" exec-plus) (const :tag "find -print0 | xargs -0" gnu) (const :tag "find -print0 | sort -z | xargs -0'" gnu-sort) + (const :tag "find -print0 | sort -z | xargs -0' ... | cut -c -200" gnu-sort-cut) string (const :tag "Not Set" nil)) :set #'grep-apply-setting @@ -722,7 +723,8 @@ grep-compute-defaults (goto-char (point-min)) (search-forward "--color" nil t)) ;; Windows and DOS pipes fail `isatty' detection in Grep. - (if (memq system-type '(windows-nt ms-dos)) + (if (or (eq grep-find-use-xargs 'gnu-sort-cut) + (memq system-type '(windows-nt ms-dos))) 'always 'auto))))) (unless (and grep-command grep-find-command @@ -775,6 +777,9 @@ grep-compute-defaults ((eq grep-find-use-xargs 'gnu-sort) (format "%s . -type f -print0 | sort -z | \"%s\" -0 %s" find-program xargs-program grep-command)) + ((eq grep-find-use-xargs 'gnu-sort-cut) + (format "%s . -type f -print0 | sort -z | \"%s\" -0 %s | cut -c -200" + find-program xargs-program grep-command)) ((memq grep-find-use-xargs '(exec exec-plus)) (let ((cmd0 (format "%s . -type f -exec %s" find-program grep-command)) @@ -803,6 +808,9 @@ grep-compute-defaults ((eq grep-find-use-xargs 'gnu-sort) (format "%s -type f -print0 | sort -z | \"%s\" -0 %s" find-program xargs-program gcmd)) + ((eq grep-find-use-xargs 'gnu-sort-cut) + (format "%s -type f -print0 | sort -z | \"%s\" -0 %s | cut -c -200" + find-program xargs-program gcmd)) ((eq grep-find-use-xargs 'exec) (format "%s -type f -exec %s %s %s%s" find-program gcmd quot-braces null quot-scolon)) --=-=-=--