]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow toggling Grep command abbreviation, and rename related symbols
authorCharles A. Roelli <charles@aurox.ch>
Sun, 11 Mar 2018 13:56:00 +0000 (14:56 +0100)
committerAndrew G Cohen <cohen@andy.bu.edu>
Tue, 11 Dec 2018 06:15:03 +0000 (14:15 +0800)
* lisp/progmodes/grep.el (grep-find-hide): Rename 'grep-find-hide'
to 'grep-find-abbreviate'.
(grep-find-hide-properties): Rename to
'grep-find-abbreviate-properties'.
(grep-mode-font-lock-keywords): Even when 'grep-find-abbreviate'
is nil, fontify the verbose command options with property
'abbreviated-command', so that the toggling command can later find
these parts without refontifying.
(grep-find-show): Rename to 'grep-find-toggle-abbreviation',
simplify the code, and permit toggling the hidden command options.
(grep-mode-map): Add a menu-bar item and new separator for
'grep-find-toggle-abbreviation', and fix the incumbent separators
in the "Grep" menu-bar, of which only one was showing before this
commit, even though two were specified.
* etc/NEWS (grep):
* doc/emacs/building.texi (Grep Searching): Document these
changes, and mention 'grep-find-toggle-abbreviation'.

doc/emacs/building.texi
etc/NEWS
lisp/progmodes/grep.el

index 0697e1b590de945f67c385c304c42e95f3f30f85..e1c3cea0355611b7d95aea4616cccfe5611395a6 100644 (file)
@@ -434,14 +434,17 @@ 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
+@vindex grep-find-abbreviate
+@findex grep-find-toggle-abbreviation
   By default, the shell commands constructed for @code{lgrep},
 @code{rgrep}, and @code{zgrep} are abbreviated for display by
 concealing the part that contains a long list of files and directories
 to ignore.  You can reveal the concealed part by clicking on the
-button with ellipsis, which represents them.  To disable this
-abbreviation of the shell commands, customize the option
-@code{grep-find-hide} to a @code{nil} value.
+button with ellipsis, which represents them.  You can also
+interactively toggle viewing the concealed part by typing @kbd{M-x
+grep-find-toggle-abbreviation}.  To disable this abbreviation of the
+shell commands, customize the option @code{grep-find-abbreviate} to a
+@code{nil} value.
 
 @node Flymake
 @section Finding Syntax Errors On The Fly
index bf2b1162b33a33108b1497461a13807a741c99fc..57a8ccdedee527e01d3c03b4d732e31246fcd5c5 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -228,8 +228,10 @@ by default.
 
 *** 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'.
+Clicking on the button with ellipsis unhides it.
+The abbreviation can be disabled by the new option
+'grep-find-abbreviate'.  The new command
+'grep-find-toggle-abbreviation' toggles it interactively.
 
 ** ERT
 
index dc74ad2de5fe4f010cf7597c764dd088c5c62439..8c0e46f35aea3b149f62c5cfd0f7b5a3991925c9 100644 (file)
@@ -286,6 +286,11 @@ See `compilation-error-screen-columns'"
     (define-key map [menu-bar grep]
       (cons "Grep" (make-sparse-keymap "Grep")))
 
+    (define-key map [menu-bar grep grep-find-toggle-abbreviation]
+      '(menu-item "Toggle command abbreviation"
+                  grep-find-toggle-abbreviation
+                  :help "Toggle showing verbose command options"))
+    (define-key map [menu-bar grep compilation-separator3] '("----"))
     (define-key map [menu-bar grep compilation-kill-compilation]
       '(menu-item "Kill Grep" kill-compilation
                  :help "Kill the currently running grep process"))
@@ -308,7 +313,7 @@ See `compilation-error-screen-columns'"
     (define-key map [menu-bar grep compilation-recompile]
       '(menu-item "Repeat grep" recompile
                  :help "Run grep again"))
-    (define-key map [menu-bar grep compilation-separator2] '("----"))
+    (define-key map [menu-bar grep compilation-separator1] '("----"))
     (define-key map [menu-bar grep compilation-first-error]
       '(menu-item "First Match" first-error
                  :help "Restart at the first match, visit corresponding location"))
@@ -433,24 +438,26 @@ See `compilation-error-regexp-alist' for format details.")
                       help-echo "Number of matches so far")
     "]"))
 
-(defcustom grep-find-hide t
+(defcustom grep-find-abbreviate 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."
+and reveals the entire command line.  The visibility of the
+abbreviated part can also be toggled with
+`grep-find-toggle-abbreviation'."
   :type 'boolean
   :version "27.1"
   :group 'grep)
 
-(defvar grep-find-hide-properties
+(defvar grep-find-abbreviate-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)
+    (define-key map [mouse-2] 'grep-find-toggle-abbreviation)
+    (define-key map "\C-m" 'grep-find-toggle-abbreviation)
     `(face nil display ,ellipsis mouse-face highlight
       help-echo "RET, mouse-2: show unabbreviated command"
-      keymap ,map))
+      keymap ,map abbreviated-command t))
   "Properties of button-like ellipsis on part of rgrep command line.")
 
 (defvar grep-mode-font-lock-keywords
@@ -476,10 +483,12 @@ and reveals the entire command line."
              `(face nil display ,(match-string 2)))))
      ;; Hide excessive part of rgrep command
      ("^find \\(\\. -type d .*\\\\)\\)"
-      (1 (when grep-find-hide grep-find-hide-properties)))
+      (1 (if grep-find-abbreviate grep-find-abbreviate-properties
+           '(face nil abbreviated-command t))))
      ;; Hide excessive part of lgrep command
      ("^grep \\( *--exclude.*--exclude[^ ]+\\)"
-      (1 (when grep-find-hide grep-find-hide-properties))))
+      (1 (if grep-find-abbreviate grep-find-abbreviate-properties
+           '(face nil abbreviated-command t)))))
    "Additional things to highlight in grep output.
 This gets tacked on the end of the generated expressions.")
 
@@ -1195,23 +1204,19 @@ 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."
+(defun grep-find-toggle-abbreviation ()
+  "Toggle showing 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))))
+  (with-silent-modifications
+    (let* ((beg (next-single-property-change (point-min) 'abbreviated-command))
+           (end (when beg
+                  (next-single-property-change beg 'abbreviated-command))))
+      (if end
+          (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-find-abbreviate-properties))
+        (user-error "No abbreviated part to hide/show")))))
 
 ;;;###autoload
 (defun zrgrep (regexp &optional files dir confirm template)