aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCharles A. Roelli2018-03-11 14:56:00 +0100
committerCharles A. Roelli2018-03-11 14:56:00 +0100
commit0965d94ca426765382f366bf48f88ba5f9500afd (patch)
tree9edaf0fbae28388f0a24327377cb141031515e08
parentc773dc118e897d6e0b95c131051e73d6fef97111 (diff)
downloademacs-0965d94ca426765382f366bf48f88ba5f9500afd.tar.gz
emacs-0965d94ca426765382f366bf48f88ba5f9500afd.zip
Allow toggling Grep command abbreviation, and rename related symbols
* 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'.
-rw-r--r--doc/emacs/building.texi11
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/progmodes/grep.el55
3 files changed, 41 insertions, 31 deletions
diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi
index 0697e1b590d..e1c3cea0355 100644
--- a/doc/emacs/building.texi
+++ b/doc/emacs/building.texi
@@ -434,14 +434,17 @@ the variable @code{grep-files-aliases}.
434@kbd{M-x rgrep}. The default value includes the data directories used 434@kbd{M-x rgrep}. The default value includes the data directories used
435by various version control systems. 435by various version control systems.
436 436
437@vindex grep-find-hide 437@vindex grep-find-abbreviate
438@findex grep-find-toggle-abbreviation
438 By default, the shell commands constructed for @code{lgrep}, 439 By default, the shell commands constructed for @code{lgrep},
439@code{rgrep}, and @code{zgrep} are abbreviated for display by 440@code{rgrep}, and @code{zgrep} are abbreviated for display by
440concealing the part that contains a long list of files and directories 441concealing the part that contains a long list of files and directories
441to ignore. You can reveal the concealed part by clicking on the 442to ignore. You can reveal the concealed part by clicking on the
442button with ellipsis, which represents them. To disable this 443button with ellipsis, which represents them. You can also
443abbreviation of the shell commands, customize the option 444interactively toggle viewing the concealed part by typing @kbd{M-x
444@code{grep-find-hide} to a @code{nil} value. 445grep-find-toggle-abbreviation}. To disable this abbreviation of the
446shell commands, customize the option @code{grep-find-abbreviate} to a
447@code{nil} value.
445 448
446@node Flymake 449@node Flymake
447@section Finding Syntax Errors On The Fly 450@section Finding Syntax Errors On The Fly
diff --git a/etc/NEWS b/etc/NEWS
index f35a5134a94..9eb28e18f71 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -228,8 +228,10 @@ by default.
228 228
229*** rgrep, lgrep and zrgrep now hide part of the command line 229*** rgrep, lgrep and zrgrep now hide part of the command line
230that contains a list of ignored directories and files. 230that contains a list of ignored directories and files.
231Clicking on the button with ellipsis unhides the truncated part. 231Clicking on the button with ellipsis unhides it.
232This truncation can be disabled by the new option 'grep-find-hide'. 232The abbreviation can be disabled by the new option
233'grep-find-abbreviate'. The new command
234'grep-find-toggle-abbreviation' toggles it interactively.
233 235
234** ERT 236** ERT
235 237
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index dc74ad2de5f..8c0e46f35ae 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -286,6 +286,11 @@ See `compilation-error-screen-columns'"
286 (define-key map [menu-bar grep] 286 (define-key map [menu-bar grep]
287 (cons "Grep" (make-sparse-keymap "Grep"))) 287 (cons "Grep" (make-sparse-keymap "Grep")))
288 288
289 (define-key map [menu-bar grep grep-find-toggle-abbreviation]
290 '(menu-item "Toggle command abbreviation"
291 grep-find-toggle-abbreviation
292 :help "Toggle showing verbose command options"))
293 (define-key map [menu-bar grep compilation-separator3] '("----"))
289 (define-key map [menu-bar grep compilation-kill-compilation] 294 (define-key map [menu-bar grep compilation-kill-compilation]
290 '(menu-item "Kill Grep" kill-compilation 295 '(menu-item "Kill Grep" kill-compilation
291 :help "Kill the currently running grep process")) 296 :help "Kill the currently running grep process"))
@@ -308,7 +313,7 @@ See `compilation-error-screen-columns'"
308 (define-key map [menu-bar grep compilation-recompile] 313 (define-key map [menu-bar grep compilation-recompile]
309 '(menu-item "Repeat grep" recompile 314 '(menu-item "Repeat grep" recompile
310 :help "Run grep again")) 315 :help "Run grep again"))
311 (define-key map [menu-bar grep compilation-separator2] '("----")) 316 (define-key map [menu-bar grep compilation-separator1] '("----"))
312 (define-key map [menu-bar grep compilation-first-error] 317 (define-key map [menu-bar grep compilation-first-error]
313 '(menu-item "First Match" first-error 318 '(menu-item "First Match" first-error
314 :help "Restart at the first match, visit corresponding location")) 319 :help "Restart at the first match, visit corresponding location"))
@@ -433,24 +438,26 @@ See `compilation-error-regexp-alist' for format details.")
433 help-echo "Number of matches so far") 438 help-echo "Number of matches so far")
434 "]")) 439 "]"))
435 440
436(defcustom grep-find-hide t 441(defcustom grep-find-abbreviate t
437 "If non-nil, hide part of rgrep/lgrep/zrgrep command line. 442 "If non-nil, hide part of rgrep/lgrep/zrgrep command line.
438The hidden part contains a list of ignored directories and files. 443The hidden part contains a list of ignored directories and files.
439Clicking on the button-like ellipsis unhides the abbreviated part 444Clicking on the button-like ellipsis unhides the abbreviated part
440and reveals the entire command line." 445and reveals the entire command line. The visibility of the
446abbreviated part can also be toggled with
447`grep-find-toggle-abbreviation'."
441 :type 'boolean 448 :type 'boolean
442 :version "27.1" 449 :version "27.1"
443 :group 'grep) 450 :group 'grep)
444 451
445(defvar grep-find-hide-properties 452(defvar grep-find-abbreviate-properties
446 (let ((ellipsis (if (char-displayable-p ?…) "[…]" "[...]")) 453 (let ((ellipsis (if (char-displayable-p ?…) "[…]" "[...]"))
447 (map (make-sparse-keymap))) 454 (map (make-sparse-keymap)))
448 (define-key map [down-mouse-2] 'mouse-set-point) 455 (define-key map [down-mouse-2] 'mouse-set-point)
449 (define-key map [mouse-2] 'grep-find-show) 456 (define-key map [mouse-2] 'grep-find-toggle-abbreviation)
450 (define-key map "\C-m" 'grep-find-show) 457 (define-key map "\C-m" 'grep-find-toggle-abbreviation)
451 `(face nil display ,ellipsis mouse-face highlight 458 `(face nil display ,ellipsis mouse-face highlight
452 help-echo "RET, mouse-2: show unabbreviated command" 459 help-echo "RET, mouse-2: show unabbreviated command"
453 keymap ,map)) 460 keymap ,map abbreviated-command t))
454 "Properties of button-like ellipsis on part of rgrep command line.") 461 "Properties of button-like ellipsis on part of rgrep command line.")
455 462
456(defvar grep-mode-font-lock-keywords 463(defvar grep-mode-font-lock-keywords
@@ -476,10 +483,12 @@ and reveals the entire command line."
476 `(face nil display ,(match-string 2))))) 483 `(face nil display ,(match-string 2)))))
477 ;; Hide excessive part of rgrep command 484 ;; Hide excessive part of rgrep command
478 ("^find \\(\\. -type d .*\\\\)\\)" 485 ("^find \\(\\. -type d .*\\\\)\\)"
479 (1 (when grep-find-hide grep-find-hide-properties))) 486 (1 (if grep-find-abbreviate grep-find-abbreviate-properties
487 '(face nil abbreviated-command t))))
480 ;; Hide excessive part of lgrep command 488 ;; Hide excessive part of lgrep command
481 ("^grep \\( *--exclude.*--exclude[^ ]+\\)" 489 ("^grep \\( *--exclude.*--exclude[^ ]+\\)"
482 (1 (when grep-find-hide grep-find-hide-properties)))) 490 (1 (if grep-find-abbreviate grep-find-abbreviate-properties
491 '(face nil abbreviated-command t)))))
483 "Additional things to highlight in grep output. 492 "Additional things to highlight in grep output.
484This gets tacked on the end of the generated expressions.") 493This gets tacked on the end of the generated expressions.")
485 494
@@ -1195,23 +1204,19 @@ to specify a command to run."
1195 (shell-quote-argument ")") 1204 (shell-quote-argument ")")
1196 " -prune -o "))))) 1205 " -prune -o ")))))
1197 1206
1198(defun grep-find-show () 1207(defun grep-find-toggle-abbreviation ()
1199 "Show the hidden part of rgrep/lgrep/zrgrep command line." 1208 "Toggle showing the hidden part of rgrep/lgrep/zrgrep command line."
1200 (interactive) 1209 (interactive)
1201 (when (get-text-property (point) 'display) 1210 (with-silent-modifications
1202 (let ((beg (or (previous-single-property-change 1211 (let* ((beg (next-single-property-change (point-min) 'abbreviated-command))
1203 (min (point-max) (1+ (point))) 'display) 1212 (end (when beg
1204 (point))) 1213 (next-single-property-change beg 'abbreviated-command))))
1205 (end (or (next-single-property-change 1214 (if end
1206 (point) 'display) 1215 (if (get-text-property beg 'display)
1207 (point))) 1216 (remove-list-of-text-properties
1208 (inhibit-modification-hooks t) 1217 beg end '(display help-echo mouse-face help-echo keymap))
1209 (inhibit-read-only t) 1218 (add-text-properties beg end grep-find-abbreviate-properties))
1210 (buffer-undo-list t) 1219 (user-error "No abbreviated part to hide/show")))))
1211 (modified (buffer-modified-p)))
1212 (remove-list-of-text-properties
1213 beg end '(display help-echo mouse-face help-echo keymap))
1214 (set-buffer-modified-p modified))))
1215 1220
1216;;;###autoload 1221;;;###autoload
1217(defun zrgrep (regexp &optional files dir confirm template) 1222(defun zrgrep (regexp &optional files dir confirm template)