From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#11095: [PATCH] Re: bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment? Date: Mon, 10 Dec 2012 16:27:07 -0500 Message-ID: References: <81d37z271c.fsf@gmail.com> <87626i2i4r.fsf@gmail.com> <87zk1r3h3b.fsf@gmail.com> <87lidaan4g.fsf@gmail.com> <87a9tq6cs5.fsf@gmail.com> <87sj7iii4f.fsf@gmail.com> <87pq2k6744.fsf@gmail.com> <87ip8a352w.fsf@gmail.com> <87lid57ie1.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1355174858 1497 80.91.229.3 (10 Dec 2012 21:27:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Dec 2012 21:27:38 +0000 (UTC) Cc: 11095-done@debbugs.gnu.org To: Jambunathan K Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 10 22:27:51 2012 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 1TiAt5-00011m-Ad for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Dec 2012 22:27:43 +0100 Original-Received: from localhost ([::1]:53531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiAss-0005Wl-Q2 for geb-bug-gnu-emacs@m.gmane.org; Mon, 10 Dec 2012 16:27:30 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:39896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiAso-0005WR-Ow for bug-gnu-emacs@gnu.org; Mon, 10 Dec 2012 16:27:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TiAsn-0006eH-C1 for bug-gnu-emacs@gnu.org; Mon, 10 Dec 2012 16:27:26 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiAsn-0006eB-8n for bug-gnu-emacs@gnu.org; Mon, 10 Dec 2012 16:27:25 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TiAtO-0006KA-4l for bug-gnu-emacs@gnu.org; Mon, 10 Dec 2012 16:28:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 10 Dec 2012 21:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11095 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 11095-done@debbugs.gnu.org id=D11095.135517486924289 (code D ref 11095); Mon, 10 Dec 2012 21:28:02 +0000 Original-Received: (at 11095-done) by debbugs.gnu.org; 10 Dec 2012 21:27:49 +0000 Original-Received: from localhost ([127.0.0.1]:35954 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TiAtA-0006Ji-SH for submit@debbugs.gnu.org; Mon, 10 Dec 2012 16:27:49 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:40064) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TiAt8-0006Ja-QL for 11095-done@debbugs.gnu.org; Mon, 10 Dec 2012 16:27:47 -0500 Original-Received: from faina.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id qBALRC9M026184; Mon, 10 Dec 2012 16:27:12 -0500 Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id B4BAAB415D; Mon, 10 Dec 2012 16:27:07 -0500 (EST) In-Reply-To: <87lid57ie1.fsf@gmail.com> (Jambunathan K.'s message of "Tue, 11 Dec 2012 02:07:58 +0530") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4428=0 X-NAI-Spam-Version: 2.2.0.9309 : core <4428> : streams <873207> : uri <1290446> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.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:68293 Archived-At: > (let* ((hi-text > (buffer-substring-no-properties > - (previous-single-property-change (point) 'face) > - (next-single-property-change (point) 'face)))) > + (previous-single-char-property-change (point) 'face) > + (next-single-char-property-change (point) 'face)))) > ;; Compute hi-lock patterns that match the > ;; highlighted text at point. Use this later in > ;; during completing-read. But when overlays are used, the previous code should have found the overlay already. IIUC the above patch works only because of an inconsistency between previous-single-property-change and previous-single-char-property-change where the first may return nil whereas the other always returns an integer. But now that I look at this code I see that it doesn't work right for its intended use case (i.e. when font-lock-mode is on) when point is at the very start/end of the matched. So I've installed a completely different patch instead (see below). There should be an easier way to do it :-( > - (unless hi-lock-interactive-patterns > - (setq hi-lock--unused-faces hi-lock-face-defaults)) > + (unless (or hi-lock-interactive-patterns hi-lock--unused-faces) > + ;; This is the very first request for interactive highlighting. > + ;; Initialize unused faces list. > + (setq hi-lock--unused-faces (copy-sequence hi-lock-face-defaults))) [...] > - (setq hi-lock--unused-faces (remove face hi-lock--unused-faces)) > + (setq hi-lock--unused-faces (delete face hi-lock--unused-faces)) Why? Stefan === modified file 'lisp/hi-lock.el' --- lisp/hi-lock.el 2012-12-10 18:33:59 +0000 +++ lisp/hi-lock.el 2012-12-10 21:16:31 +0000 @@ -474,19 +474,33 @@ (let ((regexp (get-char-property (point) 'hi-lock-overlay-regexp))) (when regexp (push regexp regexps))) ;; With font-locking on, check if the cursor is on a highlighted text. - (and (memq (face-at-point) - (mapcar #'hi-lock-keyword->face hi-lock-interactive-patterns)) + (let ((face-after (get-text-property (point) 'face)) + (face-before + (unless (bobp) (get-text-property (1- (point)) 'face))) + (faces (mapcar #'hi-lock-keyword->face + hi-lock-interactive-patterns))) + (unless (memq face-before faces) (setq face-before nil)) + (unless (memq face-after faces) (setq face-after nil)) + (when (and face-before face-after (not (eq face-before face-after))) + (setq face-before nil)) + (when (or face-after face-before) (let* ((hi-text (buffer-substring-no-properties - (previous-single-property-change (point) 'face) - (next-single-property-change (point) 'face)))) + (if face-before + (or (previous-single-property-change (point) 'face) + (point-min)) + (point)) + (if face-after + (or (next-single-property-change (point) 'face) + (point-max)) + (point))))) ;; Compute hi-lock patterns that match the ;; highlighted text at point. Use this later in ;; during completing-read. (dolist (hi-lock-pattern hi-lock-interactive-patterns) (let ((regexp (car hi-lock-pattern))) (if (string-match regexp hi-text) - (push regexp regexps)))))) + (push regexp regexps))))))) regexps)) (defvar-local hi-lock--unused-faces nil