Re: Cannot (initially) change font-lock-keywords in mhtml-mode-hook
Michael Heerdegen via Users list for the GNU Emacs text editor <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <[email protected]> |
Frank Steiner <[email protected]> writes: > Hi, > > I'm trying to redefine sgml-font-lock-keywords as I prefer > some different font locking for my html files. I do so by > > (add-hook > 'mhtml-mode-hook > (lambda () (progn > (setq sgml-font-lock-keywords ... (do some stuff)) > (setq sgml-font-lock-keywords-1 sgml-font-lock-keywords) > (setq sgml-font-lock-keywords-2 sgml-font-lock-keywords) > ))) > > > Now when I load a html file, it choses the html+ (mhtml) mode > but shows the font locking (colors and classes, e.g. <head> > with function-name-face) as defined in sgml-mode.el. That's expected - it's too late. Variables like `sgml-font-lock-keywords' only hold the definitions, but what actually is used by font-lock is the value of `font-lock-defaults'. This variable is initialized in the mode's function (using `sgml-font-lock-keywords' - see `sgml-mode'), but when your hook function is called, this has already been done. The typical solution for this kind of problem is to move such definitions from the mode hook to an according `with-eval-after-load' call. Michael.