emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Explicitly numbered subgroups in regular expressions


From: Juri Linkov
Subject: Re: Explicitly numbered subgroups in regular expressions
Date: Tue, 12 Jun 2007 23:56:28 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

>> The feature seems useful, but how does this affect the numbering of
>> groups that don't specify a number?  That has to be done right, then
>> documented in the two manuals.
>
> Done.  Except I have only documented it in the Elisp manual: I believe it's
> only useful for Lisp programming, not for interactive regexp use.

This feature makes regexps more readable and less error-prone, so I think
it would be useful for interactive usage like in query-replace-regexp.

Now since it was installed, I noticed that in Emacs Lisp files numbers
in regexps don't get highlighted like grouping constructs in
font-lock-regexp-grouping-construct face.  The patch below adds highlighting
for them.  It also uses this new feature in the same regexp ;)

Index: lisp/font-lock.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/font-lock.el,v
retrieving revision 1.317
diff -c -r1.317 font-lock.el
*** lisp/font-lock.el   21 Apr 2007 14:30:25 -0000      1.317
--- lisp/font-lock.el   12 Jun 2007 20:55:41 -0000
***************
*** 2279,2285 ****
              ;; that do not occur in strings.  The associated regexp matches 
one
              ;; of `\\\\' `\\(' `\\(?:' `\\|' `\\)'.  `\\\\' has been included 
to
              ;; avoid highlighting, for example, `\\(' in `\\\\('.
!             (while (re-search-forward 
"\\(\\\\\\\\\\)\\(?:\\(\\\\\\\\\\)\\|\\((\\(?:\\?:\\)?\\|[|)]\\)\\)" bound t)
                (unless (match-beginning 2)
                  (let ((face (get-text-property (1- (point)) 'face)))
                    (when (or (and (listp face)
--- 2279,2285 ----
              ;; that do not occur in strings.  The associated regexp matches 
one
              ;; of `\\\\' `\\(' `\\(?:' `\\|' `\\)'.  `\\\\' has been included 
to
              ;; avoid highlighting, for example, `\\(' in `\\\\('.
!             (while (re-search-forward 
"\\(?1:\\\\\\\\\\)\\(?:\\(?2:\\\\\\\\\\)\\|\\(?3:(\\(?:\\?[0-9]*:\\)?\\|[|)]\\)\\)"
 bound t)
                (unless (match-beginning 2)
                  (let ((face (get-text-property (1- (point)) 'face)))
                    (when (or (and (listp face)

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]