From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha 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: Sat, 22 Apr 2017 21:31:31 +0900 Message-ID: <87vapwipy4.fsf@calancha-pc> References: <87si1a2tod.fsf@secretsauce.net> <8760x7vyui.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1492864335 13774 195.159.176.226 (22 Apr 2017 12:32:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 22 Apr 2017 12:32:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 22541@debbugs.gnu.org, Dima Kogan , tino.calancha@gmail.com To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 22 14:32:09 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1uCv-0003QY-6Q for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Apr 2017 14:32:09 +0200 Original-Received: from localhost ([::1]:35505 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1uD0-0008Jy-PG for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Apr 2017 08:32:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d1uCr-0008Jd-IQ for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 08:32:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d1uCo-0007pw-F2 for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 08:32:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35060) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d1uCo-0007pm-9l for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 08:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d1uCo-0000Xs-0l for bug-gnu-emacs@gnu.org; Sat, 22 Apr 2017 08:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Apr 2017 12:32:01 +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.14928643072076 (code B ref 22541); Sat, 22 Apr 2017 12:32:01 +0000 Original-Received: (at 22541) by debbugs.gnu.org; 22 Apr 2017 12:31:47 +0000 Original-Received: from localhost ([127.0.0.1]:33259 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1uCY-0000XP-Jb for submit@debbugs.gnu.org; Sat, 22 Apr 2017 08:31:46 -0400 Original-Received: from mail-io0-f179.google.com ([209.85.223.179]:35855) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d1uCW-0000X8-VF for 22541@debbugs.gnu.org; Sat, 22 Apr 2017 08:31:45 -0400 Original-Received: by mail-io0-f179.google.com with SMTP id p80so26249458iop.3 for <22541@debbugs.gnu.org>; Sat, 22 Apr 2017 05:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=WY9AMrc4movKFcsBaAu8f26SyGOwUiY9xTcahI40lsE=; b=NYwErRaK4errW8UH4xHKT3/4irlbAvnSmLTbPbgT7mn/2YXe7CvxZwi/BWqt/FyWwa QYGqldqPBEQUNhcYSP3oJRnw5pb6I41VkyCePrJMusFkGzMispyxJ7/TnSq/fX5uS/Ov DU3eCBykOBK4KonHCJcczqgflygsggOMnoUf4X/3tBOjRaJ6gPoulsgfAKFe5asizSlI Fy5GjXfOeTBcfjMblwqNdj7wefHsBIywRNVqCA3d7c20f5DJ4Grt2qaQEug4TkmJSQzl V/WDx01bjRzsJ9IHoevYw2m1f2s7ddxpc4uam4aq2XCCmOKOZPGhhOMTs+0bSJboPHtC fSZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=WY9AMrc4movKFcsBaAu8f26SyGOwUiY9xTcahI40lsE=; b=BVX/Ul+o0wdXJ3KfU62LSSUoAJkMQkAIHa7vRO8gPFuen92hEsyi/oZnljXs/rzEAd DgqWvt7B9xBswD+FbBW2fhQQcFskxUuK2R9MXuRi1v7DvhGG1MU7Y7Rge78nv++8NsuW j87aSnhfqw6o5gVC+LVtGGa8ubvUp65rjYh5y3LZyGBmUmOXoCPTXSlkDajhmsrG/Nyl RDkhpSldgoUsG+/6H/Mb9bWcNwfiqP+XYfTMjS2TZO+yiTtwv3N6Lk2JZpHk7WFev/jG mInSKh++U8vYrfbcjzyjnrelvfFGTyVqAqRkwjNdS99cuuCRSOcUb1Dzoiu426x526j4 oKoA== X-Gm-Message-State: AN3rC/5A09vdUFzCVIsCJ0HA7meGSLpUXjVDIV7dd6li07MqXxSSBlOz 7kthn3dCoGanxg== X-Received: by 10.98.219.197 with SMTP id f188mr16656817pfg.109.1492864298096; Sat, 22 Apr 2017 05:31:38 -0700 (PDT) Original-Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id c63sm21392767pfb.13.2017.04.22.05.31.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 22 Apr 2017 05:31:36 -0700 (PDT) In-Reply-To: <8760x7vyui.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 01 Mar 2016 02:14:15 +0200") 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" Xref: news.gmane.org gmane.emacs.bugs:131861 Archived-At: Juri Linkov 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 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))) --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