auctex-devel
[Top][All Lists]
Advanced

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

Re: [AUCTeX-devel] Question reg. font-locking


From: Mosè Giordano
Subject: Re: [AUCTeX-devel] Question reg. font-locking
Date: Sun, 14 Feb 2016 01:35:27 +0100

Hi Arash,

2016-02-13 21:45 GMT+01:00 Arash Esbati <address@hidden>:
> Hi all,
>
> I have written a style for titlesec.sty (attached for reference) and I
> have a question reg. font-locking.  titlesec.sty has two macros which
> alter the number of mandatory arguments when invoked with `*':
>
> 1) 
> \titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]
>    \titleformat*{<command>}{<format>}
>
> 2) \titlerule[<height>]
>    \titlerule*[<width>]{<text>}
>
> As for \titlerule, the usual way within a style with:
>
> (font-latex-add-keywords '(("titlerule"  "*[{"))
>                          'function)
>
> does not work any more.  I rather need something like this:
>
> (font-latex-add-keywords '(("titlerule"  "[")
>                            ("titlerule*" "[{"))
>                          'function)
>
> Is there a way to make `*' part of the macro?

Not that I'm aware of, but I faced a similar problem some years ago
with "\caption*" macro provided by longtable.sty package: the standard
"\caption" macro takes an optional and a mandatory argument,
"\caption*" by longtable.sty only a mandatory one: the font-locking
specification that makes all cases work is "*[{".

In your case I'd use:

    (font-latex-add-keywords '(("titleformat" "*{[{")) 'function)
    (font-latex-add-keywords '(("titlerule" "*[{")) 'function)

They're not strictly true, but works in most cases, most importantly
when the syntax is right.  The rule of thumb is to use the minimum
number of common mandatory arguments.  There will be some cases with
"good font-locking with wrong syntax", above all with "\titleformat",
but I consider these cases less serious than "bad font-locking with
right syntax".

If you decide to go by this route, please add a comment explaining
this is a workaround (like what I did in style/longtable.el),
hopefully it'll be useful for other people reading that code.

Anyway, feel free to investigate how to make it possible to specify
font-locking rules with macros with a star in their name ;-)

Bye,
Mosè



reply via email to

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