From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Jambunathan K <kjambunathan@gmail.com>
Cc: 11095-done@debbugs.gnu.org
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 [thread overview]
Message-ID: <jwvk3spr5hf.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87lid57ie1.fsf@gmail.com> (Jambunathan K.'s message of "Tue, 11 Dec 2012 02:07:58 +0530")
> (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
next prev parent reply other threads:[~2012-12-10 21:27 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-26 6:46 bug#11095: 24.0.94; hi-lock-face-buffer/unhighlight-regexp': Augment? Jambunathan K
2012-10-10 20:21 ` bug#11095: [PATCH] " Jambunathan K
2012-12-04 21:14 ` Stefan Monnier
2012-12-04 21:39 ` Drew Adams
2012-12-04 21:57 ` Stefan Monnier
2012-12-04 22:43 ` Drew Adams
2012-12-05 3:46 ` Stefan Monnier
2012-12-05 22:15 ` Jambunathan K
2012-12-06 1:14 ` Stefan Monnier
2012-12-06 5:06 ` Jambunathan K
2012-12-06 14:50 ` Jambunathan K
2012-12-06 19:16 ` Stefan Monnier
2012-12-06 19:36 ` Drew Adams
2012-12-06 21:26 ` Jambunathan K
2012-12-06 21:36 ` Stefan Monnier
2012-12-06 22:23 ` Jambunathan K
2012-12-07 4:07 ` Stefan Monnier
2012-12-07 4:46 ` Jambunathan K
2012-12-07 16:55 ` Stefan Monnier
2012-12-08 12:50 ` Jambunathan K
2012-12-10 4:26 ` Jambunathan K
2012-12-10 18:34 ` Stefan Monnier
2012-12-10 20:37 ` Jambunathan K
2012-12-10 21:27 ` Stefan Monnier [this message]
2012-10-10 22:08 ` Jambunathan K
2012-10-11 20:24 ` Jambunathan K
2012-10-11 20:33 ` Jambunathan K
2012-10-11 22:41 ` Juri Linkov
2012-10-12 4:30 ` Jambunathan K
2012-10-13 16:10 ` Juri Linkov
2012-10-13 17:28 ` Jambunathan K
2012-10-12 16:17 ` Jambunathan K
2012-10-12 18:18 ` Jambunathan K
2012-10-12 19:32 ` bug#11095: [FINAL] " Jambunathan K
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=jwvk3spr5hf.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=11095-done@debbugs.gnu.org \
--cc=kjambunathan@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 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).