unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords
@ 2016-02-27 15:07 Clément Pit--Claudel
  2016-02-27 17:26 ` Drew Adams
  2016-02-27 22:51 ` John Wiegley
  0 siblings, 2 replies; 3+ messages in thread
From: Clément Pit--Claudel @ 2016-02-27 15:07 UTC (permalink / raw)
  To: Emacs developers


[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords
  2016-02-27 15:07 Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords Clément Pit--Claudel
@ 2016-02-27 17:26 ` Drew Adams
  2016-02-27 22:51 ` John Wiegley
  1 sibling, 0 replies; 3+ messages in thread
From: Drew Adams @ 2016-02-27 17:26 UTC (permalink / raw)
  To: Clément Pit--Claudel, Emacs developers

> 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!)

My understanding (but someone will correct me, if mistaken) is
that such things are _accepted_ either here (emacs-devel) or as
a bug report, but that using the bug tracker (i.e., reporting a
bug, with the fix/patch) is generally preferred/encouraged.

For one thing, that separates such stuff from this list.  For
another, the bug is tracked...



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords
  2016-02-27 15:07 Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords Clément Pit--Claudel
  2016-02-27 17:26 ` Drew Adams
@ 2016-02-27 22:51 ` John Wiegley
  1 sibling, 0 replies; 3+ messages in thread
From: John Wiegley @ 2016-02-27 22:51 UTC (permalink / raw)
  To: Clément Pit--Claudel; +Cc: Emacs developers

>>>>> Clément Pit--Claudel <clement.pit@gmail.com> writes:

> 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!)

I prefer the bug tracker, so that they do not get lost. Issues and patches
deserve a "ticket number". This guarantees they will be looked at *some day*,
and focuses discussions around them; while messages only sent here may get
lost in the emacs-devel archives forever.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-27 22:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-27 15:07 Running (prettify-symbols-mode) twice adds two entries to font-lock-keywords Clément Pit--Claudel
2016-02-27 17:26 ` Drew Adams
2016-02-27 22:51 ` John Wiegley

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).