From: Tino Calancha <tino.calancha@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: 22541@debbugs.gnu.org, Dima Kogan <dima@secretsauce.net>,
tino.calancha@gmail.com
Subject: bug#22541: 25.0.50; highlight-regexp from isearch has is case-sensitive even if case-fold is active
Date: Sat, 22 Apr 2017 21:31:31 +0900 [thread overview]
Message-ID: <87vapwipy4.fsf@calancha-pc> (raw)
In-Reply-To: <8760x7vyui.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 01 Mar 2016 02:14:15 +0200")
Juri Linkov <juri@linkov.net> writes:
> The problem is that with introduction of char-folding, a hack responsible
> for case-folding in isearch-highlight-regexp that turns isearch-string
> into a case-insensitive regexp is not used anymore, i.e. it's overridden by
> isearch-regexp-function. (Also note a FIXME comment in hi-lock-process-phrase)
>
> Since we can't change the value of font-lock-keywords-case-fold-search
> for font-lock based highlighting in hi-lock for individual regexps,
> the best solution is to rely on the feature allowing MATCHER in
> font-lock-keywords to be a function. So we can let-bind case-fold-search
> in its lambda.
>
> Now the remaining problem is how to transfer case-fold from
> isearch-highlight-regexp down to hi-lock-set-pattern.
>
> Implementing pcre-style embedded modifiers is a good long-term goal,
> but we need to fix this for the next release. What options do we have now?
> I see no other way than adding new argument to the chain of calls:
Hi Juri,
I think is a good moment to comeback to this issue once we have already
released Emacs 25.2.
I have updated your patch so that hi-lock-face-buffer checks search-upper-case
in interactive calls. It works OK.
Since there isn't recent activity in the implementation of the pcre-style
embedded modifiers, we might use your patch in the meantime.
--8<-----------------------------cut here---------------start------------->8---
commit 7c3a515ec92f4bd9e82393dff1fcc4a3c2bb03b4
Author: Juri Linkov <juri@linkov.net>
Date: Sat Apr 22 21:11:41 2017 +0900
highlight-regexp: Honor case-fold-search
Perform the matches of REGEXP as `isearch-forward' (Bug#22541).
* lisp/hi-lock.el (hi-lock-face-buffer, hi-lock-set-pattern):
Add optional arg CASE-FOLD. All callers updated.
* lisp/isearch.el (isearch-highlight-regexp): Call hi-lock-face-buffer
with 3 arguments.
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index ebd18621ef..845b52c6b6 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -432,8 +432,9 @@ hi-lock-line-face-buffer
;;;###autoload
(defalias 'highlight-regexp 'hi-lock-face-buffer)
;;;###autoload
-(defun hi-lock-face-buffer (regexp &optional face)
+(defun hi-lock-face-buffer (regexp &optional face case-fold)
"Set face of each match of REGEXP to FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it.
Interactively, prompt for REGEXP using `read-regexp', then FACE.
Use the global history list for FACE.
@@ -441,13 +442,18 @@ hi-lock-face-buffer
use overlays for highlighting. If overlays are used, the
highlighting will not update as you type."
(interactive
- (list
- (hi-lock-regexp-okay
- (read-regexp "Regexp to highlight" 'regexp-history-last))
- (hi-lock-read-face-name)))
+ (let* ((reg
+ (hi-lock-regexp-okay
+ (read-regexp "Regexp to highlight" 'regexp-history-last)))
+ (face (hi-lock-read-face-name))
+ (fold
+ (if search-upper-case
+ (isearch-no-upper-case-p reg t)
+ case-fold-search)))
+ (list reg face fold)))
(or (facep face) (setq face 'hi-yellow))
(unless hi-lock-mode (hi-lock-mode 1))
- (hi-lock-set-pattern regexp face))
+ (hi-lock-set-pattern regexp face case-fold))
;;;###autoload
(defalias 'highlight-phrase 'hi-lock-face-phrase-buffer)
@@ -689,11 +695,18 @@ hi-lock-read-face-name
(add-to-list 'hi-lock-face-defaults face t))
(intern face)))
-(defun hi-lock-set-pattern (regexp face)
- "Highlight REGEXP with face FACE."
+(defun hi-lock-set-pattern (regexp face &optional case-fold)
+ "Highlight REGEXP with face FACE.
+If optional arg CASE-FOLD is non-nil, then bind `case-fold-search' to it."
;; Hashcons the regexp, so it can be passed to remove-overlays later.
(setq regexp (hi-lock--hashcons regexp))
- (let ((pattern (list regexp (list 0 (list 'quote face) 'prepend))))
+ (let ((pattern (list (if (eq case-fold 'undefined)
+ regexp
+ (byte-compile
+ `(lambda (limit)
+ (let ((case-fold-search ,case-fold))
+ (re-search-forward ,regexp limit t)))))
+ (list 0 (list 'quote face) 'prepend))))
;; Refuse to highlight a text that is already highlighted.
(unless (assoc regexp hi-lock-interactive-patterns)
(push pattern hi-lock-interactive-patterns)
@@ -711,12 +724,13 @@ hi-lock-set-pattern
(+ range-max (max 0 (- (point-min) range-min))))))
(save-excursion
(goto-char search-start)
- (while (re-search-forward regexp search-end t)
- (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
- (overlay-put overlay 'hi-lock-overlay t)
- (overlay-put overlay 'hi-lock-overlay-regexp regexp)
- (overlay-put overlay 'face face))
- (goto-char (match-end 0)))))))))
+ (let ((case-fold-search case-fold))
+ (while (re-search-forward regexp search-end t)
+ (let ((overlay (make-overlay (match-beginning 0) (match-end 0))))
+ (overlay-put overlay 'hi-lock-overlay t)
+ (overlay-put overlay 'hi-lock-overlay-regexp regexp)
+ (overlay-put overlay 'face face))
+ (goto-char (match-end 0))))))))))
(defun hi-lock-set-file-patterns (patterns)
"Replace file patterns list with PATTERNS and refontify."
diff --git a/lisp/isearch.el b/lisp/isearch.el
index c34739d638..250d37b45e 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1950,7 +1950,12 @@ isearch-highlight-regexp
(regexp-quote s))))
isearch-string ""))
(t (regexp-quote isearch-string)))))
- (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
+ (hi-lock-face-buffer regexp (hi-lock-read-face-name)
+ (if (and (eq isearch-case-fold-search t)
+ search-upper-case)
+ (isearch-no-upper-case-p
+ isearch-string isearch-regexp)
+ isearch-case-fold-search)))
(and isearch-recursive-edit (exit-recursive-edit)))
\f
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 26.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-04-22
Repository revision: eb52828a439f674733ba70844b795c6673733572
next prev parent reply other threads:[~2017-04-22 12:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-03 6:29 bug#22541: 25.0.50; highlight-regexp from isearch has is case-sensitive even if case-fold is active Dima Kogan
2016-03-01 0:14 ` Juri Linkov
2016-04-27 5:02 ` Dima Kogan
2016-04-30 20:07 ` Juri Linkov
2020-05-21 23:23 ` Juri Linkov
2017-04-22 12:31 ` Tino Calancha [this message]
2017-04-23 23:18 ` Juri Linkov
2017-04-25 5:22 ` Tino Calancha
2017-04-25 20:52 ` Juri Linkov
2017-04-27 14:22 ` Tino Calancha
2017-05-09 22:10 ` Juri Linkov
2017-05-24 13:35 ` Tino Calancha
2017-05-25 12:11 ` Tino Calancha
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87vapwipy4.fsf@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=22541@debbugs.gnu.org \
--cc=dima@secretsauce.net \
--cc=juri@linkov.net \
/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 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).