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, 10 Aug 2014 15:04:11 -0700

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.


>From ca3b5261d034b21467f781d7aa2620d0050fea37 Mon Sep 17 00:00:00 2001
From: Dima Kogan <address@hidden>
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))))
 
 
 (defun isearch-delete-char ()
-- 
2.0.0


reply via email to

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