Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Example matcher function for font-lock-keywords?

49 views
Skip to first unread message

Alexis

unread,
Feb 25, 2015, 6:28:38 PM2/25/15
to help-gnu-emacs

Hi all,

i'm working on a prog-mode for PicoLisp. The design of PicoLisp is
such that strings are merely instances of what are called
'transient symbols'; one can do things like:

(setq "My string" 10)

such that evaluating "My string" will yield the value 10.

http://software-lab.de/doc/ref.html#transient provides more
details.

Consequently, the syntax table for PicoLisp should designate
double-quotes as marking a symbol, not a string. This, however,
means that syntactic highlighting of comments doesn't work
properly - for example, when the comment character '#' appears
inside a transient symbol, it /shouldn't/ be treated as a comment
character (and the remainder of the line following it shouldn't be
treated as a comment).

Initially i tried to handle this by using a regex in the mode's
font-lock-keywords list, but that quickly became unwieldy. So
instead, i'd like to use a matcher function in that list.

The documentation for `font-lock-keywords` says:

"MATCHER can be either the regexp to search for, or the
function name to call to make the search (called with one
argument, the limit of the search; it should return non-nil,
move point, and set `match-data' appropriately if it succeeds;
like `re-search-forward' would)."

Having played around with trying to create such a function, using
both `re-search-forward` and `string-match`, i can't seem to get
any highlighting at all, let alone correct highlighting.

Could someone please point me to an example 'in-production'
matcher function, e.g. in the Emacs ELisp code base?

Thanks in advance,


Alexis.

Dmitry Gutov

unread,
Feb 25, 2015, 6:34:45 PM2/25/15
to Alexis, help-gnu-emacs
On 02/26/2015 01:28 AM, Alexis wrote:

> Consequently, the syntax table for PicoLisp should designate
> double-quotes as marking a symbol, not a string. This, however, means
> that syntactic highlighting of comments doesn't work properly - for
> example, when the comment character '#' appears inside a transient
> symbol, it /shouldn't/ be treated as a comment character (and the
> remainder of the line following it shouldn't be treated as a comment).

In all likelihood, that means you should implement a
syntax-propertize-function, which would mark those occurrences of `#'
with a different syntax class.

For usage examples, you can take a look at js-syntax-propertize and
ruby-syntax-propertize-function.

Alexis

unread,
Feb 25, 2015, 8:48:34 PM2/25/15
to help-gnu-emacs

On 2015-02-26T10:34:28+1100, Dmitry Gutov said:

DG> In all likelihood, that means you should implement a DG>
syntax-propertize-function, which would mark those occurrences of
DG> `#' with a different syntax class.

DG> For usage examples, you can take a look at
js-syntax-propertize DG> and ruby-syntax-propertize-function.

Ah, that looks promising .... Many thanks!


Alexis.

0 new messages