* bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords
@ 2016-08-07 6:41 Clément Pit--Claudel
[not found] ` <handler.24176.B.14705521086608.ack@debbugs.gnu.org>
0 siblings, 1 reply; 6+ messages in thread
From: Clément Pit--Claudel @ 2016-08-07 6:41 UTC (permalink / raw)
To: 24176
[-- Attachment #1.1: Type: text/plain, Size: 686 bytes --]
Hi bug-gnu-emacs,
Given the following mode definitions, I was expecting ~/a to have one keyword, ~/b to have two, and ~/c to have three:
(define-derived-mode ~/a fundamental-mode
(font-lock-add-keywords nil `(("a" 0 'font-lock-keyword-face))))
(define-derived-mode ~/b ~/a
(font-lock-add-keywords nil `(("b" 0 'font-lock-builtin-face))))
(define-derived-mode ~/c ~/b
(font-lock-add-keywords nil `(("c" 0 'font-lock-constant-face))))
This assumption is wrong, as can be easily verified by opening a new buffer, inserting "abc", and switching between ~/a, ~/b, ~/c.
What's going on? Is this a font-lock bug, a doc bug, or a user-got-confused issue?
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#24176: Acknowledgement (Confusing interaction between define-derived-mode and font-lock-add-keywords)
[not found] ` <handler.24176.B.14705521086608.ack@debbugs.gnu.org>
@ 2016-08-07 6:57 ` Clément Pit--Claudel
2016-08-25 0:53 ` bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords npostavs
0 siblings, 1 reply; 6+ messages in thread
From: Clément Pit--Claudel @ 2016-08-07 6:57 UTC (permalink / raw)
To: 24176
[-- Attachment #1.1: Type: text/plain, Size: 548 bytes --]
Sorry, the original report had a confusing example; here is a fixed copy.
(define-derived-mode ~/a fundamental-mode "~/a"
(font-lock-add-keywords nil `(("a" 0 'font-lock-keyword-face))))
(define-derived-mode ~/b ~/a "~/b"
(font-lock-add-keywords nil `(("b" 0 'font-lock-builtin-face))))
(define-derived-mode ~/c ~/b "~/c"
(font-lock-add-keywords nil `(("c" 0 'font-lock-constant-face))))
Explicitly calling (setq font-lock-major-mode major-mode) before calling font-lock-add-keywords yields the expected behaviour.
Clément.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords
2016-08-07 6:57 ` bug#24176: Acknowledgement (Confusing interaction between define-derived-mode and font-lock-add-keywords) Clément Pit--Claudel
@ 2016-08-25 0:53 ` npostavs
2019-11-17 6:59 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: npostavs @ 2016-08-25 0:53 UTC (permalink / raw)
To: Clément Pit--Claudel; +Cc: 24176
severity 24176 minor
tags 24176 confirmed
found 24176 25.1
quit
Clément Pit--Claudel <clement.pitclaudel@live.com> writes:
> Sorry, the original report had a confusing example; here is a fixed copy.
>
> (define-derived-mode ~/a fundamental-mode "~/a"
> (font-lock-add-keywords nil `(("a" 0 'font-lock-keyword-face))))
> (define-derived-mode ~/b ~/a "~/b"
> (font-lock-add-keywords nil `(("b" 0 'font-lock-builtin-face))))
> (define-derived-mode ~/c ~/b "~/c"
> (font-lock-add-keywords nil `(("c" 0 'font-lock-constant-face))))
>
> Explicitly calling (setq font-lock-major-mode major-mode) before calling font-lock-add-keywords yields the expected behaviour.
Yeah, it seems `font-lock-set-defaults' (called from
`font-lock-add-keywords') deletes the parent mode's added keywords since
they were not from the "correct" mode.
(defun font-lock-set-defaults ()
"Set fontification defaults appropriately for this mode.
Sets various variables using `font-lock-defaults' and
`font-lock-maximum-decoration'."
;; Set fontification defaults if not previously set for correct major mode.
(unless (and font-lock-set-defaults
(eq font-lock-major-mode major-mode))
(setq font-lock-major-mode major-mode)
(setq font-lock-set-defaults t)
...
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords
2016-08-25 0:53 ` bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords npostavs
@ 2019-11-17 6:59 ` Lars Ingebrigtsen
2019-11-17 18:55 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-11-17 6:59 UTC (permalink / raw)
To: npostavs; +Cc: Clément Pit--Claudel, Stefan Monnier, 24176
npostavs@users.sourceforge.net writes:
> Clément Pit--Claudel <clement.pitclaudel@live.com> writes:
>
>> Sorry, the original report had a confusing example; here is a fixed copy.
>>
>> (define-derived-mode ~/a fundamental-mode "~/a"
>> (font-lock-add-keywords nil `(("a" 0 'font-lock-keyword-face))))
>> (define-derived-mode ~/b ~/a "~/b"
>> (font-lock-add-keywords nil `(("b" 0 'font-lock-builtin-face))))
>> (define-derived-mode ~/c ~/b "~/c"
>> (font-lock-add-keywords nil `(("c" 0 'font-lock-constant-face))))
>>
>> Explicitly calling (setq font-lock-major-mode major-mode) before
>> calling font-lock-add-keywords yields the expected behaviour.
>
> Yeah, it seems `font-lock-set-defaults' (called from
> `font-lock-add-keywords') deletes the parent mode's added keywords since
> they were not from the "correct" mode.
>
> (defun font-lock-set-defaults ()
> "Set fontification defaults appropriately for this mode.
> Sets various variables using `font-lock-defaults' and
> `font-lock-maximum-decoration'."
> ;; Set fontification defaults if not previously set for correct major mode.
> (unless (and font-lock-set-defaults
> (eq font-lock-major-mode major-mode))
> (setq font-lock-major-mode major-mode)
> (setq font-lock-set-defaults t)
> ...
Stefan, is this working as designed? If so, the behaviour should
perhaps be mentioned in the doc for font-lock-add-keywords and/or
define-derived-mode?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords
2019-11-17 6:59 ` Lars Ingebrigtsen
@ 2019-11-17 18:55 ` Stefan Monnier
2022-01-24 10:56 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-11-17 18:55 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Clément Pit--Claudel, npostavs, 24176
> Stefan, is this working as designed?
Not really, no. The design didn't take this into account at least.
> If so, the behaviour should perhaps be mentioned in the doc for
> font-lock-add-keywords and/or define-derived-mode?
I think it'd be better to fix it ;-)
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords
2019-11-17 18:55 ` Stefan Monnier
@ 2022-01-24 10:56 ` Lars Ingebrigtsen
0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-24 10:56 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Clément Pit--Claudel, 24176, npostavs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Stefan, is this working as designed?
>
> Not really, no. The design didn't take this into account at least.
>
>> If so, the behaviour should perhaps be mentioned in the doc for
>> font-lock-add-keywords and/or define-derived-mode?
>
> I think it'd be better to fix it ;-)
I think I've fixed this in Emacs 29.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-01-24 10:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-07 6:41 bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords Clément Pit--Claudel
[not found] ` <handler.24176.B.14705521086608.ack@debbugs.gnu.org>
2016-08-07 6:57 ` bug#24176: Acknowledgement (Confusing interaction between define-derived-mode and font-lock-add-keywords) Clément Pit--Claudel
2016-08-25 0:53 ` bug#24176: Confusing interaction between define-derived-mode and font-lock-add-keywords npostavs
2019-11-17 6:59 ` Lars Ingebrigtsen
2019-11-17 18:55 ` Stefan Monnier
2022-01-24 10:56 ` Lars Ingebrigtsen
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.