GNU bug report logs -
#24176
Confusing interaction between define-derived-mode and font-lock-add-keywords
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24176 in the body.
You can then email your comments to 24176 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24176
; Package
emacs
.
(Sun, 07 Aug 2016 06:42:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Clément Pit--Claudel <clement.pitclaudel <at> live.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sun, 07 Aug 2016 06:42:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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.
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24176
; Package
emacs
.
(Sun, 07 Aug 2016 06:58:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 24176 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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.
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24176
; Package
emacs
.
(Thu, 25 Aug 2016 00:54:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 24176 <at> debbugs.gnu.org (full text, mbox):
severity 24176 minor
tags 24176 confirmed
found 24176 25.1
quit
Clément Pit--Claudel <clement.pitclaudel <at> 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)
...
Severity set to 'minor' from 'normal'
Request was from
npostavs <at> users.sourceforge.net
to
control <at> debbugs.gnu.org
.
(Thu, 25 Aug 2016 00:54:02 GMT)
Full text and
rfc822 format available.
Added tag(s) confirmed.
Request was from
npostavs <at> users.sourceforge.net
to
control <at> debbugs.gnu.org
.
(Thu, 25 Aug 2016 00:54:02 GMT)
Full text and
rfc822 format available.
bug Marked as found in versions 25.1.
Request was from
npostavs <at> users.sourceforge.net
to
control <at> debbugs.gnu.org
.
(Thu, 25 Aug 2016 00:54:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24176
; Package
emacs
.
(Sun, 17 Nov 2019 07:01:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 24176 <at> debbugs.gnu.org (full text, mbox):
npostavs <at> users.sourceforge.net writes:
> Clément Pit--Claudel <clement.pitclaudel <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24176
; Package
emacs
.
(Sun, 17 Nov 2019 18:56:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 24176 <at> debbugs.gnu.org (full text, mbox):
> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#24176
; Package
emacs
.
(Mon, 24 Jan 2022 10:57:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 24176 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> 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
bug marked as fixed in version 29.1, send any further explanations to
24176 <at> debbugs.gnu.org and Clément Pit--Claudel <clement.pitclaudel <at> live.com>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 24 Jan 2022 10:57:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 21 Feb 2022 12:24:14 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 120 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.