From: Dima Kogan <dima@secretsauce.net>
To: 18241@debbugs.gnu.org
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 [thread overview]
Message-ID: <87sil4uhlw.fsf@secretsauce.net> (raw)
[-- 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
next reply other threads:[~2014-08-10 22:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-10 22:04 Dima Kogan [this message]
2019-06-25 22:32 ` bug#18241: 24.4.50; [PATCH] I can now highlight-lines-matching-regexp from isearch 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sil4uhlw.fsf@secretsauce.net \
--to=dima@secretsauce.net \
--cc=18241@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.