all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Font Lock Problems
@ 2003-10-21 15:31 Phillip Lord
  2003-10-21 16:11 ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Phillip Lord @ 2003-10-21 15:31 UTC (permalink / raw)





I'm trying to add support for font lock to a small mode I have
written. 

I am defining the font lock keywords like so...


(defvar language-speak-delimiter " >>>> ")

(font-lock-add-keywords
 'language-speak-mode
 (list (cons language-speak-delimiter font-lock-keyword-face)
       (list (concat "\\(.*\\)" language-speak-delimiter)  1 font-lock-string-face)
       (list (concat language-speak-delimiter "\\(.*\\)") 1 font-lock-type-face)))

(font-lock-add-keywords
 'language-speak-mode
 '(("#.*" 0 font-lock-comment-face)))


This works fine an does what I expect (that is for each line
highlights ">>>>" in one colour, all the text before it in another,
and all the text after it in another). But its does it very
lazily. In fact I have to call "font-lock-fontify-buffer" to get it to
do any fontification at all. 

I'd like it to work a little bit more "on the fly". Can anyone tell me
why it is not?

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-21 15:31 Font Lock Problems Phillip Lord
@ 2003-10-21 16:11 ` Stefan Monnier
  2003-10-21 17:08   ` Phillip Lord
  2003-10-23  5:18   ` Harald Maier
  0 siblings, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2003-10-21 16:11 UTC (permalink / raw)


> (font-lock-add-keywords
>  'language-speak-mode
>  '(("#.*" 0 font-lock-comment-face)))

Better setup the syntax-table properly to mark # as a comment-startand
\n as comment-end.

> This works fine an does what I expect (that is for each line
> highlights ">>>>" in one colour, all the text before it in another,
> and all the text after it in another). But its does it very
> lazily. In fact I have to call "font-lock-fontify-buffer" to get it to
> do any fontification at all. 

Have you turned font-lock-mode ON ?


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-21 16:11 ` Stefan Monnier
@ 2003-10-21 17:08   ` Phillip Lord
  2003-10-21 20:03     ` Stefan Monnier
  2003-10-23  5:18   ` Harald Maier
  1 sibling, 1 reply; 11+ messages in thread
From: Phillip Lord @ 2003-10-21 17:08 UTC (permalink / raw)


>>>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

  >> (font-lock-add-keywords 'language-speak-mode '(("#.*" 0
  >> font-lock-comment-face)))

  Stefan> Better setup the syntax-table properly to mark # as a
  Stefan> comment-startand \n as comment-end.

Okay, thats fair enough. I've never done anything with the syntax
table before, but I shall investigate. 


  >> This works fine an does what I expect (that is for each line
  >> highlights ">>>>" in one colour, all the text before it in
  >> another, and all the text after it in another). But its does it
  >> very lazily. In fact I have to call "font-lock-fontify-buffer" to
  >> get it to do any fontification at all.

  Stefan> Have you turned font-lock-mode ON ?

I presume so. 

I am using global-font-lock-mode. Do I have to add something to my
mode to provide support for font-lock? I'm currently defining my mode
as a derived mode from text-mode.

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-21 17:08   ` Phillip Lord
@ 2003-10-21 20:03     ` Stefan Monnier
  2003-10-22 13:44       ` Phillip Lord
  2003-10-23 15:49       ` Phillip Lord
  0 siblings, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2003-10-21 20:03 UTC (permalink / raw)


> Okay, thats fair enough. I've never done anything with the syntax
> table before, but I shall investigate. 

Check out SampleMode in the emacswiki where it has an example.

>>> This works fine an does what I expect (that is for each line
>>> highlights ">>>>" in one colour, all the text before it in
>>> another, and all the text after it in another). But its does it
>>> very lazily. In fact I have to call "font-lock-fontify-buffer" to
>>> get it to do any fontification at all.

Stefan> Have you turned font-lock-mode ON ?
> I presume so.

Well, what is the value of `font-lock-mode' ?

> I am using global-font-lock-mode. Do I have to add something to my
> mode to provide support for font-lock? I'm currently defining my mode
> as a derived mode from text-mode.

Don't use `font-lock-add-keywords' when defining a major mode.
See SampleMode for an example.


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-21 20:03     ` Stefan Monnier
@ 2003-10-22 13:44       ` Phillip Lord
  2003-10-22 14:10         ` Stefan Monnier
  2003-10-23 15:49       ` Phillip Lord
  1 sibling, 1 reply; 11+ messages in thread
From: Phillip Lord @ 2003-10-22 13:44 UTC (permalink / raw)


>>>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

  >> Okay, thats fair enough. I've never done anything with the syntax
  >> table before, but I shall investigate.

  Stefan> Check out SampleMode in the emacswiki where it has an
  Stefan> example.

Okay. 

  >>>> This works fine an does what I expect (that is for each line
  >>>> highlights ">>>>" in one colour, all the text before it in
  >>>> another, and all the text after it in another). But its does it
  >>>> very lazily. In fact I have to call "font-lock-fontify-buffer"
  >>>> to get it to do any fontification at all.

  Stefan> Have you turned font-lock-mode ON ?
  >> I presume so.

  Stefan> Well, what is the value of `font-lock-mode' ?

It's nil. This worried me, but I checked the value in other buffers
which appear to be font locked and it was likewise null there. 


  >> I am using global-font-lock-mode. Do I have to add something to
  >> my mode to provide support for font-lock? I'm currently defining
  >> my mode as a derived mode from text-mode.

  Stefan> Don't use `font-lock-add-keywords' when defining a major
  Stefan> mode.  See SampleMode for an example.

Yes, this looks good. I shall work with this. 

Thanks Stefan

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-22 13:44       ` Phillip Lord
@ 2003-10-22 14:10         ` Stefan Monnier
  2003-10-22 15:09           ` Phillip Lord
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2003-10-22 14:10 UTC (permalink / raw)


> It's nil. This worried me, but I checked the value in other buffers
> which appear to be font locked and it was likewise null there. 

Not all highlighting is done by font-lock.  E.g. Info, PCL-CVS, most Gnus
buffers, ...


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-22 14:10         ` Stefan Monnier
@ 2003-10-22 15:09           ` Phillip Lord
  0 siblings, 0 replies; 11+ messages in thread
From: Phillip Lord @ 2003-10-22 15:09 UTC (permalink / raw)


>>>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

  >> It's nil. This worried me, but I checked the value in other
  >> buffers which appear to be font locked and it was likewise null
  >> there.

  Stefan> Not all highlighting is done by font-lock.  E.g. Info,
  Stefan> PCL-CVS, most Gnus buffers, ...

Yeah, I thought that this would be the case, but I didn't have a good
way of working out which was, and which was not. 

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-21 16:11 ` Stefan Monnier
  2003-10-21 17:08   ` Phillip Lord
@ 2003-10-23  5:18   ` Harald Maier
  2003-10-23 14:21     ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Harald Maier @ 2003-10-23  5:18 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> (font-lock-add-keywords
>>  'language-speak-mode
>>  '(("#.*" 0 font-lock-comment-face)))
>
> Better setup the syntax-table properly to mark # as a comment-startand
> \n as comment-end.

Should I here for explicitly change the syntax table or is it enough
to set the 'comment-start' and 'comment-end' variables? Or should I
not confuse the variable 'comment-start' and the 'comment-start
sequence' syntax table entries.  If this is so for what purposes do I
need the variable 'comment-start' and 'comment-end'. Do I need
'comment-start' and 'comment-end' maybe for fill-paragraph.

In my special case I am not able to use fill paragraph inside a
comment. What should I use to get this to work. Or with other words: I
want that inside a comment line the fill-paragraph function wraps the
line and prefixes the new lines with the same comment characters as
the original line.

Harald

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-23  5:18   ` Harald Maier
@ 2003-10-23 14:21     ` Stefan Monnier
  2003-10-23 15:53       ` Harald Maier
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2003-10-23 14:21 UTC (permalink / raw)


> Should I here for explicitly change the syntax table or is it enough
> to set the 'comment-start' and 'comment-end' variables? Or should I
> not confuse the variable 'comment-start' and the 'comment-start
> sequence' syntax table entries.  If this is so for what purposes do I
> need the variable 'comment-start' and 'comment-end'. Do I need
> 'comment-start' and 'comment-end' maybe for fill-paragraph.

The comment-start and comment-end variables are used by things like
newcomment (i.e. comment-region, auto-fill, ...).  The syntax-table's
comment markers are used by things like forward-sexp, font-lock, and also
newcomment.el (though it still requires the comment-start and comment-end
things as well).

The default filling code (which is separate from auto-fill) does not know
about comments at all.  In Emacs-CVS, this has been improved a little, so
that it now uses comment-start (as well as syntax-tables sometimes), but
only for \n-terminated comments and it doesn't work right in
all circumstances.

I.e. you need to set both the variables and the syntax-table and if you want
fill-paragraph to pay attention to comments, you either need to use
Emacs-CVS or to write your own fill-paragraph-function.  Take a look at the
lisp-paragraph-function used in lisp-mode for an example (it is the function
that got generalized and moved to fill.el in Emacs-CVS).

This is an area that still requires a good deal of improvement, as you
can see.


        Stefan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-21 20:03     ` Stefan Monnier
  2003-10-22 13:44       ` Phillip Lord
@ 2003-10-23 15:49       ` Phillip Lord
  1 sibling, 0 replies; 11+ messages in thread
From: Phillip Lord @ 2003-10-23 15:49 UTC (permalink / raw)


>>>>> "Stefan" == Stefan Monnier <monnier@iro.umontreal.ca> writes:

  >> I am using global-font-lock-mode. Do I have to add something to
  >> my mode to provide support for font-lock? I'm currently defining
  >> my mode as a derived mode from text-mode.

  Stefan> Don't use `font-lock-add-keywords' when defining a major
  Stefan> mode.  See SampleMode for an example.


Okay, I've looked at SampleMode, and I have it all working now. Many
thanks.

Cheers

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Font Lock Problems
  2003-10-23 14:21     ` Stefan Monnier
@ 2003-10-23 15:53       ` Harald Maier
  0 siblings, 0 replies; 11+ messages in thread
From: Harald Maier @ 2003-10-23 15:53 UTC (permalink / raw)


Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Should I here for explicitly change the syntax table or is it
>> enough to set the 'comment-start' and 'comment-end' variables? Or
>> should I not confuse the variable 'comment-start' and the
>> 'comment-start sequence' syntax table entries.  If this is so for
>> what purposes do I need the variable 'comment-start' and
>> 'comment-end'. Do I need 'comment-start' and 'comment-end' maybe
>> for fill-paragraph.
>
> The comment-start and comment-end variables are used by things like
> newcomment (i.e. comment-region, auto-fill, ...).  The
> syntax-table's comment markers are used by things like forward-sexp,
> font-lock, and also newcomment.el (though it still requires the
> comment-start and comment-end things as well).
>
> The default filling code (which is separate from auto-fill) does not
> know about comments at all.  In Emacs-CVS, this has been improved a
> little, so that it now uses comment-start (as well as syntax-tables
> sometimes), but only for \n-terminated comments and it doesn't work
> right in all circumstances.
>
> I.e. you need to set both the variables and the syntax-table and if
> you want fill-paragraph to pay attention to comments, you either
> need to use Emacs-CVS or to write your own fill-paragraph-function.
> Take a look at the lisp-paragraph-function used in lisp-mode for an
> example (it is the function that got generalized and moved to
> fill.el in Emacs-CVS).
>
> This is an area that still requires a good deal of improvement, as
> you can see.

Thanks Stefan,

good answer. That's what I am looking for.

Harald

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-10-23 15:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-21 15:31 Font Lock Problems Phillip Lord
2003-10-21 16:11 ` Stefan Monnier
2003-10-21 17:08   ` Phillip Lord
2003-10-21 20:03     ` Stefan Monnier
2003-10-22 13:44       ` Phillip Lord
2003-10-22 14:10         ` Stefan Monnier
2003-10-22 15:09           ` Phillip Lord
2003-10-23 15:49       ` Phillip Lord
2003-10-23  5:18   ` Harald Maier
2003-10-23 14:21     ` Stefan Monnier
2003-10-23 15:53       ` Harald Maier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.