unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* regular expression help (again)
@ 2013-01-24  7:22 Luca Ferrari
  2013-01-24  9:23 ` Luca Ferrari
  2013-01-28 14:33 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Luca Ferrari @ 2013-01-24  7:22 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,
there is something I'm missing: I'm still writing my mode for a
programming language and I'd like to set a font-lock for a block of
lines that begins with /SOMETHING and ends with /* like the following:

/MASK
Field 1: _____
Field 2: _____
/*

So I defined the following regular expression to first match the whole block:

"^/\w+[ \t\n]+(.*\n)/\*$"

but it is not working, in particular testing it against
re-search-forward the \w+ works as expected but the [ \t\n]+
subsedquent part is blocking the regular expression. What am I doing
wrong?

Second question, within the same block would it be possible to set a
fot-lock for any word that is not made by underscores and to set
another font-lock for any _ found in the block? I need a little
suggestion about this (if possible).

Thanks,
Luca



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

* Re: regular expression help (again)
       [not found] <mailman.18180.1359012159.855.help-gnu-emacs@gnu.org>
@ 2013-01-24  9:01 ` Barry Margolin
  0 siblings, 0 replies; 4+ messages in thread
From: Barry Margolin @ 2013-01-24  9:01 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.18180.1359012159.855.help-gnu-emacs@gnu.org>,
 Luca Ferrari <fluca1978@infinito.it> wrote:

> Hi,
> there is something I'm missing: I'm still writing my mode for a
> programming language and I'd like to set a font-lock for a block of
> lines that begins with /SOMETHING and ends with /* like the following:
> 
> /MASK
> Field 1: _____
> Field 2: _____
> /*
> 
> So I defined the following regular expression to first match the whole block:
> 
> "^/\w+[ \t\n]+(.*\n)/\*$"
> 
> but it is not working, in particular testing it against
> re-search-forward the \w+ works as expected but the [ \t\n]+
> subsedquent part is blocking the regular expression. What am I doing
> wrong?
> 
> Second question, within the same block would it be possible to set a
> fot-lock for any word that is not made by underscores and to set
> another font-lock for any _ found in the block? I need a little
> suggestion about this (if possible).

In Lisp code you need to double the backslashes that are used for regexp 
escape sequences, since backslash is also the string escape character. 
So change it to:

"^/\\w+[ \t\n]+(.*\n)/\\*$"

When you're typing a regexp interatively in response to a command 
prompt, you don't need to do this. However, \t and \n don't have any 
special meaning in regexp syntax (they're part of string syntax), so you  
have to enter them literally with C-q TAB anc C-q C-j.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


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

* Re: regular expression help (again)
  2013-01-24  7:22 regular expression help (again) Luca Ferrari
@ 2013-01-24  9:23 ` Luca Ferrari
  2013-01-28 14:33 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Luca Ferrari @ 2013-01-24  9:23 UTC (permalink / raw)
  To: help-gnu-emacs

As far as I can see here
http://www.emacswiki.org/emacs/MultilineFontLock using multiple lines
is not enough simple to wrap it into a single regexp and appears also
to be a bad idea.

Luca

On Thu, Jan 24, 2013 at 8:22 AM, Luca Ferrari <fluca1978@infinito.it> wrote:
> Hi,
> there is something I'm missing: I'm still writing my mode for a
> programming language and I'd like to set a font-lock for a block of
> lines that begins with /SOMETHING and ends with /* like the following:
>
> /MASK
> Field 1: _____
> Field 2: _____
> /*
>
> So I defined the following regular expression to first match the whole block:
>
> "^/\w+[ \t\n]+(.*\n)/\*$"
>
> but it is not working, in particular testing it against
> re-search-forward the \w+ works as expected but the [ \t\n]+
> subsedquent part is blocking the regular expression. What am I doing
> wrong?
>
> Second question, within the same block would it be possible to set a
> fot-lock for any word that is not made by underscores and to set
> another font-lock for any _ found in the block? I need a little
> suggestion about this (if possible).
>
> Thanks,
> Luca



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

* Re: regular expression help (again)
  2013-01-24  7:22 regular expression help (again) Luca Ferrari
  2013-01-24  9:23 ` Luca Ferrari
@ 2013-01-28 14:33 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2013-01-28 14:33 UTC (permalink / raw)
  To: help-gnu-emacs

> there is something I'm missing: I'm still writing my mode for a
> programming language and I'd like to set a font-lock for a block of
> lines that begins with /SOMETHING and ends with /* like the following:

I recommend you take a look at (info "(elisp)Multiline Font Lock").

Also in some cases, you can use syntax-propertize-function instead, to
mark the whole construct as a kind of comment or string.  Then use
font-lock-syntactic-face-function to highlight the block with
a particular face (if the default string-face or comment-face is not
good enough).  And then in font-lock-keywords, you can match "word that
is not made by underscores" and use (syntax-ppss) to decide whether it's
within a /MASK block or not to decide how to highlight it.


        Stefan




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

end of thread, other threads:[~2013-01-28 14:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-24  7:22 regular expression help (again) Luca Ferrari
2013-01-24  9:23 ` Luca Ferrari
2013-01-28 14:33 ` Stefan Monnier
     [not found] <mailman.18180.1359012159.855.help-gnu-emacs@gnu.org>
2013-01-24  9:01 ` Barry Margolin

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