Re: conditional highlight (without losing other definitions)

Lorenzo Bettini <[email protected]> Wed, 22 Feb 2012 10:42:47 +0100
Newsgroups gmane.comp.gnu.source-highlight.general
Message-ID <[email protected]>
On 02/22/2012 09:27 AM, Federico Bruni wrote:
> Il 11/02/2012 17:52, Lorenzo Bettini ha scritto:
>> On 02/02/2012 06:09 PM, Federico Bruni wrote:
>>> Hi,
>>>
>>> I'm trying to find a smarter way to highlight some strings:
>>>
>>> All the "\strings" inside \markup{ ... } should have a different colour
>>> of \strings occurences in other parts of the input.
>>> How can I achieve that in a smart way (i.e. without using a list of all
>>> the \strings which can occur inside a \markup{} block)?
>>>
>>> I want to preserve all the other highlighting definitions. Maybe
>>> state|environment is not the right tool? Because in Doc 7.9 it says:
>>>
>>> "When entering a state/environment, however, the definitions given
>>> outside the state/environment are not matched. "
>>>
>>> Let's do an example:
>>>
>>> \markup {
>>> \override #'(box-padding . 1.0) \override #'(baseline-skip . 2.7) \box
>>> \center-column {
>>> \small \line { Sheet music from \with-url
>>> #"http://www.MutopiaProject.org"
>>> \line { \teeny www. \hspace #-0.5 MutopiaProject \hspace #-0.5 \teeny
>>> .org \hspace #0.5 }
>>> }
>>> }
>>> }
>>>
>>> I want to match only: \override \box \center-column \small \line
>>> \with-url \teeny \hspace
>>>
>>> The following environment:
>>>
>>> environment markup delim '\\markup\s*\{' "}" multiline nested begin
>>> environment markup delim "{" "}" multiline nested begin
>>> markup_command = '\\[[:alpha:]-]+'
>>> end
>>> end
>>>
>>> can see the relevant block and highlight the \strings correctly, but at
>>> the same time it breaks something, in particular some elements lose
>>> their highlighting (as documentations says):
>>>
>>> 1) \markup
>>> 2) {}
>>> 3) #......
>>>
>>> So I guess that state|environment is not the solution here. Or I'm
>>> missing something?
>>
>> these elements lose highlighting since they are in a new environment as
>> you said, but you can put in the environment the definitions that you
>> want to be valid; instead of repeating them you might want to use
>> variables, for instance the definition for #... can be put in a variable
>> and have the definition outside the environment and inside...
>>
>> for instance
>>
>> vardef SCHEME_VALUE = '##(t|f)', '#{1,2}\'?[[:alnum:]\.:+-]+'
>>
>> scheme_value = $SCHEME_VALUE
>>
>> environment markup delim '\\markup\s*\{' "}" multiline nested begin
>> environment markup delim "{" "}" multiline nested begin
>> scheme_value = $SCHEME_VALUE
>> markup_command = '\\[[:alpha:]-]+'
>> end
>> end
>>
>> though, from what I understand, what you said, it should be
>>
>> environment markup delim '\\markup\s*\{' "}" multiline nested begin
>> scheme_value = $SCHEME_VALUE
>> markup_command = '\\[[:alpha:]-]+'
>> environment markup delim "{" "}" multiline nested begin
>> scheme_value = $SCHEME_VALUE
>> markup_command = '\\[[:alpha:]-]+'
>> end
>> end
>>
>
> Yes, the second is better.
> I don't like the repetition, but it's necessary.
>
> One more question: how can I create a variable of a delimiter?
> For example:
>
> string delim "\"" "\"" multiline
>
> Should I rephrase it as a regexp?
> Or there's a better way?
> I've tried the following regexp but I can't make it working multiline.
>
> #string delim "\"" "\"" multiline
> vardef STRING = '".*"'
> string = $STRING
>

If I remember correctly, you can create a variable for the single 
delimiter and then use the variable twice (in your case), for instance 
(not tested)

vardef STRING = "\""
string delim $STRING $STRING multiline

using

vardef STRING = '".*"'

will not let you use the environment mechanisms and will surely eagerly 
try to match everything till it finds another "

cheers
	Lorenzo


-- 
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net