Article View: gnu.emacs.bug
Article #87338Re: [19.27]: font-lock-mode - easier way to add new regexps
From: Simon Marshall
Date: Mon, 03 Oct 1994 09:04
Date: Mon, 03 Oct 1994 09:04
58 lines
3299 bytes
3299 bytes
Kevin> I've been looking into adding font-lock-keywords for other modes.
Kevin> It's a real pain to have to add something like:- [real pain code]
OK, I addressed the problem in font-lock.el by adding the following new
variable:
(defvar font-lock-defaults-alist
'(...)
"*Alist of major mode and Font Lock defaults.
Each item should be a list of the form:
(MAJOR-MODE . (FONT-LOCK-KEYWORDS KEYWORDS-ONLY CASE-FOLD FONT-LOCK-SYNTAX))
where both MAJOR-MODE and FONT-LOCK-KEYWORDS are symbols. If KEYWORDS-ONLY is
non-nil, syntactic fontification (strings and comments) is not performed.
If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying.
FONT-LOCK-SYNTAX should be a list of cons pairs of the form (CHAR . STRING), it
is used to set the local Font Lock syntax table for keyword fontification.")
one such item is:
(c-mode . (c-font-lock-keywords nil nil ((?\_ . "w"))))
Kevin> Another pain is having to set font-lock-no-comments if the mode
Kevin> doesn't have a comment syntax defined.
See above.
The above solution does mean that, if the new font-lock-defaults-alist is
not autoloaded, you have to do things like:
(eval-after-load "font-lock"
'(or (assq 'foo-mode font-lock-defaults-alist)
(setq font-lock-defaults-alist
(cons '(foo-mode . (foo-font-lock-keywords t nil t ((?\_ . "w"))))
font-lock-defaults-alist))))
to add foo-mode to the list. The difficulty with font-lock.el is that a
loading a package (to satisfy, say, an autoload for foo-mode) may or may
not need font-lock.el (foo-mode-hook has or has not 'turn-on-font-lock),
and font-lock.el may not be around.
I thought about building the variable name to use for font-lock-keywords
by (intern (concat (symbol-name major-mode) "-font-lock-keywords")), but
it (a) didn't seem reliable enough, and (b) didn't address the problem of
setting font-lock-no-comments, font-lock-keywords-case-fold-search, and
font-lock-syntax-table.
Setting font-lock-no-comments on the basis of the mode's comment-start (or
better comment-start-skip, at least font-lock-fontify-region uses that)
does of course assume that you never want to fontify strings if you don't
set comment-start[-skip]. I'm not sure about that, though I haven't an
example to show it;-) It doesn't address the other two variables anyhow.
My solution is still verbose, but I couldn't think of a way to deal with
all the 4 font-lock.el variables that need setting.
What do you think?
Si.
Technical Details
Message-ID:
<9410030906.AA00312@plod.esrin.esa.it>Path:
arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!mail.ESrin.ESa.IT!Simon.MarshallReferences:
<9409301322.AA20709@bartley>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,403ccaf6ecf69fde,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1994-10-03 02:12:26 PST Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!mail.ESrin.ESa.IT!Simon.Marshall From: Simon.Marshall@mail.ESrin.ESa.IT (Simon Marshall) Newsgroups: gnu.emacs.bug Subject: Re: [19.27]: font-lock-mode - easier way to add new regexps Date: 3 Oct 1994 05:04:41 -0400 Organization: GNUs Not Usenet Lines: 58 Sender: daemon@cis.ohio-state.edu Approved: bug-gnu-emacs@prep.ai.mit.edu Distribution: gnu Message-ID: <9410030906.AA00312@plod.esrin.esa.it> References: <9409301322.AA20709@bartley>