unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: charles@aurox.ch (Charles A. Roelli)
Cc: 30503@debbugs.gnu.org
Subject: bug#30503: 27.0.50; allow hiding M-x grep command line
Date: Tue, 20 Feb 2018 22:54:34 +0200	[thread overview]
Message-ID: <87sh9vs7p1.fsf@mail.linkov.net> (raw)
In-Reply-To: <m2y3jrinwv.fsf@aurox.ch> (Charles A. Roelli's message of "Sat, 17 Feb 2018 17:25:20 +0100")

[-- Attachment #1: Type: text/plain, Size: 2087 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: grep-hide.patch --]
[-- Type: text/x-diff, Size: 2169 bytes --]

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.

  parent reply	other threads:[~2018-02-20 20:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-17 16:25 bug#30503: 27.0.50; allow hiding M-x grep command line Charles A. Roelli
2018-02-17 17:06 ` Eli Zaretskii
2018-02-17 19:13   ` Charles A. Roelli
2018-02-20 20:54 ` Juri Linkov [this message]
2018-02-21  3:44   ` Eli Zaretskii
2018-02-21 20:20     ` Juri Linkov
2018-02-22  7:43       ` Eli Zaretskii
2018-02-22 21:51         ` Juri Linkov
2018-02-23  6:55           ` Eli Zaretskii
2018-02-25 19:50           ` Charles A. Roelli
2018-02-27 21:06             ` Juri Linkov
2018-03-04 16:11               ` Charles A. Roelli
2018-03-11 14:00                 ` Charles A. Roelli
2018-02-21 20:30   ` Charles A. Roelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sh9vs7p1.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=30503@debbugs.gnu.org \
    --cc=charles@aurox.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).