From 8ba61ffd8cebb0ff9f7a219022f3c1f3eac2f6d0 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Thu, 22 Feb 2018 23:51:41 +0200 Subject: [PATCH] * lisp/progmodes/grep.el (grep-find-hide): New defcustom (bug#30503). (grep-find-hide-properties): New variable. (grep-mode-font-lock-keywords): Put grep-find-hide-properties on part of grep command line. (grep-find-show): New function. * doc/emacs/building.texi (Grep Searching): Document grep-find-hide. --- doc/emacs/building.texi | 6 +++++ etc/NEWS | 7 ++++++ lisp/progmodes/grep.el | 49 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi index b6b664ddb39..91705711b84 100644 --- a/doc/emacs/building.texi +++ b/doc/emacs/building.texi @@ -434,6 +434,12 @@ the variable @code{grep-files-aliases}. @kbd{M-x rgrep}. The default value includes the data directories used by various version control systems. +@vindex grep-find-hide + The boolean option @code{grep-find-hide} controls shortening of the +displayed command line by hiding the part containing ignored +directories and files. The hidden part can be revealed by clicking on +the button with ellipsis. + @node Flymake @section Finding Syntax Errors On The Fly @cindex checking syntax diff --git a/etc/NEWS b/etc/NEWS index 848b66d20d7..6a89182493a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -182,6 +182,13 @@ by default. ** Gamegrid +** grep + +*** rgrep, lgrep and zrgrep now hide part of the command line +that contains a list of ignored directories and files. +Clicking on the button with ellipsis unhides the truncated part. +This truncation can be disabled by the new option 'grep-find-hide'. + ** ERT +++ diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 755c9c73d37..9b2c6f112c6 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -433,6 +433,26 @@ See `compilation-error-regexp-alist' for format details.") help-echo "Number of matches so far") "]")) +(defcustom grep-find-hide t + "If non-nil, hide part of rgrep/lgrep/zrgrep command line. +The hidden part contains a list of ignored directories and files. +Clicking on the button-like ellipsis unhides the abbreviated part +and reveals the entire command line." + :type 'boolean + :version "27.1" + :group 'grep) + +(defvar grep-find-hide-properties + (let ((ellipsis (if (char-displayable-p ?…) "[…]" "[...]")) + (map (make-sparse-keymap))) + (define-key map [down-mouse-2] 'mouse-set-point) + (define-key map [mouse-2] 'grep-find-show) + (define-key map "\C-m" 'grep-find-show) + `(face nil display ,ellipsis mouse-face highlight + help-echo "RET, mouse-2: show unabbreviated command" + keymap ,map)) + "Properties of button-like ellipsis on part of rgrep command line.") + (defvar grep-mode-font-lock-keywords '(;; Command output lines. (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$" @@ -450,9 +470,16 @@ See `compilation-error-regexp-alist' for format details.") (2 grep-error-face nil t)) ;; "filename-linenumber-" format is used for context lines in GNU grep, ;; "filename=linenumber=" for lines with function names in "git grep -p". - ("^.+?\\([-=\0]\\)[0-9]+\\([-=]\\).*\n" (0 grep-context-face) + ("^.+?\\([-=\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 rgrep command + ("^find \\(\\. -type d .*\\\\)\\)" + (1 (when grep-find-hide grep-find-hide-properties))) + ;; Hide excessive part of lgrep command + ("^grep \\( *--exclude.*--exclude[^ ]+\\)" + (1 (when grep-find-hide grep-find-hide-properties)))) "Additional things to highlight in grep output. This gets tacked on the end of the generated expressions.") @@ -1168,6 +1195,24 @@ to specify a command to run." (shell-quote-argument ")") " -prune -o "))))) +(defun grep-find-show () + "Show the hidden part of rgrep/lgrep/zrgrep command line." + (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. -- 2.39.2