unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Multi-line font-lock parser
Date: Tue, 11 Aug 2009 07:48:15 +0200	[thread overview]
Message-ID: <87hbweucio.fsf@tux.homenetwork> (raw)
In-Reply-To: 87ocqn55z9.fsf@iki.fi

Teemu Likonen <tlikonen@iki.fi> writes:

> On 2009-08-10 23:32 (+0200), Thierry Volpiatto wrote:
>> Hi,
>> Teemu Likonen <tlikonen@iki.fi> writes:
>>
>>> I'd like to write font-lock code which highlights the first line that
>>> (1) is non-empty and (2) does not start with a "#" comment character.
>>> This requires some multi-line parsing so plain regular expressions won't
>>> suffice.
>>>
>>> I'm too stupid to understand how to implement this kind of parsing. I
>>> can write a code which finds such a line but I don't know how to
>>> integrate it to font-lock. I don't understand the (info "(elisp) Font
>>> Lock Multiline") manual either. So I'd _really_ appreciate if someone
>>> posted an example code here.
>>>
>> Did you try to use add-text-properties?
>> Something like:
>>
>> ,----
>> | (defun test-prop ()
>> |   (interactive)
>> |   (when (re-search-forward "^[a-z]+")
>> |     (beginning-of-line)
>> |     (add-text-properties (1- (point-at-bol)) (point-at-eol) '(font-lock-face font-lock-comment-face))))
>> `----
>>
>> should work.
>
> Thanks but I don't know where to start. Care to elaborate how to
> integrate that with font-lock? I mean, who is going to run this
> test-prop function?
>
Why do you want to integrate something to fontlock?
If i understand well what you want to do e.g Adding properties to the
first line that don't start with "#" and is not an empty line, the
simple code above suffice.

,----
| X ==> point
| 
| # One line starting with #.
| 
| the line we want to add text properties to.
`----

If you start to X (point) just running M-x test-prop will highlight the
line you want.

Is it what you want to do?


-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





  reply	other threads:[~2009-08-11  5:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-10 19:19 Multi-line font-lock parser Teemu Likonen
2009-08-10 21:32 ` Thierry Volpiatto
     [not found] ` <mailman.4341.1249940353.2239.help-gnu-emacs@gnu.org>
2009-08-11  4:28   ` Teemu Likonen
2009-08-11  5:48     ` Thierry Volpiatto [this message]
     [not found]     ` <mailman.4364.1249970086.2239.help-gnu-emacs@gnu.org>
2009-08-11  6:18       ` Teemu Likonen
2009-08-11  7:55         ` Thierry Volpiatto
2009-08-18  1:29 ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hbweucio.fsf@tux.homenetwork \
    --to=thierry.volpiatto@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).