all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: 22541@debbugs.gnu.org, Dima Kogan <dima@secretsauce.net>
Subject: bug#22541: 25.0.50; highlight-regexp from isearch has is case-sensitive even if case-fold is active
Date: Tue, 25 Apr 2017 23:52:06 +0300	[thread overview]
Message-ID: <87mvb4yzux.fsf@localhost> (raw)
In-Reply-To: <87pog112pp.fsf@calancha-pc> (Tino Calancha's message of "Tue, 25 Apr 2017 14:22:10 +0900")

> I updated the patch to make work `hi-lock-unface-buffer'.  I added tests
> as well.
>
> Note that in interactive calls the case fold is determined with the
> variables `search-upper-case' and `case-fold-search'.  This way it behaves
> as `isearch-forward-regexp'.
> Before this bug case fold was determined _just_ with `case-fold-search'.
> Do you prefer avoid `search-upper-case' in this case?

Since ‘search-upper-case’ is used by other commands such as ‘occur’ and
‘perform-replace’, I think ‘hi-lock’ should use it as well.

>>From 7cad27c0fcc39add8679d0893010c4fdb3ed507a Mon Sep 17 00:00:00 2001
> From: Juri Linkov <juri@jurta.org>
> Date: Tue, 25 Apr 2017 14:17:23 +0900
> Subject: [PATCH] highlight-regexp: Honor case-fold-search
> ...
> Co-authored-by: Tino Calancha <tino.calancha@gmail.com>

I recommend to commit first my old patch, and then later your changes over it.

> -(defun hi-lock-face-buffer (regexp &optional face)
> +(defun hi-lock-face-buffer (regexp &optional face case-fold)
> ...
> +   (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)))

Small thing, but for readability in the interactive spec better to use
the same variable names as argument names:

        (list regexp face case-fold)

> -(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
> +                         (cons regexp
> +                               (byte-compile
> +                          `(lambda (limit)
> +                             (let ((case-fold-search ,case-fold))
> +                               (re-search-forward ,regexp limit t))))))
> +                       (list 0 (list 'quote face) 'prepend))))

Do you need to remember also the value of ‘case-fold-search’
(together with ‘regexp’)?

> @@ -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)))

If this works reliably, then we could remove that ugly hack
from ‘isearch-highlight-regexp’, I mean the one with the comment
“Turn isearch-string into a case-insensitive regexp”.





  reply	other threads:[~2017-04-25 20:52 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
2017-04-23 23:18     ` Juri Linkov
2017-04-25  5:22       ` Tino Calancha
2017-04-25 20:52         ` Juri Linkov [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mvb4yzux.fsf@localhost \
    --to=juri@linkov.net \
    --cc=22541@debbugs.gnu.org \
    --cc=dima@secretsauce.net \
    --cc=tino.calancha@gmail.com \
    /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.