help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Special hilighting for comments


From: Heime
Subject: Re: Special hilighting for comments
Date: Sun, 11 Dec 2022 07:52:53 +0000

------- Original Message -------
On Sunday, December 11th, 2022 at 7:47 AM, tomas@tuxteam.de <tomas@tuxteam.de> 
wrote:


> On Sun, Dec 11, 2022 at 07:33:19AM +0000, Heime wrote:
> 
> > ------- Original Message -------
> > On Sunday, December 11th, 2022 at 7:24 AM, tomas@tuxteam.de 
> > tomas@tuxteam.de wrote:
> > 
> > > On Sun, Dec 11, 2022 at 06:59:32AM +0000, Heime wrote:
> > > 
> > > > ------- Original Message -------
> > > > On Sunday, December 11th, 2022 at 6:54 AM, tomas@tuxteam.de 
> > > > tomas@tuxteam.de wrote:
> > > > 
> > > > > On Sun, Dec 11, 2022 at 02:37:38AM +0000, Heime wrote:
> > > > > 
> > > > > > Would you know the problem with the following regexp
> > > > > > 
> > > > > > "^;; \\[.+\\].*$"
> > > > > > 
> > > > > > It fails to match
> > > > > > 
> > > > > > ;; [something] other things
> > > > > 
> > > > > Worksforme. At least if the first semicolon is actually at the
> > > > > start of a line, that is.
> > > > > 
> > > > > Cheers
> > > > > --
> > > > > t
> > > > 
> > > > Yes it works. I am trying to use subexp in highlight-regexp.
> > > > To match "^;; \\[.+\\].*$" but highlight only the "\\[.+\\]" part.
> > > 
> > > Aha. Read again the documentation string of `hightlight-regexp'.
> > > Is there any part in there you don't understand? What about
> > > SUBEXP?
> > 
> > Right. Have done
> > 
> > (highlight-regexp "^;; \\[.+\\].*$" 'elf-face "\\[.+\\]")
> > 
> > which does not get the highlighting.
> 
> 
> [...]
> 
> Ah. There's your misunderstanding. Read the section about
> "grouping constructs" in regular expressions. The short
> version is that this argument SUBGROUP refers to the count
> number of that subexpression, starting with 1.
> 
> So you need to group the part you are interested in in
> your regexp (the subexpression) with \(...\) (don't forget
> the extra backslash for the string syntax) like so:
> 
> "^;; \\(\\[.+\\]\\).$"
> 
> Now this is the first subgroup in your regexp (actually, the
> only one). You refer to it with 1. This might work
> 
> (highlight-regexp "^;; \\(\\[.+\\]\\).$" 'elf-face 1)
> 
> Now read the section on "\( ... \)" in the chapter "Backslash
> constructs in Regular Expressions". The others are useful,
> too :)

Success.  Thank you so very much.  I now understand how it works.



reply via email to

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