From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#22541: 25.0.50; highlight-regexp from isearch has is case-sensitive even if case-fold is active Date: Tue, 01 Mar 2016 02:14:15 +0200 Organization: LINKOV.NET Message-ID: <8760x7vyui.fsf@mail.linkov.net> References: <87si1a2tod.fsf@secretsauce.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1456791754 26019 80.91.229.3 (1 Mar 2016 00:22:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Mar 2016 00:22:34 +0000 (UTC) Cc: 22541@debbugs.gnu.org To: Dima Kogan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Mar 01 01:22:22 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aaY4z-00005u-3q for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Mar 2016 01:22:21 +0100 Original-Received: from localhost ([::1]:39915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaY4y-0003v5-97 for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Feb 2016 19:22:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57794) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaY4k-0003cQ-GV for bug-gnu-emacs@gnu.org; Mon, 29 Feb 2016 19:22:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaY4h-00049d-7r for bug-gnu-emacs@gnu.org; Mon, 29 Feb 2016 19:22:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:57211) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaY4g-00049X-TY for bug-gnu-emacs@gnu.org; Mon, 29 Feb 2016 19:22:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aaY4g-0006eG-Ps for bug-gnu-emacs@gnu.org; Mon, 29 Feb 2016 19:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Mar 2016 00:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22541 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22541-submit@debbugs.gnu.org id=B22541.145679170425526 (code B ref 22541); Tue, 01 Mar 2016 00:22:02 +0000 Original-Received: (at 22541) by debbugs.gnu.org; 1 Mar 2016 00:21:44 +0000 Original-Received: from localhost ([127.0.0.1]:54337 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aaY4O-0006de-B0 for submit@debbugs.gnu.org; Mon, 29 Feb 2016 19:21:44 -0500 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:43997 helo=homiemail-a22.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aaY4L-0006dI-M2 for 22541@debbugs.gnu.org; Mon, 29 Feb 2016 19:21:42 -0500 Original-Received: from homiemail-a22.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTP id EB809114066; Mon, 29 Feb 2016 16:21:40 -0800 (PST) Original-Received: from localhost.linkov.net (62.65.219.72.cable.starman.ee [62.65.219.72]) (Authenticated sender: jurta@jurta.org) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPA id 20E83114060; Mon, 29 Feb 2016 16:21:39 -0800 (PST) In-Reply-To: <87si1a2tod.fsf@secretsauce.net> (Dima Kogan's message of "Tue, 02 Feb 2016 22:29:22 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:114184 Archived-At: > This is an offshoot of #22520: > > Juri Linkov wrote: > >> > Another possible side effect of this is that highlighting >> > >> > Database directory: >> > >> > doesn't work: hi-lock goes through the motions but nothing ends up b= eing >> > highlighted. Turning off char-folding fixes that. >> >> Actually =E2=80=9CDatabase directory:=E2=80=9D is not highlighted due = to case-folding. >> After toggling case-folding with =E2=80=98M-s c=E2=80=99 and preservin= g the capital D, >> it's highlighted correctly. > > This is true! And it's really weird... The user expectation is that if > we highlight something (M-s h r) directly from isearch, then at least > the thing isearch was finding would be highlighted, and here this > doesn't happen. So a slightly simpler example is: > > 0: Let the buffer have the string Ab > 1: put the point on A > 2: C-s > 3: C-w (to isearch the whole thing) > 4: M-s h r enter > > Then Ab isn't found because we defaulted to char-folding, and the regex= was > > \(?:a[=CC=80-=CC=84=CC=86-=CC=8A=CC=8C=CC=8F=CC=91=CC=A3=CC=A5=CC=A8]= \|[a=C2=AA=C3=A0-=C3=A5=C4=81=C4=83=C4=85=C7=8E=C8=81=C8=83=C8=A7=E1=B5=83= =E1=B8=81=E1=BA=A1=E1=BA=A3=E2=82=90=E2=93=90=EF=BD=81=F0=9D=90=9A=F0=9D=91= =8E=F0=9D=92=82=F0=9D=92=B6=F0=9D=93=AA=F0=9D=94=9E=F0=9D=95=92=F0=9D=96=86= =F0=9D=96=BA=F0=9D=97=AE=F0=9D=98=A2=F0=9D=99=96=F0=9D=9A=8A]\)\(?:b[=CC=87= =CC=A3=CC=B1]\|[b=E1=B5=87=E1=B8=83=E1=B8=85=E1=B8=87=E2=93=91=EF=BD=82=F0= =9D=90=9B=F0=9D=91=8F=F0=9D=92=83=F0=9D=92=B7=F0=9D=93=AB=F0=9D=94=9F=F0=9D= =95=93=F0=9D=96=87=F0=9D=96=BB=F0=9D=97=AF=F0=9D=98=A3=F0=9D=99=97=F0=9D=9A= =8B]\) > > This clearly has no case-folding active on top of the char-folding. But > the isearch had both, so the regex should get both. This would make the > regex twice as long, but it would be right, at least. > > If we turn off char-folding (but leave case-folding alone; on) by addin= g > a step > > 2.5: M-s ' > > then the regex we get is > > [Aa][Bb] > > which clearly has the case-folding, and works the way we expect. 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-p= hrase) 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 no= w? I see no other way than adding new argument to the chain of calls: diff --git a/lisp/isearch.el b/lisp/isearch.el index 2efa4c7..f77ef19 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1906,7 +1906,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))) =20 =0C diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index ec14e0b..27a2ae6 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -432,7 +432,7 @@ 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. Interactively, prompt for REGEXP using `read-regexp', then FACE. Use the global history list for FACE. @@ -444,10 +444,11 @@ hi-lock-face-buffer (list (hi-lock-regexp-okay (read-regexp "Regexp to highlight" 'regexp-history-last)) - (hi-lock-read-face-name))) + (hi-lock-read-face-name) + case-fold-search)) (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)) =20 ;;;###autoload (defalias 'highlight-phrase 'hi-lock-face-phrase-buffer) @@ -689,11 +690,17 @@ hi-lock-read-face-name (add-to-list 'hi-lock-face-defaults face t)) (intern face))) =20 -(defun hi-lock-set-pattern (regexp face) +(defun hi-lock-set-pattern (regexp face &optional case-fold) "Highlight REGEXP with face FACE." ;; 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 +718,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-en= d 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)))))))))) =20 (defun hi-lock-set-file-patterns (patterns) "Replace file patterns list with PATTERNS and refontify."