bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp fr


From: Dima Kogan
Subject: bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
Date: Sun, 30 Jun 2019 11:08:16 -0700
User-agent: mu4e 1.0; emacs 27.0.50

Juri Linkov <juri@linkov.net> writes:

> It's already possible to do this by typing in isearch:
>
>   M-s h l
>   M-n M-n M-n RET
>
> because the third default value of hi-lock commands is
> the last isearch string.
>
> Its only difference is that it quits isearch, but I wonder
> is it really useful to keep isearch active after running
> this hi-lock command?

I guess this is true, but that requires 5 extra keystrokes and extra
knowledge: I didn't know about this default, and it didn't even work
until I updated my 2-month-old emacs

Given that 'M-s h r' is handled specially in isearch already, it only
makes sense that 'M-s h l' would be too. And there's no down side to
supporting this at all.

I'm attaching a new patch. It does away with the weird macro thing I was
doing (don't know why I was doing that), and adds notes in the NEWS and
the documentation.

Thanks.


>From 7267753901e5a5b61c78c982661d1bb3f92a596e Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
Date: Sun, 30 Jun 2019 10:37:53 -0700
Subject: [PATCH] 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-internal): New internal function

* etc/NEWS (Search and Replace): Mention this change.

* doc/emacs/search.texi: Added this binding to the documentation
---
 doc/emacs/search.texi | 10 ++++++++++
 etc/NEWS              |  3 +++
 lisp/isearch.el       | 26 +++++++++++++++++++++++---
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index c61578bab76..e7cbd3bef82 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -461,6 +461,16 @@ Special Isearch
 for the face to use for highlighting.  To remove the highlighting,
 type @kbd{M-s h u} (@code{unhighlight-regexp}).
 
+@kindex M-s h l @r{(Incremental Search)}
+@findex isearch-highlight-lines-matching-regexp
+  Similarly, you can exit the search while highlighting whole lines
+containing matches of the last search string.  To this end, type
+@kbd{M-s h l} (@code{isearch-highlight-lines-matching-regexp}), which
+will run @code{highlight-lines-matching-regexp} (@pxref{Highlight
+Interactively}) passing it the regexp derived from the last search
+string and prompting you for the face to use for highlighting.  To
+remove the highlighting, type @kbd{M-s h u} (@code{unhighlight-regexp}).
+
 @cindex incremental search, help on special keys
 @kindex C-h C-h @r{(Incremental Search)}
 @findex isearch-help-map
diff --git a/etc/NEWS b/etc/NEWS
index abbece374a4..72b30373587 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1111,6 +1111,9 @@ highlight in one iteration while processing the full 
buffer.
 'isearch-yank-symbol-or-char'.  'isearch-del-char' is now bound to
 'C-M-d'.
 
+'M-s h l' invokes highlight-lines-matching-regexp directly using the
+search string, similar to what 'M-s h r' was doing already.
+
 +++
 *** New variable 'isearch-yank-on-move' provides options 't' and 'shift'
 to extend the search string by yanking text that ends at the new
diff --git a/lisp/isearch.el b/lisp/isearch.el
index f150a3bba4b..e54fdb74783 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -753,6 +753,7 @@ isearch-mode-map
     (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
     (define-key map "\M-so" 'isearch-occur)
     (define-key map "\M-shr" 'isearch-highlight-regexp)
+    (define-key map "\M-shl" 'isearch-highlight-lines-matching-regexp)
 
     ;; The key translations defined in the C-x 8 prefix should add
     ;; characters to the search string.  See iso-transl.el.
@@ -1039,6 +1040,9 @@ isearch-forward
  the last search string.
 Type \\[isearch-highlight-regexp] to run `highlight-regexp'\
  that highlights the last search string.
+Type \\[isearch-highlight-lines-matching-regexp] to run
+ `highlight-lines-matching-regexp'\ that highlights lines
+ matching the last search string.
 
 Type \\[isearch-describe-bindings] to display all Isearch key bindings.
 Type \\[isearch-describe-key] to display documentation of Isearch key.
@@ -2339,12 +2343,11 @@ isearch-occur
 
 (declare-function hi-lock-read-face-name "hi-lock" ())
 
-(defun isearch-highlight-regexp ()
+(defun isearch--highlight-regexp-or-lines-internal (hi-lock-func)
   "Run `highlight-regexp' with regexp from the current search string.
 It exits Isearch mode and calls `hi-lock-face-buffer' with its regexp
 argument from the last search regexp or a quoted search string,
 and reads its face argument using `hi-lock-read-face-name'."
-  (interactive)
   (let (
        ;; Set `isearch-recursive-edit' to nil to prevent calling
        ;; `exit-recursive-edit' in `isearch-done' that terminates
@@ -2373,9 +2376,26 @@ isearch-highlight-regexp
                              (regexp-quote s))))
                        isearch-string ""))
                      (t (regexp-quote isearch-string)))))
-    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
+    (funcall hi-lock-func regexp (hi-lock-read-face-name)))
   (and isearch-recursive-edit (exit-recursive-edit)))
 
+(defun isearch-highlight-regexp ()
+  "Run `highlight-regexp' with regexp from the current search string.
+It exits Isearch mode and calls `hi-lock-face-buffer' with its regexp
+argument from the last search regexp or a quoted search string,
+and reads its face argument using `hi-lock-read-face-name'."
+  (interactive)
+  (isearch--highlight-regexp-or-lines-internal 'hi-lock-face-buffer))
+
+(defun isearch-highlight-lines-matching-regexp ()
+  "Run `highlight-lines-matching-regexp' with regexp from the
+current search string.  It exits Isearch mode and calls
+`hi-lock-face-buffer' with its regexp argument from the last
+search regexp or a quoted search string, and reads its face
+argument using `hi-lock-read-face-name'."
+  (interactive)
+  (isearch--highlight-regexp-or-lines-internal 'hi-lock-line-face-buffer))
+
 
 (defun isearch-delete-char ()
   "Undo last input item during a search.
-- 
2.20.0.rc2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]