unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* fontifying of user defined variables
@ 2006-09-12 10:00 dieter
  2006-09-13 21:54 ` Dieter Wilhelm
       [not found] ` <mailman.6912.1158195722.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: dieter @ 2006-09-12 10:00 UTC (permalink / raw)


Hi

I'd like to highlight user specified variables in a major mode for a simple macro language (Ansys parametric design language or APDL). 

All number variables are specified with the following assignment:

VARIABEL=VALUE

I'd like to fontify in a certain face any variable VARIABLE which was defined in such a way and appears after the definition anywhere in the code.

Could you please outline the method or point to a lisp file where such a "dynamic" highlighting is accomplished.

--
  Dieter

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

* Re: fontifying of user defined variables
  2006-09-12 10:00 fontifying of user defined variables dieter
@ 2006-09-13 21:54 ` Dieter Wilhelm
       [not found] ` <mailman.6912.1158195722.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Dieter Wilhelm @ 2006-09-13 21:54 UTC (permalink / raw)


dieter@duenenhof-wilhelm.de writes:

>
> I'd like to highlight user specified variables in a major mode for a
> simple macro language (Ansys parametric design language or APDL).
> All number variables are specified with the following assignment:
>
> VARIABEL=VALUE
>
> I'd like to fontify in a certain face any variable VARIABLE which
> was defined in such a way and appears after the definition anywhere
> in the code.  Could you please outline the method or point to a lisp
> file where such a "dynamic" highlighting is accomplished.

Well, had a look at C/C++ mode and not even there I could find above
functionality.  So I guess it's too awkward to program this otherwise,
I think, very helpful stuff.

The only idea I've so far is for a function which parses now and then
the buffer and adds or removes font lock keywords to the
font-lock-keywords variable according to the current variable
definitions in the buffer.

                Dieter

-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

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

* Re: fontifying of user defined variables
       [not found] ` <mailman.6912.1158195722.9609.help-gnu-emacs@gnu.org>
@ 2006-09-14 14:47   ` rgb
  2006-09-16  7:42     ` Dieter Wilhelm
  0 siblings, 1 reply; 4+ messages in thread
From: rgb @ 2006-09-14 14:47 UTC (permalink / raw)


Dieter Wilhelm wrote:
> dieter@duenenhof-wilhelm.de writes:
>
> >
> > I'd like to highlight user specified variables in a major mode for a
> > simple macro language (Ansys parametric design language or APDL).
> > All number variables are specified with the following assignment:
> >
> > VARIABEL=VALUE
> >
> > I'd like to fontify in a certain face any variable VARIABLE which
> > was defined in such a way and appears after the definition anywhere
> > in the code.  Could you please outline the method or point to a lisp
> > file where such a "dynamic" highlighting is accomplished.
>
> Well, had a look at C/C++ mode and not even there I could find above
> functionality.  So I guess it's too awkward to program this otherwise,
> I think, very helpful stuff.
>
> The only idea I've so far is for a function which parses now and then
> the buffer and adds or removes font lock keywords to the
> font-lock-keywords variable according to the current variable
> definitions in the buffer.

That could turn out to be very inefficient and therefore
very slow if you work on large files.  Otherwise, except for
one (possibly major) point it seems a workable idea.

The potential problem is that variables will be highlighted no matter
where they appear.  Even before the point they are defined.

The only way around that problem (that I know of) is to supply a
function rather than a regexp to font-lock-keywords.  The
function would then be responsible for identifying variable names
to be highlighted.

You can always supply a function anywhere a regexp is
allowed in the font-lock setup variables.  The function must take
1 argument (search-limit).  font-lock expects the function  to
act like re-search-forward in that it must return t or nil if it finds
a match and it must use set-match-data to mark the location
of the match and it must leave point somewhere after the match.
The big difference, of course, is that your function
must know what to look for (because it's only argument is
search-limit) whereas re-search-forward gets a regexp argument
that tells it what to look for.

Your periodic scanning function would still maintain a list of
variable names to highlight but wouldn't update font-lock-keywords.
Instead, it saves them to some other variable of your choosing in
a list that includes a marker to where the definition was detected.

The function you provide to font-lock-keywords would then
find keywords (variable names) only if they occured after the
point where they were defined.  Your function (like
re-search-forward) is expected to operate on the region between
point and search-limit.  So if you don't find a keyword in that range
you return nil.  If you find one you set match-data and return t.
When you return t you can expect that your function will be called
again by font-lock to look for more keywords.  point will be
whereever you left it when you were called last so you need to be
sure to leave point after any keyword you find or you'll loop finding
it over and over.

Good luck

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

* Re: fontifying of user defined variables
  2006-09-14 14:47   ` rgb
@ 2006-09-16  7:42     ` Dieter Wilhelm
  0 siblings, 0 replies; 4+ messages in thread
From: Dieter Wilhelm @ 2006-09-16  7:42 UTC (permalink / raw)
  Cc: help-gnu-emacs

"rgb" <rbielaws@i1.net> writes:

> Dieter Wilhelm wrote:
>> dieter@duenenhof-wilhelm.de writes:
>> >
>> > I'd like to highlight user specified variables in a major mode for a
>> > simple macro language (Ansys parametric design language or APDL).
>> > All number variables are specified with the following assignment:
>> >
>> > VARIABEL=VALUE
...
>> >
> The potential problem is that variables will be highlighted no matter
> where they appear.  Even before the point they are defined.

Right, since Ansys allows variables names which are identical to some
command options, for example.
>
> The only way around that problem (that I know of) is to supply a
> function rather than a regexp to font-lock-keywords.  The
...
> must know what to look for (because it's only argument is
> search-limit) whereas re-search-forward gets a regexp argument
> that tells it what to look for.

I see, thanks for the introduction to the enhanced font-lock
capability.
>
> Your periodic scanning function would still maintain a list of
> variable names to highlight but wouldn't update font-lock-keywords.
> Instead, it saves them to some other variable of your choosing in
> a list that includes a marker to where the definition was detected.
>

I could use some timer, I've never tried but I guess there is a timer
functionality in Emacs which allows such a scanning operation only
when Emacs is idling.

> The function you provide to font-lock-keywords would then
> find keywords (variable names) only if they occured after the
...
> it over and over.
>
> Good luck

Thanks for your friendly advice.

-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

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

end of thread, other threads:[~2006-09-16  7:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-12 10:00 fontifying of user defined variables dieter
2006-09-13 21:54 ` Dieter Wilhelm
     [not found] ` <mailman.6912.1158195722.9609.help-gnu-emacs@gnu.org>
2006-09-14 14:47   ` rgb
2006-09-16  7:42     ` Dieter Wilhelm

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