* font-lock basics?
@ 2005-01-31 4:03 Miles Bader
2005-01-31 13:36 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Miles Bader @ 2005-01-31 4:03 UTC (permalink / raw)
Is there some trick to using font-lock?
I tried the simplest thing I could think of:
(progn
(font-lock-mode -1)
(kill-all-local-variables)
(font-lock-add-keywords nil '(("high" . font-lock-keyword-face)))
(font-lock-mode t))
on the following text in a buffer:
Oh how I love high society.
... and .... no highlighted keywords.
What's up?
Here's the resulting value of font-lock-keywords:
font-lock-keywords's value is
(t
(("high" . font-lock-keyword-face))
("high"
(0 font-lock-keyword-face)))
Local in buffer asdf; global value is nil
-Miles
--
.Numeric stability is probably not all that important when you're guessing.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: font-lock basics?
2005-01-31 4:03 font-lock basics? Miles Bader
@ 2005-01-31 13:36 ` Stefan Monnier
2005-01-31 15:43 ` Francis Litterio
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2005-01-31 13:36 UTC (permalink / raw)
Cc: emacs-devel
> (progn
> (font-lock-mode -1)
> (kill-all-local-variables)
> (font-lock-add-keywords nil '(("high" . font-lock-keyword-face)))
> (font-lock-mode t))
Try to set font-lock-defaults instead.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: font-lock basics?
2005-01-31 13:36 ` Stefan Monnier
@ 2005-01-31 15:43 ` Francis Litterio
2005-01-31 16:14 ` Francis Litterio
2005-01-31 16:29 ` Stefan Monnier
0 siblings, 2 replies; 6+ messages in thread
From: Francis Litterio @ 2005-01-31 15:43 UTC (permalink / raw)
Stefan Monnier wrote:
>> (progn
>> (font-lock-mode -1)
>> (kill-all-local-variables)
>> (font-lock-add-keywords nil '(("high" . font-lock-keyword-face)))
>> (font-lock-mode t))
>
> Try to set font-lock-defaults instead.
That begs the question: What is wrong with the above code? According to
the docstrings for the functions called above, it should work. Why
doesn't it?
--
Francis Litterio
franl <at> world . std . com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: font-lock basics?
2005-01-31 15:43 ` Francis Litterio
@ 2005-01-31 16:14 ` Francis Litterio
2005-01-31 16:29 ` Stefan Monnier
1 sibling, 0 replies; 6+ messages in thread
From: Francis Litterio @ 2005-01-31 16:14 UTC (permalink / raw)
I wrote:
> Stefan Monnier wrote:
>
>>> (progn
>>> (font-lock-mode -1)
>>> (kill-all-local-variables)
>>> (font-lock-add-keywords nil '(("high" . font-lock-keyword-face)))
>>> (font-lock-mode t))
>>
>> Try to set font-lock-defaults instead.
>
> That begs the question: What is wrong with the above code? According to
> the docstrings for the functions called above, it should work. Why
> doesn't it?
I think this code in function font-lock-default-function is preventing
the fontification from happening:
;; Only do hard work if the mode has specified stuff in
;; `font-lock-defaults'.
(when (or font-lock-defaults
(cdr (assq major-mode font-lock-defaults-alist)))
(font-lock-mode-internal mode)))
In a newly-created fundamental-mode buffer, font-lock-defaults is nil if
the user has not explicitly assigned it a value (and the font-lock
documentation does not state that one _must_ set font-lock-defaults for
font-lock-mode to work).
This patch to font-core.el fixes the problem:
--- font-core.el 01 Sep 2003 11:45:12 -0400 1.23
+++ font-core.el 31 Jan 2005 11:18:03 -0500
@@ -200,8 +200,10 @@
(delq elt char-property-alias-alist))))))
;; Only do hard work if the mode has specified stuff in
- ;; `font-lock-defaults'.
+ ;; `font-lock-defaults' or if `font-lock-keywords' is non-nil
+ ;; in this buffer.
(when (or font-lock-defaults
+ font-lock-keywords
(cdr (assq major-mode font-lock-defaults-alist)))
(font-lock-mode-internal mode)))
I hope this helps.
--
Francis Litterio
franl <at> world . std . com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: font-lock basics?
2005-01-31 15:43 ` Francis Litterio
2005-01-31 16:14 ` Francis Litterio
@ 2005-01-31 16:29 ` Stefan Monnier
2005-01-31 17:31 ` Francis Litterio
1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2005-01-31 16:29 UTC (permalink / raw)
Cc: emacs-devel
>>> (progn
>>> (font-lock-mode -1)
>>> (kill-all-local-variables)
>>> (font-lock-add-keywords nil '(("high" . font-lock-keyword-face)))
>>> (font-lock-mode t))
>>
>> Try to set font-lock-defaults instead.
> That begs the question: What is wrong with the above code? According to
> the docstrings for the functions called above, it should work. Why
> doesn't it?
Actually the docstrings are sufficiently vague that it's not clear whether
it should work or not. In any case one of the problems is that
font-lock-add-keywords is meant to add to a *preexisting* list of keywords.
So the above only makes sense if the font-lock-add-keywords is called from
some minor mode which simply assumes that the major mode has setup
font-lock-defaults. And even that doesn't work so well because the minor
mode has no control over font-lock-case-fold-search.
Maybe the patch below papers over this particular manifestation of the more
general problem.
Miles, what is the context of your question?
Stefan
Index: font-core.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/font-core.el,v
retrieving revision 1.23
diff -u -u -b -r1.23 font-core.el
--- font-core.el 1 Sep 2003 15:45:12 -0000 1.23
+++ font-core.el 31 Jan 2005 16:24:56 -0000
@@ -1,7 +1,7 @@
;;; font-core.el --- Core interface to font-lock
-;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001, 02, 2003
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+;; 2002, 2003, 2005 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Keywords: languages, faces
@@ -202,6 +202,7 @@
;; Only do hard work if the mode has specified stuff in
;; `font-lock-defaults'.
(when (or font-lock-defaults
+ (and (boundp 'font-lock-keywords) font-lock-keywords)
(cdr (assq major-mode font-lock-defaults-alist)))
(font-lock-mode-internal mode)))
@@ -295,6 +296,5 @@
(provide 'font-core)
+;; arch-tag: f8c286e1-02f7-41d9-b89b-1b67780aed71
;;; font-core.el ends here
-
-;;; arch-tag: f8c286e1-02f7-41d9-b89b-1b67780aed71
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: font-lock basics?
2005-01-31 16:29 ` Stefan Monnier
@ 2005-01-31 17:31 ` Francis Litterio
0 siblings, 0 replies; 6+ messages in thread
From: Francis Litterio @ 2005-01-31 17:31 UTC (permalink / raw)
Stefan Monnier wrote:
> Maybe the patch below papers over this particular manifestation of the more
> general problem.
It does. Your patch is preferable to mine (in another message) -- I
didn't realize that font-lock-keywords might not be bound when this code
executes.
> Index: font-core.el
> ===================================================================
> RCS file: /cvsroot/emacs/emacs/lisp/font-core.el,v
> retrieving revision 1.23
> diff -u -u -b -r1.23 font-core.el
> --- font-core.el 1 Sep 2003 15:45:12 -0000 1.23
> +++ font-core.el 31 Jan 2005 16:24:56 -0000
> @@ -1,7 +1,7 @@
> ;;; font-core.el --- Core interface to font-lock
>
> -;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001, 02, 2003
> -;; Free Software Foundation, Inc.
> +;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
> +;; 2002, 2003, 2005 Free Software Foundation, Inc.
>
> ;; Maintainer: FSF
> ;; Keywords: languages, faces
> @@ -202,6 +202,7 @@
> ;; Only do hard work if the mode has specified stuff in
> ;; `font-lock-defaults'.
> (when (or font-lock-defaults
> + (and (boundp 'font-lock-keywords) font-lock-keywords)
> (cdr (assq major-mode font-lock-defaults-alist)))
> (font-lock-mode-internal mode)))
>
> @@ -295,6 +296,5 @@
>
> (provide 'font-core)
>
> +;; arch-tag: f8c286e1-02f7-41d9-b89b-1b67780aed71
> ;;; font-core.el ends here
> -
> -;;; arch-tag: f8c286e1-02f7-41d9-b89b-1b67780aed71
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-01-31 17:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-31 4:03 font-lock basics? Miles Bader
2005-01-31 13:36 ` Stefan Monnier
2005-01-31 15:43 ` Francis Litterio
2005-01-31 16:14 ` Francis Litterio
2005-01-31 16:29 ` Stefan Monnier
2005-01-31 17:31 ` Francis Litterio
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).