diff options
| author | Charles A. Roelli | 2018-03-11 14:56:00 +0100 |
|---|---|---|
| committer | Charles A. Roelli | 2018-03-11 14:56:00 +0100 |
| commit | 0965d94ca426765382f366bf48f88ba5f9500afd (patch) | |
| tree | 9edaf0fbae28388f0a24327377cb141031515e08 /lisp | |
| parent | c773dc118e897d6e0b95c131051e73d6fef97111 (diff) | |
| download | emacs-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'.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/grep.el | 55 |
1 files changed, 30 insertions, 25 deletions
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. |
| 438 | The hidden part contains a list of ignored directories and files. | 443 | The hidden part contains a list of ignored directories and files. |
| 439 | Clicking on the button-like ellipsis unhides the abbreviated part | 444 | Clicking on the button-like ellipsis unhides the abbreviated part |
| 440 | and reveals the entire command line." | 445 | and reveals the entire command line. The visibility of the |
| 446 | abbreviated 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. |
| 484 | This gets tacked on the end of the generated expressions.") | 493 | This 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) |