unofficial mirror of bug-gnu-emacs@gnu.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

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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).