* [PATCH 1/2] Add new function derived-mode-parents
@ 2011-02-08 18:43 Julien Danjou
2011-02-08 18:43 ` [PATCH 2/2] Make font-lock honor parents mode of current major-mode Julien Danjou
2011-02-08 21:12 ` [PATCH 1/2] Add new function derived-mode-parents Stefan Monnier
0 siblings, 2 replies; 9+ messages in thread
From: Julien Danjou @ 2011-02-08 18:43 UTC (permalink / raw)
To: emacs-devel; +Cc: Julien Danjou
Signed-off-by: Julien Danjou <julien@danjou.info>
---
lisp/ChangeLog | 4 ++++
lisp/emacs-lisp/derived.el | 7 +++++++
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c3b8d52..3ea0487 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2011-02-08 Julien Danjou <julien@danjou.info>
+
+ * emacs-lisp/derived.el (derived-mode-parents): New function.
+
2011-02-07 Jay Belanger <jay.p.belanger@gmail.com>
* calc/calc-units.el (math-logunits-quant): Add support for
diff --git a/lisp/emacs-lisp/derived.el b/lisp/emacs-lisp/derived.el
index 425a77e..5adba0e 100644
--- a/lisp/emacs-lisp/derived.el
+++ b/lisp/emacs-lisp/derived.el
@@ -277,6 +277,13 @@ is not very useful."
mode)
(make-obsolete 'derived-mode-class 'derived-mode-p "22.1")
+(defun derived-mode-parents (mode)
+ "Return the list of ancestors for MODE.
+MODE is included in the result."
+ (loop with mode = major-mode
+ while mode
+ collect mode
+ do (setq mode (get mode 'derived-mode-parent))))
\f
;;; PRIVATE
--
1.7.2.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/2] Make font-lock honor parents mode of current major-mode
2011-02-08 18:43 [PATCH 1/2] Add new function derived-mode-parents Julien Danjou
@ 2011-02-08 18:43 ` Julien Danjou
2011-02-09 16:37 ` Stefan Monnier
2011-02-08 21:12 ` [PATCH 1/2] Add new function derived-mode-parents Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Julien Danjou @ 2011-02-08 18:43 UTC (permalink / raw)
To: emacs-devel; +Cc: Julien Danjou
This allows to add font-lock keyword to prog-mode directly, so every other
children mode will use them.
Signed-off-by: Julien Danjou <julien@danjou.info>
---
lisp/ChangeLog | 5 +++++
lisp/font-lock.el | 15 ++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3ea0487..d405f47 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,10 @@
2011-02-08 Julien Danjou <julien@danjou.info>
+ * font-lock.el (font-lock-assq-mode): New function: execute assq
+ for a mode and its parents.
+ (font-lock-value-in-major-mode): Use font-lock-assq-mode.
+ (font-lock-set-defaults): Use font-lock-assq-mode.
+
* emacs-lisp/derived.el (derived-mode-parents): New function.
2011-02-07 Jay Belanger <jay.p.belanger@gmail.com>
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index b7b617f..9996424 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -1732,11 +1732,18 @@ If SYNTACTIC-KEYWORDS is non-nil, it means these keywords are used for
(funcall keywords)
(eval keywords)))))
+(defun font-lock-assq-mode (mode alist)
+ "Call `assq' with MODE and its parents on ALIST."
+ (loop for m in (derived-mode-parents mode)
+ for v = (assq m alist)
+ if v return v))
+
(defun font-lock-value-in-major-mode (alist)
"Return value in ALIST for `major-mode', or ALIST if it is not an alist.
Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t."
(if (consp alist)
- (cdr (or (assq major-mode alist) (assq t alist)))
+ (cdr (or (font-lock-assq-mode major-mode alist)
+ (assq t alist)))
alist))
(defun font-lock-choose-keywords (keywords level)
@@ -1789,9 +1796,11 @@ Sets various variables using `font-lock-defaults' and
(keywords
(font-lock-choose-keywords (nth 0 defaults)
(font-lock-value-in-major-mode font-lock-maximum-decoration)))
- (local (cdr (assq major-mode font-lock-keywords-alist)))
+ (local (cdr (font-lock-assq-mode
+ major-mode font-lock-keywords-alist)))
(removed-keywords
- (cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
+ (cdr-safe (font-lock-assq-mode
+ major-mode font-lock-removed-keywords-alist))))
(set (make-local-variable 'font-lock-defaults) defaults)
;; Syntactic fontification?
(if (nth 1 defaults)
--
1.7.2.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] Make font-lock honor parents mode of current major-mode
2011-02-08 18:43 ` [PATCH 2/2] Make font-lock honor parents mode of current major-mode Julien Danjou
@ 2011-02-09 16:37 ` Stefan Monnier
2011-02-09 17:15 ` Julien Danjou
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2011-02-09 16:37 UTC (permalink / raw)
To: Julien Danjou; +Cc: emacs-devel
> This allows to add font-lock keyword to prog-mode directly, so every other
> children mode will use them.
Making inheritance work with font-lock keywords is a good idea, but this
is the wrong way to do it. The right way is to take advantage of the
way inheritance works. E.g. use a variable which modes would
*modify* rather than just set. E.g. somehow convince all modes to use
the equivalent of font-lock-add-keywords.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] Make font-lock honor parents mode of current major-mode
2011-02-09 16:37 ` Stefan Monnier
@ 2011-02-09 17:15 ` Julien Danjou
2011-02-09 21:47 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: Julien Danjou @ 2011-02-09 17:15 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 707 bytes --]
On Wed, Feb 09 2011, Stefan Monnier wrote:
>> This allows to add font-lock keyword to prog-mode directly, so every other
>> children mode will use them.
>
> Making inheritance work with font-lock keywords is a good idea, but this
> is the wrong way to do it. The right way is to take advantage of the
> way inheritance works. E.g. use a variable which modes would
> *modify* rather than just set. E.g. somehow convince all modes to use
> the equivalent of font-lock-add-keywords.
I may not have enough knowledge of modes and font-lock to understand the
way you describe. Would you mind ellaboring a bit so I can maybe work on
that? :)
--
Julien Danjou
❱ http://julien.danjou.info
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] Make font-lock honor parents mode of current major-mode
2011-02-09 17:15 ` Julien Danjou
@ 2011-02-09 21:47 ` Stefan Monnier
2011-02-10 9:25 ` Julien Danjou
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2011-02-09 21:47 UTC (permalink / raw)
To: emacs-devel
>>> This allows to add font-lock keyword to prog-mode directly, so every other
>>> children mode will use them.
>>
>> Making inheritance work with font-lock keywords is a good idea, but this
>> is the wrong way to do it. The right way is to take advantage of the
>> way inheritance works. E.g. use a variable which modes would
>> *modify* rather than just set. E.g. somehow convince all modes to use
>> the equivalent of font-lock-add-keywords.
> I may not have enough knowledge of modes and font-lock to understand the
> way you describe. Would you mind ellaboring a bit so I can maybe work on
> that? :)
If modes *add* keywords to `font-lock-new-keywords', then children of
prog-mode will automatically inherit the prog-mode's keyword since
variables set by the parent are carried to the child.
So, I think we should change font-lock.el so that major modes setup
font-lock keywords by adding them to a variable. For backward
compatibility, the keywords listed in font-lock-defaults would be added,
of course.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] Make font-lock honor parents mode of current major-mode
2011-02-09 21:47 ` Stefan Monnier
@ 2011-02-10 9:25 ` Julien Danjou
2011-02-10 18:16 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: Julien Danjou @ 2011-02-10 9:25 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 930 bytes --]
On Wed, Feb 09 2011, Stefan Monnier wrote:
> If modes *add* keywords to `font-lock-new-keywords', then children of
> prog-mode will automatically inherit the prog-mode's keyword since
> variables set by the parent are carried to the child.
>
> So, I think we should change font-lock.el so that major modes setup
> font-lock keywords by adding them to a variable. For backward
> compatibility, the keywords listed in font-lock-defaults would be added,
> of course.
Just to be clean, what I was trying to fix actually is something I do in
my configuration file:
#+begin_src: emacs-lisp
(font-lock-add-keywords
'prog-mode
'(("\\<\\(FIXME\\|HACK\\|XXX\\|TODO\\)" 1 font-lock-warning-face prepend)))
#+end_src
This is not something modes do, I think. But doing that have no effect,
because font-lock does not check inheritance, therefore my patches.
--
Julien Danjou
❱ http://julien.danjou.info
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] Make font-lock honor parents mode of current major-mode
2011-02-10 9:25 ` Julien Danjou
@ 2011-02-10 18:16 ` Stefan Monnier
0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2011-02-10 18:16 UTC (permalink / raw)
To: emacs-devel
> #+begin_src: emacs-lisp
> (font-lock-add-keywords
> 'prog-mode
> '(("\\<\\(FIXME\\|HACK\\|XXX\\|TODO\\)" 1 font-lock-warning-face prepend)))
> #+end_src
> This is not something modes do, I think. But doing that have no effect,
> because font-lock does not check inheritance, therefore my patches.
The `prog-mode' argument to font-lock-add-keywords is the reason why
you'd need to explicitly check inheritance.
If you use
(add-hook 'prog-mode-hook
(lambda ()
(font-lock-add-keywords
nil
'(("\\<\\(FIXME\\|HACK\\|XXX\\|TODO\\)"
1 font-lock-warning-face prepend)))))
then things can be made to work without ever having to look at the
inheritance data. But of course, the above won't work either with the
current font-lock.el. That's what we need to fix.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] Add new function derived-mode-parents
2011-02-08 18:43 [PATCH 1/2] Add new function derived-mode-parents Julien Danjou
2011-02-08 18:43 ` [PATCH 2/2] Make font-lock honor parents mode of current major-mode Julien Danjou
@ 2011-02-08 21:12 ` Stefan Monnier
2011-02-08 21:19 ` Julien Danjou
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2011-02-08 21:12 UTC (permalink / raw)
To: Julien Danjou; +Cc: emacs-devel
> + * emacs-lisp/derived.el (derived-mode-parents): New function.
What for?
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-02-10 18:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-08 18:43 [PATCH 1/2] Add new function derived-mode-parents Julien Danjou
2011-02-08 18:43 ` [PATCH 2/2] Make font-lock honor parents mode of current major-mode Julien Danjou
2011-02-09 16:37 ` Stefan Monnier
2011-02-09 17:15 ` Julien Danjou
2011-02-09 21:47 ` Stefan Monnier
2011-02-10 9:25 ` Julien Danjou
2011-02-10 18:16 ` Stefan Monnier
2011-02-08 21:12 ` [PATCH 1/2] Add new function derived-mode-parents Stefan Monnier
2011-02-08 21:19 ` Julien Danjou
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).