From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: charles@aurox.ch (Charles A. Roelli) Newsgroups: gmane.emacs.bugs Subject: bug#30503: 27.0.50; allow hiding M-x grep command line Date: Wed, 21 Feb 2018 21:30:40 +0100 Message-ID: References: <87sh9vs7p1.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1519244597 11203 195.159.176.226 (21 Feb 2018 20:23:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 21 Feb 2018 20:23:17 +0000 (UTC) Cc: 30503@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Feb 21 21:23:12 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eoav2-0002WK-9E for geb-bug-gnu-emacs@m.gmane.org; Wed, 21 Feb 2018 21:23:12 +0100 Original-Received: from localhost ([::1]:34669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoax2-00086B-TN for geb-bug-gnu-emacs@m.gmane.org; Wed, 21 Feb 2018 15:25:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoavS-0006zJ-0R for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2018 15:25:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoatv-0004tG-Gj for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2018 15:23:37 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47026) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eoatu-0004sA-VC for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2018 15:22:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eoatu-00018A-IX for bug-gnu-emacs@gnu.org; Wed, 21 Feb 2018 15:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: charles@aurox.ch (Charles A. Roelli) Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 21 Feb 2018 20:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30503 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30503-submit@debbugs.gnu.org id=B30503.15192444654279 (code B ref 30503); Wed, 21 Feb 2018 20:22:02 +0000 Original-Received: (at 30503) by debbugs.gnu.org; 21 Feb 2018 20:21:05 +0000 Original-Received: from localhost ([127.0.0.1]:54923 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eoasx-00016u-1j for submit@debbugs.gnu.org; Wed, 21 Feb 2018 15:21:03 -0500 Original-Received: from sinyavsky.aurox.ch ([37.35.109.145]:47868) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eoasu-000163-9J for 30503@debbugs.gnu.org; Wed, 21 Feb 2018 15:21:00 -0500 Original-Received: from sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) by sinyavsky.aurox.ch (Postfix) with ESMTP id 388942269F for <30503@debbugs.gnu.org>; Wed, 21 Feb 2018 20:21:16 +0000 (UTC) Authentication-Results: sinyavsky.aurox.ch (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=aurox.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aurox.ch; h= references:subject:subject:in-reply-to:to:from:from:message-id :date:date; s=dkim; t=1519244473; x=1520108474; bh=NKXmcaLVLIfOo WypnrZ8brzOZi48/RsBZ+ZeASEtY4U=; b=BK8T6s/66E1gypdZ/3QbRoTWpyVjB kjjCBtNLlHzsromWWw9X5BROVG1tXVsgzLi4oTBXEN4ENgHkdvOPTrOWTSiDx+rY Kppt20Fnzn7Tzh32EUOpZSbRG4rNLOja/vSQ5pLwht392NlH95dP3te2W60+XSPO cdTT/pHaL4qUb0= X-Virus-Scanned: Debian amavisd-new at test.virtualizor.com Original-Received: from sinyavsky.aurox.ch ([127.0.0.1]) by sinyavsky.aurox.ch (sinyavsky.aurox.ch [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 6L_dSIqPr4FV for <30503@debbugs.gnu.org>; Wed, 21 Feb 2018 20:21:13 +0000 (UTC) Original-Received: from gray (125.85.192.178.dynamic.wline.res.cust.swisscom.ch [178.192.85.125]) by sinyavsky.aurox.ch (Postfix) with ESMTPSA id 313AF22688; Wed, 21 Feb 2018 20:21:12 +0000 (UTC) In-reply-to: <87sh9vs7p1.fsf@mail.linkov.net> (message from Juri Linkov on Tue, 20 Feb 2018 22:54:34 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:143572 Archived-At: > From: Juri Linkov > Organization: LINKOV.NET > Date: Tue, 20 Feb 2018 22:54:34 +0200 > > retitle 30503 allow hiding M-x rgrep/lgrep/zrgrep command line > thanks > > > The first thing you see after M-x grep is a 1382-character line like > > this: > > > > find . -type d \( -path \*/SCCS -o -path \*/RCS -o -path \*/CVS -o -path > > \*/MCVS -o -path \*/.src -o -path \*/.svn -o -path \*/.git -o -path > > \*/.hg -o -path \*/.bzr -o -path \*/_MTN -o -path \*/_darcs -o -path > > \*/\{arch\} \) -prune -o \! -type d \( -name .\#\* -o -name \*.o -o -name > > \*\~ -o -name \*.bin -o -name \*.lbin -o -name \*.so -o -name \*.a -o -name > > \*.ln -o -name \*.blg -o -name \*.bbl -o -name \*.elc -o -name > > \*.lof -o -name \*.glo -o -name \*.idx -o -name \*.lot -o -name > > \*.fmt -o -name \*.tfm -o -name \*.class -o -name \*.fas -o -name > > \*.lib -o -name \*.mem -o -name \*.x86f -o -name \*.sparcf -o -name > > \*.dfsl -o -name \*.pfsl -o -name \*.d64fsl -o -name \*.p64fsl -o -name > > \*.lx64fsl -o -name \*.lx32fsl -o -name \*.dx64fsl -o -name > > \*.dx32fsl -o -name \*.fx64fsl -o -name \*.fx32fsl -o -name > > \*.sx64fsl -o -name \*.sx32fsl -o -name \*.wx64fsl -o -name > > \*.wx32fsl -o -name \*.fasl -o -name \*.ufsl -o -name \*.fsl -o -name > > \*.dxl -o -name \*.lo -o -name \*.la -o -name \*.gmo -o > > -name \*.mo -o -name \*.toc -o -name \*.aux -o -name \*.cp -o -name > > \*.fn -o -name \*.ky -o -name \*.pg -o -name \*.tp -o -name \*.vr -o -name > > \*.cps -o -name \*.fns -o -name \*.kys -o -name \*.pgs -o -name > > \*.tps -o -name \*.vrs -o -name \*.pyc -o -name \*.pyo \) -prune -o -type > > f \( -iname \* -o -iname .\[\!.\]\* -o -iname ..\?\* \) -exec > > grep --color -nH --null -e Emacs \{\} + > > > > Could we provide an option to hide the barrage of ignored directories > > and files? It might also be worth adding a text button or keybinding > > to toggle their visibility interactively. > > Yes, this is a real problem. Even though I set truncate-lines to t, > often there is a need to see grep switches at the end of the > command line. So there is a patch to hide uninteresting parts > under a button like is used to hide part of output by > elisp-last-sexp-toggle-display. It supports rgrep, lgrep and zrgrep. > > > diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el > index 14e251e..34a9b2f 100644 > --- a/lisp/progmodes/grep.el > +++ b/lisp/progmodes/grep.el > @@ -452,7 +452,13 @@ grep-mode-font-lock-keywords > ;; "filename=linenumber=" for lines with function names in "git grep -p". > ("^.+?\\([-=\0]\\)[0-9]+\\([-=]\\).*\n" (0 grep-context-face) > (1 (if (eq (char-after (match-beginning 1)) ?\0) > - `(face nil display ,(match-string 2)))))) > + `(face nil display ,(match-string 2))))) > + ;; Hide excessive part of the command from rgrep > + ("^find \\(\\. -type d .*\\\\)\\)" > + (1 (rgrep-command-hide))) > + ;; Hide excessive part of the command from lgrep > + ("^grep \\( *--exclude.*--exclude[^ ]+\\)" > + (1 (rgrep-command-hide)))) > "Additional things to highlight in grep output. > This gets tacked on the end of the generated expressions.") > > @@ -1166,6 +1173,32 @@ rgrep-default-command > (shell-quote-argument ")") > " -prune -o "))))) > > +(defun rgrep-command-hide () > + (let ((map (make-sparse-keymap))) > + (define-key map [down-mouse-2] 'mouse-set-point) > + (define-key map [mouse-2] 'rgrep-command-show) > + (define-key map "\C-m" 'rgrep-command-show) > + `(face nil display "[...]" mouse-face highlight > + help-echo "RET, mouse-2: toggle truncated command" > + keymap ,map))) > + > +(defun rgrep-command-show () > + (interactive) > + (when (get-text-property (point) 'display) > + (let ((beg (or (previous-single-property-change > + (min (point-max) (1+ (point))) 'display) > + (point))) > + (end (or (next-single-property-change > + (point) 'display) > + (point))) > + (inhibit-modification-hooks t) > + (inhibit-read-only t) > + (buffer-undo-list t) > + (modified (buffer-modified-p))) > + (remove-list-of-text-properties > + beg end '(display help-echo mouse-face help-echo keymap)) > + (set-buffer-modified-p modified)))) > + > ;;;###autoload > (defun zrgrep (regexp &optional files dir confirm template) > "Recursively grep for REGEXP in gzipped FILES in tree rooted at DIR. Thanks, this is a great start. I iterated on your patch, with a few changes: - Change naming to start with `grep' instead of `rgrep' (the position of the functions may still have to change within the file). - Use `with-silent-modifications'. - Provide a toggling command for hiding/showing the shortened command. What still remains to be added is the doc, a possible keybinding/menu item, and a customization variable that determines whether the hiding is done immediately for every rgrep/lgrep/rzgrep buffer. And I think there's some room for error in my change to the beg/end let-bindings in grep-toggle-shortened-command (e.g. if beg ends up being nil), so I'll fix that eventually as well. diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 14e251e..6699787 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -452,7 +452,13 @@ grep-mode-font-lock-keywords ;; "filename=linenumber=" for lines with function names in "git grep -p". ("^.+?\\([-=\0]\\)[0-9]+\\([-=]\\).*\n" (0 grep-context-face) (1 (if (eq (char-after (match-beginning 1)) ?\0) - `(face nil display ,(match-string 2)))))) + `(face nil display ,(match-string 2))))) + ;; Hide excessive part of the command from rgrep + ("^find \\(\\. -type d .*\\\\)\\)" + (1 (grep-shortened-command-properties))) + ;; Hide excessive part of the command from lgrep + ("^grep \\( *--exclude.*--exclude[^ ]+\\)" + (1 (grep-shortened-command-properties)))) "Additional things to highlight in grep output. This gets tacked on the end of the generated expressions.") @@ -1166,6 +1172,30 @@ rgrep-default-command (shell-quote-argument ")") " -prune -o "))))) +(defun grep-shortened-command-properties () + "Return a list of text properties applied to verbose command arguments." + (let ((map (make-sparse-keymap))) + (define-key map [down-mouse-2] 'mouse-set-point) + (define-key map [mouse-2] 'grep-toggle-shortened-command) + (define-key map "\C-m" 'grep-toggle-shortened-command) + `(face nil display "[...]" mouse-face highlight + help-echo "RET, mouse-2: toggle shortened command" + keymap ,map + shortened-command t))) + +(defun grep-toggle-shortened-command () + "Toggle the display of a shortened command in `grep-mode' buffers." + (interactive) + (with-silent-modifications + (let* ((beg (next-single-property-change + (point-min) 'shortened-command)) + (end (next-single-property-change + beg 'shortened-command))) + (if (get-text-property beg 'display) + (remove-list-of-text-properties + beg end '(display help-echo mouse-face help-echo keymap)) + (add-text-properties beg end (grep-shortened-command-properties)))))) + ;;;###autoload (defun zrgrep (regexp &optional files dir confirm template) "Recursively grep for REGEXP in gzipped FILES in tree rooted at DIR.