unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* font-lock and fontifying the few first nonempty lines in a buffer
@ 2003-06-26 20:47 Ulf Andersson
  2003-06-26 23:26 ` Kevin Rodgers
  0 siblings, 1 reply; 8+ messages in thread
From: Ulf Andersson @ 2003-06-26 20:47 UTC (permalink / raw)


Hello,

I'm sorry if this is a trivial question asked too many times,
but i couldn't find it.

I'm trying to write a major mode for Emacs, that need to fontify the few
first nonempty lines in the buffer. The mode do some other coloring in
addition to this, and that works OK. So far I have experimented with
`after-change-functions' and function matchers in `font-lock-keywords',
but all I manage to do is sending my Emacs into an infinite loop deep
down inside. I have to kill it from outside to get out of the lockup.

I am using emacs 21.2.1 in a Windows 2000 environment.

Has anyone already done somthing similar?
Is there an `obvious canonical way' to do this?
Is this downright impossible to do using `font-lock'?

Thank you all for your time and effort.

  /Ulf Andersson

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

* Re: font-lock and fontifying the few first nonempty lines in a buffer
  2003-06-26 20:47 font-lock and fontifying the few first nonempty lines in a buffer Ulf Andersson
@ 2003-06-26 23:26 ` Kevin Rodgers
  2003-06-27 10:43   ` Ulf Andersson
  0 siblings, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2003-06-26 23:26 UTC (permalink / raw)


Ulf Andersson wrote:

 > I'm trying to write a major mode for Emacs, that need to fontify the few
 > first nonempty lines in the buffer. The mode do some other coloring in
 > addition to this, and that works OK. So far I have experimented with
 > `after-change-functions' and function matchers in `font-lock-keywords',
 > but all I manage to do is sending my Emacs into an infinite loop deep
 > down inside. I have to kill it from outside to get out of the lockup.
 >
 > I am using emacs 21.2.1 in a Windows 2000 environment.
 >
 > Has anyone already done somthing similar?
 > Is there an `obvious canonical way' to do this?
 > Is this downright impossible to do using `font-lock'?

If you need a regexp that matches 3 non-empty lines at the beginning of
the buffer:

interactively 
	programatically
------------- 
	---------------
\`\(.+ C-q C-j \)\{3\}	"\\`\\(.+\n\\)\\{3\\}"

(If you need a regexp that matches the first 3 lines in the buffer,
replace + by *.)

If you need a regexp that matches the first 3 non-empty lines in the buffer:

interactively 
	programatically
------------- 
	---------------
M-< 
			(goto-char (point-min))
\(^$\)*\(.+ C-q C-q \)\{3\}	"\\(^$\\)*\\(.+\n\\)\\{3\\}"

-- 
<a href="mailto:&lt;kevin.rodgers&#64;ihs.com&gt;">Kevin Rodgers</a>

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

* Re: font-lock and fontifying the few first nonempty lines in a buffer
  2003-06-26 23:26 ` Kevin Rodgers
@ 2003-06-27 10:43   ` Ulf Andersson
  2003-06-27 12:44     ` Kai Großjohann
  2003-06-27 16:54     ` Stefan Monnier
  0 siblings, 2 replies; 8+ messages in thread
From: Ulf Andersson @ 2003-06-27 10:43 UTC (permalink / raw)


Thank's Kevin for the sugestion.

I realise that I failed to mention everything. I'm sorry.

The text header consists of the first nonempty lines in the buffer. The header
is followed by at least one empty line.

I tried to use a slightly modified version of your regexp,

    "\\`\\(\\(.+\n\\)\\{1,7\\}\\)\n"

And it does indeed color the header correctly some times, but not always.
The documentation for font-lock also says that "keywords", i.e. regexps
in the `font-lock-keywords' variable, should not span several lines, as
this is "unreliable", to use the Elisp manual's word.

This lead us back to square one, I'm afraid.

Best regards to you all.

  /Ulf Andersson

"Kevin Rodgers" <ihs_4664@yahoo.com> wrote in message
news:3EFB8125.6090600@yahoo.com...
>
> If you need a regexp that matches 3 non-empty lines at the beginning of
> the buffer:
>
> interactively
> programatically
> -------------
> ---------------
> \`\(.+ C-q C-j \)\{3\} "\\`\\(.+\n\\)\\{3\\}"
>
> (If you need a regexp that matches the first 3 lines in the buffer,
> replace + by *.)
>
> If you need a regexp that matches the first 3 non-empty lines in the buffer:
>
> interactively
> programatically
> -------------
> ---------------
> M-<
> (goto-char (point-min))
> \(^$\)*\(.+ C-q C-q \)\{3\} "\\(^$\\)*\\(.+\n\\)\\{3\\}"
>
> --
> <a href="mailto:&lt;kevin.rodgers&#64;ihs.com&gt;">Kevin Rodgers</a>
>

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

* Re: font-lock and fontifying the few first nonempty lines in a buffer
  2003-06-27 10:43   ` Ulf Andersson
@ 2003-06-27 12:44     ` Kai Großjohann
  2003-06-27 14:41       ` Ulf Andersson
  2003-06-27 16:54     ` Stefan Monnier
  1 sibling, 1 reply; 8+ messages in thread
From: Kai Großjohann @ 2003-06-27 12:44 UTC (permalink / raw)


"Ulf Andersson" <ulf.andersson7@telia.com> writes:

> And it does indeed color the header correctly some times, but not always.
> The documentation for font-lock also says that "keywords", i.e. regexps
> in the `font-lock-keywords' variable, should not span several lines, as
> this is "unreliable", to use the Elisp manual's word.

I think recent versions of font-lock have the variable
font-lock-multiline.  Does yours, too?  It might help?

-- 
~/.signature

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

* Re: font-lock and fontifying the few first nonempty lines in a buffer
  2003-06-27 12:44     ` Kai Großjohann
@ 2003-06-27 14:41       ` Ulf Andersson
  2003-06-27 15:15         ` Kai Großjohann
  0 siblings, 1 reply; 8+ messages in thread
From: Ulf Andersson @ 2003-06-27 14:41 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 787 bytes --]

That did the trick.

I guess my eyes were watering a bit when i glossed over
the relevant docs. Where can I find it, if anywhere?

Anyway, thanks a lot.

Best regards,

   /Ulf Andersson

"Kai Großjohann" <kai.grossjohann@gmx.net> wrote in message
news:84adc3sna4.fsf@lucy.is.informatik.uni-duisburg.de...
> "Ulf Andersson" <ulf.andersson7@telia.com> writes:
>
> > And it does indeed color the header correctly some times, but not always.
> > The documentation for font-lock also says that "keywords", i.e. regexps
> > in the `font-lock-keywords' variable, should not span several lines, as
> > this is "unreliable", to use the Elisp manual's word.
>
> I think recent versions of font-lock have the variable
> font-lock-multiline.  Does yours, too?  It might help?
>
> --
> ~/.signature

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

* Re: font-lock and fontifying the few first nonempty lines in a buffer
  2003-06-27 14:41       ` Ulf Andersson
@ 2003-06-27 15:15         ` Kai Großjohann
  0 siblings, 0 replies; 8+ messages in thread
From: Kai Großjohann @ 2003-06-27 15:15 UTC (permalink / raw)


"Ulf Andersson" <ulf.andersson7@telia.com> writes:

> I guess my eyes were watering a bit when i glossed over
> the relevant docs. Where can I find it, if anywhere?

M-x apropos RET searches on function and variable names, and M-x
apropos-documentation RET searches on, well, their docs.

For myself, I vaguely recall that Stefan was hacking on it, so I
kinda new what to look for, C-h v font-lock- TAB TAB quickly turned
up the right variable.
-- 
~/.signature

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

* Re: font-lock and fontifying the few first nonempty lines in a buffer
  2003-06-27 10:43   ` Ulf Andersson
  2003-06-27 12:44     ` Kai Großjohann
@ 2003-06-27 16:54     ` Stefan Monnier
  2003-06-28  1:01       ` Sandip Chitale
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2003-06-27 16:54 UTC (permalink / raw)


>     "\\`\\(\\(.+\n\\)\\{1,7\\}\\)\n"

You can also try "\\`\\(\\(.+\n\\)*?\\)\n".

> And it does indeed color the header correctly some times, but not always.
> The documentation for font-lock also says that "keywords", i.e. regexps
> in the `font-lock-keywords' variable, should not span several lines, as
> this is "unreliable", to use the Elisp manual's word.

In Emacs-21, there's a hack to try and get it to work.  It's not
100% but you might want to try it (setq font-lock-multiline t).

> This lead us back to square one, I'm afraid.

Another approach is to use font-lock-syntactic-keywords:

  (defvar foo-font-lock-syntactic-keywords
    '(("\\`." (0 "<"))
      ("\n\\(\n\\)" (1 ">"))))

This will mark the header as being a comment.  If you don't like
to color/appearance of font-lock-comment-face, you can set
`font-lock-syntactic-face-function' to something else that will
return a different face.


        Stefan

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

* Re: font-lock and fontifying the few first nonempty lines in a buffer
  2003-06-27 16:54     ` Stefan Monnier
@ 2003-06-28  1:01       ` Sandip Chitale
  0 siblings, 0 replies; 8+ messages in thread
From: Sandip Chitale @ 2003-06-28  1:01 UTC (permalink / raw)


"Stefan Monnier" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> wrote in message news:<5lisqr5ume.fsf@rum.cs.yale.edu>...
> >     "\\`\\(\\(.+\n\\)\\{1,7\\}\\)\n"
> 
> You can also try "\\`\\(\\(.+\n\\)*?\\)\n".
> 

"\\(\\`\\(?:\\(?:.+\n\\)*?\\)\n\\)"
with match data set to the whole match.

You can interactively experiment with this stuff using

M-x re-builder <RET>

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

end of thread, other threads:[~2003-06-28  1:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-26 20:47 font-lock and fontifying the few first nonempty lines in a buffer Ulf Andersson
2003-06-26 23:26 ` Kevin Rodgers
2003-06-27 10:43   ` Ulf Andersson
2003-06-27 12:44     ` Kai Großjohann
2003-06-27 14:41       ` Ulf Andersson
2003-06-27 15:15         ` Kai Großjohann
2003-06-27 16:54     ` Stefan Monnier
2003-06-28  1:01       ` Sandip Chitale

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).