From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords
Date: Sat, 27 Feb 2016 10:07:07 -0500 [thread overview]
Message-ID: <56D1BB9B.7030202@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 2704 bytes --]
Hi emacs-devel,
Do bug reports with a proposed fix go on the bug tracker, or on this list? I've seen patches discussed here, so I'm not too sure. Apologies if this is the wrong place (please do let me know!)
Changing the lists of symbols prettified by prettify-symbols-mode is more tricky than it should be; I think this is a bug in prettify-symbols-mode. Here is a test case:
(with-current-buffer (get-buffer-create "fl")
(erase-buffer)
(emacs-lisp-mode)
(prettify-symbols-mode -1)
(setq prettify-symbols-alist '(("A" . ?B)))
(prettify-symbols-mode)
(setq prettify-symbols-alist '(("A" . ?C)))
(prettify-symbols-mode)
(insert "A A A")
(pop-to-buffer (current-buffer)))
Looking at this code, I expect “C C C” to be shown. Yet it's not the case; instead, “B B B” is shown.
On the other hand, this works:
(with-current-buffer (get-buffer-create "fl")
(erase-buffer)
(emacs-lisp-mode)
(prettify-symbols-mode -1)
(setq prettify-symbols-alist '(("A" . ?B)))
(prettify-symbols-mode)
(prettify-symbols-mode -1)
(setq prettify-symbols-alist '(("A" . ?C)))
(prettify-symbols-mode)
(insert "A A A")
(pop-to-buffer (current-buffer)))
I think the line indicated by !!! in the following code sample is wrong:
(define-minor-mode prettify-symbols-mode
(...)
(if prettify-symbols-mode
;; Turn on
(when (setq prettify-symbols--keywords (prettify-symbols--make-keywords))
(font-lock-add-keywords nil prettify-symbols--keywords) ;; !!! HERE
(setq-local font-lock-extra-managed-props
(append font-lock-extra-managed-props
'(composition
prettify-symbols-start
prettify-symbols-end)))
(when prettify-symbols-unprettify-at-point
(add-hook 'post-command-hook
#'prettify-symbols--post-command-hook nil t))
(font-lock-flush))
Indeed, turning on prettify-symbols-mode twice in a row causes two entries to be added to font-lock-add-keywords. This is not an issue in general, except if one changes prettify-symbols-alist between two calls. In that case font-lock-keywords gets two distinct entries for prettify-symbols, and the second one is ignored.
The proposed fix is to move the following snippet up, so that it runs in all cases, instead of just running when prettify-symbols-mode is turned off.
(when prettify-symbols--keywords
(font-lock-remove-keywords nil prettify-symbols--keywords)
(setq prettify-symbols--keywords nil))
Cheers,
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next reply other threads:[~2016-02-27 15:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-27 15:07 Clément Pit--Claudel [this message]
2016-02-27 17:26 ` Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords Drew Adams
2016-02-27 22:51 ` John Wiegley
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=56D1BB9B.7030202@gmail.com \
--to=clement.pit@gmail.com \
--cc=emacs-devel@gnu.org \
/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.