all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
@ 2014-08-10 22:04 Dima Kogan
  2019-06-25 22:32 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Dima Kogan @ 2014-08-10 22:04 UTC (permalink / raw)
  To: 18241

[-- Attachment #1: Type: text/plain, Size: 326 bytes --]

Hi.

Before this patch it was possible to 'M-s h r' during an isearch to
highlight the regexp being sought. This patch adds similar functionality
for matching lines with 'M-s h l'. This patch moves the previous 'M-s h
r' isearch functionality into a macro, and then calls this macro
separately for the regex and line cases.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-I-can-now-highlight-lines-matching-regexp-from-isear.patch --]
[-- Type: text/x-diff, Size: 5601 bytes --]

From ca3b5261d034b21467f781d7aa2620d0050fea37 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
Date: Sun, 10 Aug 2014 14:57:56 -0700
Subject: [PATCH] I can now highlight-lines-matching-regexp from isearch

Before this patch it was possible to 'M-s h r' during an isearch to highlight
the regexp being sought. This patch adds similar functionality for matching
lines
---
 lisp/isearch.el | 79 ++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 50 insertions(+), 29 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 20dabdc..710890c 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -524,6 +524,7 @@ This is like `describe-bindings', but displays only Isearch keys."
     (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.
@@ -732,6 +733,8 @@ Type \\[isearch-occur] to run `occur' that shows\
  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.
@@ -1804,42 +1807,60 @@ characters in that string."
 
 (declare-function hi-lock-read-face-name "hi-lock" ())
 
+
+(defmacro isearch--hi-lock (hi-lock-form)
+  "Backend for isearch-highlight-*. Does all the setup work, and
+evaluates the given `hi-lock-form' to actually invoke the
+highlighting function"
+  `(progn
+     (let (
+           ;; Set `isearch-recursive-edit' to nil to prevent calling
+           ;; `exit-recursive-edit' in `isearch-done' that terminates
+           ;; the execution of this command when it is non-nil.
+           ;; We call `exit-recursive-edit' explicitly at the end below.
+           (isearch-recursive-edit nil))
+       (isearch-done nil t)
+       (isearch-clean-overlays))
+     (let ((regexp (cond ((functionp isearch-word)
+                          (funcall isearch-word isearch-string))
+                         (isearch-word (word-search-regexp isearch-string))
+                         (isearch-regexp isearch-string)
+                         ((if (and (eq isearch-case-fold-search t)
+                                   search-upper-case)
+                              (isearch-no-upper-case-p
+                               isearch-string isearch-regexp)
+                            isearch-case-fold-search)
+                          ;; Turn isearch-string into a case-insensitive
+                          ;; regexp.
+                          (mapconcat
+                           (lambda (c)
+                             (let ((s (string c)))
+                               (if (string-match "[[:alpha:]]" s)
+                                   (format "[%s%s]" (upcase s) (downcase s))
+                                 (regexp-quote s))))
+                           isearch-string ""))
+                         (t (regexp-quote isearch-string)))))
+       (eval ,hi-lock-form))
+     (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)
-  (let (
-	;; Set `isearch-recursive-edit' to nil to prevent calling
-	;; `exit-recursive-edit' in `isearch-done' that terminates
-	;; the execution of this command when it is non-nil.
-	;; We call `exit-recursive-edit' explicitly at the end below.
-	(isearch-recursive-edit nil))
-    (isearch-done nil t)
-    (isearch-clean-overlays))
   (require 'hi-lock nil t)
-  (let ((regexp (cond ((functionp isearch-word)
-		       (funcall isearch-word isearch-string))
-		      (isearch-word (word-search-regexp isearch-string))
-		      (isearch-regexp isearch-string)
-		      ((if (and (eq isearch-case-fold-search t)
-				search-upper-case)
-			   (isearch-no-upper-case-p
-			    isearch-string isearch-regexp)
-			 isearch-case-fold-search)
-		       ;; Turn isearch-string into a case-insensitive
-		       ;; regexp.
-		       (mapconcat
-			(lambda (c)
-			  (let ((s (string c)))
-			    (if (string-match "[[:alpha:]]" s)
-				(format "[%s%s]" (upcase s) (downcase s))
-			      (regexp-quote s))))
-			isearch-string ""))
-		      (t (regexp-quote isearch-string)))))
-    (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
-  (and isearch-recursive-edit (exit-recursive-edit)))
+  (isearch--hi-lock (hi-lock-face-buffer regexp (hi-lock-read-face-name))))
+
+(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)
+  (require 'hi-lock nil t)
+  (isearch--hi-lock (hi-lock-line-face-buffer regexp (hi-lock-read-face-name))))
 
 \f
 (defun isearch-delete-char ()
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2014-08-10 22:04 bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch Dima Kogan
@ 2019-06-25 22:32 ` Lars Ingebrigtsen
  2019-06-25 22:58   ` Dima Kogan
  0 siblings, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-25 22:32 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 18241

Dima Kogan <dima@secretsauce.net> writes:

> Before this patch it was possible to 'M-s h r' during an isearch to
> highlight the regexp being sought. This patch adds similar functionality
> for matching lines with 'M-s h l'. This patch moves the previous 'M-s h
> r' isearch functionality into a macro, and then calls this macro
> separately for the regex and line cases.

Hm...  Is that a feature that would be used a lot?  It's a somewhat
awkward interface and keystroke, I think.

But here's some comments on the code:

> +(defmacro isearch--hi-lock (hi-lock-form)
> +  "Backend for isearch-highlight-*. Does all the setup work, and
> +evaluates the given `hi-lock-form' to actually invoke the
> +highlighting function"

[...]

> +       (eval ,hi-lock-form))

I think this should be a function that should just take a function to
call that takes the parameters required.

And if this is something we want, it needs a NEWS entry and
documentation updates.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-06-25 22:32 ` Lars Ingebrigtsen
@ 2019-06-25 22:58   ` Dima Kogan
  2019-06-26 13:49     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Dima Kogan @ 2019-06-25 22:58 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 18241

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Dima Kogan <dima@secretsauce.net> writes:
>
>> Before this patch it was possible to 'M-s h r' during an isearch to
>> highlight the regexp being sought. This patch adds similar functionality
>> for matching lines with 'M-s h l'. This patch moves the previous 'M-s h
>> r' isearch functionality into a macro, and then calls this macro
>> separately for the regex and line cases.
>
> Hm...  Is that a feature that would be used a lot?  It's a somewhat
> awkward interface and keystroke, I think.

I'd use it. If this is already available for "M-s h r", there's a
reasonable expectation that "M-s h l" would work too. I don't disagree
that the keystroke is awkward, but that's what we've had for a long
time, and I'd rather not change it.


> I think this should be a function that should just take a function to
> call that takes the parameters required.

OK


> And if this is something we want, it needs a NEWS entry and
> documentation updates.

I can write them if this is something we want. Is this something we
want?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-06-25 22:58   ` Dima Kogan
@ 2019-06-26 13:49     ` Lars Ingebrigtsen
  2019-06-28 19:12       ` Juri Linkov
  0 siblings, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-26 13:49 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 18241

Dima Kogan <dima@secretsauce.net> writes:

> I'd use it. If this is already available for "M-s h r", there's a
> reasonable expectation that "M-s h l" would work too. I don't disagree
> that the keystroke is awkward, but that's what we've had for a long
> time, and I'd rather not change it.

That does make sense.

>> And if this is something we want, it needs a NEWS entry and
>> documentation updates.
>
> I can write them if this is something we want. Is this something we
> want?

Does anybody else have an opinion here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-06-26 13:49     ` Lars Ingebrigtsen
@ 2019-06-28 19:12       ` Juri Linkov
  2019-06-30 18:08         ` Dima Kogan
  0 siblings, 1 reply; 11+ messages in thread
From: Juri Linkov @ 2019-06-28 19:12 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 18241, Dima Kogan

>> I'd use it. If this is already available for "M-s h r", there's a
>> reasonable expectation that "M-s h l" would work too. I don't disagree
>> that the keystroke is awkward, but that's what we've had for a long
>> time, and I'd rather not change it.
>
> Does anybody else have an opinion here?

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?





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-06-28 19:12       ` Juri Linkov
@ 2019-06-30 18:08         ` Dima Kogan
  2019-06-30 21:12           ` Juri Linkov
  0 siblings, 1 reply; 11+ messages in thread
From: Dima Kogan @ 2019-06-30 18:08 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 18241, Lars Ingebrigtsen

[-- Attachment #1: Type: text/plain, Size: 878 bytes --]

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.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-ability-to-highlight-lines-matching-regexp-direc.patch --]
[-- Type: text/x-diff, Size: 5154 bytes --]

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))
+
 \f
 (defun isearch-delete-char ()
   "Undo last input item during a search.
-- 
2.20.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-06-30 18:08         ` Dima Kogan
@ 2019-06-30 21:12           ` Juri Linkov
  2019-07-01  3:09             ` Dima Kogan
  0 siblings, 1 reply; 11+ messages in thread
From: Juri Linkov @ 2019-06-30 21:12 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 18241, Lars Ingebrigtsen

> 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.

Yes, it makes sense to do the same that 'M-s h r' already does.

> 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, indeed better to avoid macros: we have 2 macros in isearch,
and they are more of a hindrance than a help especially during development.

> +@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}).

Maybe it's possible to make the text shorter by just adding a new sentence
about 'M-s h l' to the middle of the paragraph that describes 'M-s h r'?

> -(defun isearch-highlight-regexp ()
> +(defun isearch--highlight-regexp-or-lines-internal (hi-lock-func)

The suffix '-internal' is not necessary here because the double dash
in 'isearch--' implies that the function is internal.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-06-30 21:12           ` Juri Linkov
@ 2019-07-01  3:09             ` Dima Kogan
  2019-07-01 14:08               ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Dima Kogan @ 2019-07-01  3:09 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 18241, Lars Ingebrigtsen

[-- Attachment #1: Type: text/plain, Size: 461 bytes --]

Juri Linkov <juri@linkov.net> writes:

> Maybe it's possible to make the text shorter by just adding a new sentence
> about 'M-s h l' to the middle of the paragraph that describes 'M-s h r'?
>
>> -(defun isearch-highlight-regexp ()
>> +(defun isearch--highlight-regexp-or-lines-internal (hi-lock-func)
>
> The suffix '-internal' is not necessary here because the double dash
> in 'isearch--' implies that the function is internal.

Alright. Here's a new patch


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-ability-to-highlight-lines-matching-regexp-direc.patch --]
[-- Type: text/x-diff, Size: 5571 bytes --]

From 7a7f3c50fee9953ff57ed8010d626f7637008d45 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): 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 | 18 +++++++++++-------
 etc/NEWS              |  3 +++
 lisp/isearch.el       | 26 +++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index c61578bab76..571705b916f 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -453,13 +453,17 @@ Special Isearch
 
 @kindex M-s h r @r{(Incremental Search)}
 @findex isearch-highlight-regexp
-  You can exit the search while leaving the matches for the last
-search string highlighted on display.  To this end, type @kbd{M-s h r}
-(@code{isearch-highlight-regexp}), which will run
-@code{highlight-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}).
+@kindex M-s h l @r{(Incremental Search)}
+@findex isearch-highlight-lines-matching-regexp
+  You can exit the search while leaving matches for the last search
+string highlighted by typing @kbd{M-s h r}
+(@code{isearch-highlight-regexp}).  This runs @code{highlight-regexp}
+(@pxref{Highlight Interactively}), passing it the regexp derived from
+the last search string and prompting you for the face to use for
+highlighting.  Similarly, you can highlight whole lines containing
+matches by typing @kbd{M-s h l}
+(@code{isearch-highlight-lines-matching-regexp}).  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)}
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..888e83d15a1 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 (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 '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 'hi-lock-line-face-buffer))
+
 \f
 (defun isearch-delete-char ()
   "Undo last input item during a search.
-- 
2.20.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-07-01  3:09             ` Dima Kogan
@ 2019-07-01 14:08               ` Eli Zaretskii
  2019-07-04  1:31                 ` Dima Kogan
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2019-07-01 14:08 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 18241, larsi, juri

> From: Dima Kogan <dima@secretsauce.net>
> Date: Sun, 30 Jun 2019 20:09:59 -0700
> Cc: 18241@debbugs.gnu.org, Lars Ingebrigtsen <larsi@gnus.org>

Thanks, some comments regarding the documentation parts:

> +@kindex M-s h l @r{(Incremental Search)}
> +@findex isearch-highlight-lines-matching-regexp
> +  You can exit the search while leaving matches for the last search
> +string highlighted by typing @kbd{M-s h r}
> +(@code{isearch-highlight-regexp}).  This runs @code{highlight-regexp}
> +(@pxref{Highlight Interactively}), passing it the regexp derived from
> +the last search string and prompting you for the face to use for
> +highlighting.  Similarly, you can highlight whole lines containing
> +matches by typing @kbd{M-s h l}
> +(@code{isearch-highlight-lines-matching-regexp}).

This description left me wondering what is the difference between
these two commands.  IOW, how does "last search string" and "whole
lines containing matches" differ from one another?  The problem is
probably with using "search string" instead of "match" in the
description of the first command, but that's a guess.

> +'M-s h l' invokes highlight-lines-matching-regexp directly using the
> +search string, similar to what 'M-s h r' was doing already.

This needs to be more clear.  "Similar" in what sense? and if it's
similar enough, why did we introduce a new command/key binding?  Also,
since the new command is already described in the manual, this entry
should be marked with "+++", see the beginning of NEWS for
explanations why.

> -(defun isearch-highlight-regexp ()
> +(defun isearch--highlight-regexp-or-lines (hi-lock-func)
>    "Run `highlight-regexp' with regexp from the current search string.

We prefer the first line of the doc string to mention the arguments.

> +(defun isearch-highlight-regexp ()
> +  "Run `highlight-regexp' with regexp from the current search string.

What is "current search string"?  This should be explained in the rest
of the doc string, but isn't.

> +It exits Isearch mode and calls `hi-lock-face-buffer' with its regexp
> +argument from the last search regexp or a quoted search string,

I'm guessing "the last search regexp or a quoted search string" refers
to the same string as "the current search string" in the first line.
If so, please note that it is generally a bad idea to describe the
same thing by more than one term, because it leaves the reader
wondering whether you indeed mean the same thing.

> +(defun isearch-highlight-lines-matching-regexp ()
> +  "Run `highlight-lines-matching-regexp' with regexp from the
> +current search string.  It exits Isearch mode and calls

The first line of the doc string should be a complete sentence.

Thanks.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-07-01 14:08               ` Eli Zaretskii
@ 2019-07-04  1:31                 ` Dima Kogan
  2019-07-13  7:22                   ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Dima Kogan @ 2019-07-04  1:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 18241, larsi, juri

[-- Attachment #1: Type: text/plain, Size: 18 bytes --]

Try the attached


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-ability-to-highlight-lines-matching-regexp-direc.patch --]
[-- Type: text/x-diff, Size: 5743 bytes --]

From 9d0fd748c0f5648a6687fc590822fae3a0eb2e2a 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): 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 | 17 ++++++++++-------
 etc/NEWS              |  6 ++++++
 lisp/isearch.el       | 32 +++++++++++++++++++++++++-------
 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 @@ Special Isearch
 
 @kindex M-s h r @r{(Incremental Search)}
 @findex isearch-highlight-regexp
-  You can exit the search while leaving the matches for the last
-search string highlighted on display.  To this end, type @kbd{M-s h r}
-(@code{isearch-highlight-regexp}), which will run
-@code{highlight-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}).
+@kindex M-s h l @r{(Incremental Search)}
+@findex isearch-highlight-lines-matching-regexp
+  You can exit the search while leaving the matches highlighted by
+typing @kbd{M-s h r} (@code{isearch-highlight-regexp}).  This runs
+@code{highlight-regexp} (@pxref{Highlight Interactively}), passing it
+the regexp derived from the search string and prompting you for the face
+to use for highlighting.  To highlight @emph{whole lines} containing
+matches (rather than @emph{just} the matches), type @kbd{M-s h l}
+(@code{isearch-highlight-lines-matching-regexp}).  In either case, 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)}
diff --git a/etc/NEWS b/etc/NEWS
index abbece374a4..0c2340603d0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1111,6 +1111,12 @@ 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 using the search
+string to highlight lines matching the search string. This is similar
+to the existing binding 'M-s h r' (highlight-regexp) that highlights
+JUST the search string.
+
 +++
 *** 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..6c7899a384b 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,12 @@ isearch-occur
 
 (declare-function hi-lock-read-face-name "hi-lock" ())
 
-(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)
+(defun isearch--highlight-regexp-or-lines (hi-lock-func)
+  "Run HI-LOCK-FUNC to exit isearch, leaving the matches highlighted.
+This is the internal function used by `isearch-highlight-regexp'
+and `isearch-highlight-lines-matching-regexp' to invoke
+HI-LOCK-FUNC (either `highlight-regexp' or
+`highlight-lines-matching-regexp' respectively)."
   (let (
 	;; Set `isearch-recursive-edit' to nil to prevent calling
 	;; `exit-recursive-edit' in `isearch-done' that terminates
@@ -2373,9 +2377,23 @@ 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 ()
+  "Exit Isearch mode, and call `highlight-regexp' with its regexp
+argument from the last search, and the face from
+`hi-lock-read-face-name'."
+  (interactive)
+  (isearch--highlight-regexp-or-lines 'highlight-regexp))
+
+(defun isearch-highlight-lines-matching-regexp ()
+  "Exit Isearch mode, and call `highlight-lines-matching-regexp'
+with its regexp argument from the last search, and the face from
+`hi-lock-read-face-name'."
+  (interactive)
+  (isearch--highlight-regexp-or-lines 'highlight-lines-matching-regexp))
+
 \f
 (defun isearch-delete-char ()
   "Undo last input item during a search.
-- 
2.20.0.rc2


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch
  2019-07-04  1:31                 ` Dima Kogan
@ 2019-07-13  7:22                   ` Eli Zaretskii
  0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2019-07-13  7:22 UTC (permalink / raw)
  To: Dima Kogan; +Cc: larsi, 18241-done, juri

> From: Dima Kogan <dima@secretsauce.net>
> Cc: juri@linkov.net, 18241@debbugs.gnu.org, larsi@gnus.org
> Date: Wed, 03 Jul 2019 18:31:08 -0700
> 
> Try the attached

Thanks, I pushed it to master.  Please note that there were a few
minor nits left that I fixed, see my followup commit.





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-07-13  7:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-10 22:04 bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch Dima Kogan
2019-06-25 22:32 ` Lars Ingebrigtsen
2019-06-25 22:58   ` Dima Kogan
2019-06-26 13:49     ` Lars Ingebrigtsen
2019-06-28 19:12       ` Juri Linkov
2019-06-30 18:08         ` Dima Kogan
2019-06-30 21:12           ` Juri Linkov
2019-07-01  3:09             ` Dima Kogan
2019-07-01 14:08               ` Eli Zaretskii
2019-07-04  1:31                 ` Dima Kogan
2019-07-13  7:22                   ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.