aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDima Kogan2019-06-30 10:37:53 -0700
committerEli Zaretskii2019-07-13 10:12:28 +0300
commit8abe1704528d852157d1e8547841cab8e46db1ac (patch)
tree50ff713725f93326200b7594b86db1ee44ce1f40
parent04cbdde94d256d9b3fbfcc67981374a55d339fcd (diff)
downloademacs-8abe1704528d852157d1e8547841cab8e46db1ac.tar.gz
emacs-8abe1704528d852157d1e8547841cab8e46db1ac.zip
Add ability to highlight-lines-matching-regexp directly from Isearch
* lisp/isearch.el: Implement the new functionality. (isearch-highlight-lines-matching-regexp): New function bound to 'M-s h l' in isearch. (isearch--highlight-regexp-or-lines): New internal function. * etc/NEWS (Search and Replace): Mention this change. * doc/emacs/search.texi (Special Isearch): Document 'M-s h l'. (Bug#18241)
-rw-r--r--doc/emacs/search.texi17
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/isearch.el32
3 files changed, 41 insertions, 14 deletions
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index c61578bab76..b47d51a2b66 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -453,13 +453,16 @@ key sequence if you want to use it (@pxref{Rebinding}).
453 453
454@kindex M-s h r @r{(Incremental Search)} 454@kindex M-s h r @r{(Incremental Search)}
455@findex isearch-highlight-regexp 455@findex isearch-highlight-regexp
456 You can exit the search while leaving the matches for the last 456@kindex M-s h l @r{(Incremental Search)}
457search string highlighted on display. To this end, type @kbd{M-s h r} 457@findex isearch-highlight-lines-matching-regexp
458(@code{isearch-highlight-regexp}), which will run 458 You can exit the search while leaving the matches highlighted by
459@code{highlight-regexp} (@pxref{Highlight Interactively}) passing 459typing @kbd{M-s h r} (@code{isearch-highlight-regexp}). This runs
460it the regexp derived from the last search string and prompting you 460@code{highlight-regexp} (@pxref{Highlight Interactively}), passing it
461for the face to use for highlighting. To remove the highlighting, 461the regexp derived from the search string and prompting you for the face
462type @kbd{M-s h u} (@code{unhighlight-regexp}). 462to use for highlighting. To highlight @emph{whole lines} containing
463matches (rather than @emph{just} the matches), type @kbd{M-s h l}
464(@code{isearch-highlight-lines-matching-regexp}). In either case, to
465remove the highlighting, type @kbd{M-s h u} (@code{unhighlight-regexp}).
463 466
464@cindex incremental search, help on special keys 467@cindex incremental search, help on special keys
465@kindex C-h C-h @r{(Incremental Search)} 468@kindex C-h C-h @r{(Incremental Search)}
diff --git a/etc/NEWS b/etc/NEWS
index 10470dfb5eb..e04760a2c6a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1123,6 +1123,12 @@ highlight in one iteration while processing the full buffer.
1123'C-M-d'. 1123'C-M-d'.
1124 1124
1125+++ 1125+++
1126'M-s h l' invokes highlight-lines-matching-regexp using the search
1127string to highlight lines matching the search string. This is similar
1128to the existing binding 'M-s h r' (highlight-regexp) that highlights
1129JUST the search string.
1130
1131+++
1126*** New variable 'isearch-yank-on-move' provides options 't' and 'shift' 1132*** New variable 'isearch-yank-on-move' provides options 't' and 'shift'
1127to extend the search string by yanking text that ends at the new 1133to extend the search string by yanking text that ends at the new
1128position after moving point in the current buffer. 'shift' extends 1134position after moving point in the current buffer. 'shift' extends
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 94c30eb57be..e0f3f05153f 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -753,6 +753,7 @@ This is like `describe-bindings', but displays only Isearch keys."
753 (define-key map [?\C-\M-%] 'isearch-query-replace-regexp) 753 (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
754 (define-key map "\M-so" 'isearch-occur) 754 (define-key map "\M-so" 'isearch-occur)
755 (define-key map "\M-shr" 'isearch-highlight-regexp) 755 (define-key map "\M-shr" 'isearch-highlight-regexp)
756 (define-key map "\M-shl" 'isearch-highlight-lines-matching-regexp)
756 757
757 ;; The key translations defined in the C-x 8 prefix should add 758 ;; The key translations defined in the C-x 8 prefix should add
758 ;; characters to the search string. See iso-transl.el. 759 ;; characters to the search string. See iso-transl.el.
@@ -1039,6 +1040,9 @@ Type \\[isearch-occur] to run `occur' that shows\
1039 the last search string. 1040 the last search string.
1040Type \\[isearch-highlight-regexp] to run `highlight-regexp'\ 1041Type \\[isearch-highlight-regexp] to run `highlight-regexp'\
1041 that highlights the last search string. 1042 that highlights the last search string.
1043Type \\[isearch-highlight-lines-matching-regexp] to run
1044 `highlight-lines-matching-regexp'\ that highlights lines
1045 matching the last search string.
1042 1046
1043Type \\[isearch-describe-bindings] to display all Isearch key bindings. 1047Type \\[isearch-describe-bindings] to display all Isearch key bindings.
1044Type \\[isearch-describe-key] to display documentation of Isearch key. 1048Type \\[isearch-describe-key] to display documentation of Isearch key.
@@ -2343,12 +2347,12 @@ characters in that string."
2343 2347
2344(declare-function hi-lock-read-face-name "hi-lock" ()) 2348(declare-function hi-lock-read-face-name "hi-lock" ())
2345 2349
2346(defun isearch-highlight-regexp () 2350(defun isearch--highlight-regexp-or-lines (hi-lock-func)
2347 "Run `highlight-regexp' with regexp from the current search string. 2351 "Run HI-LOCK-FUNC to exit isearch, leaving the matches highlighted.
2348It exits Isearch mode and calls `hi-lock-face-buffer' with its regexp 2352This is the internal function used by `isearch-highlight-regexp'
2349argument from the last search regexp or a quoted search string, 2353and `isearch-highlight-lines-matching-regexp' to invoke
2350and reads its face argument using `hi-lock-read-face-name'." 2354HI-LOCK-FUNC (either `highlight-regexp' or
2351 (interactive) 2355`highlight-lines-matching-regexp' respectively)."
2352 (let ( 2356 (let (
2353 ;; Set `isearch-recursive-edit' to nil to prevent calling 2357 ;; Set `isearch-recursive-edit' to nil to prevent calling
2354 ;; `exit-recursive-edit' in `isearch-done' that terminates 2358 ;; `exit-recursive-edit' in `isearch-done' that terminates
@@ -2377,9 +2381,23 @@ and reads its face argument using `hi-lock-read-face-name'."
2377 (regexp-quote s)))) 2381 (regexp-quote s))))
2378 isearch-string "")) 2382 isearch-string ""))
2379 (t (regexp-quote isearch-string))))) 2383 (t (regexp-quote isearch-string)))))
2380 (hi-lock-face-buffer regexp (hi-lock-read-face-name))) 2384 (funcall hi-lock-func regexp (hi-lock-read-face-name)))
2381 (and isearch-recursive-edit (exit-recursive-edit))) 2385 (and isearch-recursive-edit (exit-recursive-edit)))
2382 2386
2387(defun isearch-highlight-regexp ()
2388 "Exit Isearch mode, and call `highlight-regexp' with its regexp
2389argument from the last search, and the face from
2390`hi-lock-read-face-name'."
2391 (interactive)
2392 (isearch--highlight-regexp-or-lines 'highlight-regexp))
2393
2394(defun isearch-highlight-lines-matching-regexp ()
2395 "Exit Isearch mode, and call `highlight-lines-matching-regexp'
2396with its regexp argument from the last search, and the face from
2397`hi-lock-read-face-name'."
2398 (interactive)
2399 (isearch--highlight-regexp-or-lines 'highlight-lines-matching-regexp))
2400
2383 2401
2384(defun isearch-delete-char () 2402(defun isearch-delete-char ()
2385 "Undo last input item during a search. 2403 "Undo last input item during a search.