unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* regexp match failure
@ 2006-11-22 14:46 sandro.dentella
  2006-11-22 16:59 ` Kevin Rodgers
       [not found] ` <mailman.999.1164214909.2155.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: sandro.dentella @ 2006-11-22 14:46 UTC (permalink / raw)


Hi,

  I can't understand wht's wrong with the following regexp:

(define-derived-mode mutt-mode text-mode "Mutt"
  (make-face 'mutt-variable-face)
  (font-lock-add-keywords
   nil
   '(
    ("^\\(Date\\|Status:\\)" 1 font-lock-keyword-face)
    ("^\\(\\S+:\\)" 1 font-lock-keyword-face)
  ))
  (font-lock-mode 1)
)

The first ine works, it colors Date: and Status:, the second line
should in my opinion be just a generalized version of the first line
but it does not work. BTW, i'd have written:

  "^[-\\S]+:"

but it doens't work eather. Can anybody explain me what I'm missing?

Thanks
sandro
*:-)

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

* Re: regexp match failure
  2006-11-22 14:46 regexp match failure sandro.dentella
@ 2006-11-22 16:59 ` Kevin Rodgers
       [not found] ` <mailman.999.1164214909.2155.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2006-11-22 16:59 UTC (permalink / raw)


sandro.dentella wrote:
 >   I can't understand wht's wrong with the following regexp:
 >
 > (define-derived-mode mutt-mode text-mode "Mutt"
 >   (make-face 'mutt-variable-face)
 >   (font-lock-add-keywords
 >    nil
 >    '(
 >     ("^\\(Date\\|Status:\\)" 1 font-lock-keyword-face)

Don't you mean "^\\(Date\\|Status\\):", with either SUBEXP = 1 as-is to
leave the colon unfontified or 0 to fontify it?

 >     ("^\\(\\S+:\\)" 1 font-lock-keyword-face)
 >   ))
 >   (font-lock-mode 1)
 > )
 >
 > The first ine works, it colors Date: and Status:, the second line
 > should in my opinion be just a generalized version of the first line
 > but it does not work.

`\S' is not a valid regexp, it needs a following syntax code.  And since
you apparently want to match characters which *are* letters rather than
those which are *not*, `\s' is the appropriate construct with the `w'
code: "^\\sw+:"

Again, don't be afraid to use 0 as the font-lock-keywords SUBEXP and
avoid `\(...\)' groupings when they're not necessary.

 > BTW, i'd have written:
 >
 >   "^[-\\S]+:"
 >
 > but it doens't work eather. Can anybody explain me what I'm missing?

Inside of the `[...]' construct, backslash constructs are not special
(RTFM).  But in Emacs 22 you can do this: "^[[:alnum:]]+:"

-- 
Kevin

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

* Re: regexp match failure
       [not found] ` <mailman.999.1164214909.2155.help-gnu-emacs@gnu.org>
@ 2006-11-22 18:50   ` sandro.dentella
  0 siblings, 0 replies; 3+ messages in thread
From: sandro.dentella @ 2006-11-22 18:50 UTC (permalink / raw)



> `\S' is not a valid regexp, it needs a following syntax code.  And since
> you apparently want to match characters which *are* letters rather than
> those which are *not*, `\s' is the appropriate construct with the `w'
> code: "^\\sw+:"

ok, thanks for pointing this out, I'm just too used to perl/python
regexp that I passed over it


> Inside of the `[...]' construct, backslash constructs are not special
> (RTFM).  But in Emacs 22 you can do this: "^[[:alnum:]]+:"

I ended up using \\S-+ to catch also the '-' char.

Thanks again
sandro
*:-)

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

end of thread, other threads:[~2006-11-22 18:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-22 14:46 regexp match failure sandro.dentella
2006-11-22 16:59 ` Kevin Rodgers
     [not found] ` <mailman.999.1164214909.2155.help-gnu-emacs@gnu.org>
2006-11-22 18:50   ` sandro.dentella

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