Re: [code] [textadept] Customize lexer

From: Mitchell <m.att.foicica.com>
Date: Thu, 9 Jan 2014 14:27:43 -0500 (Eastern Standard Time)

Hi Robert,

On Thu, 9 Jan 2014, Robert Gieseke wrote:

> Hi,
>
> is is possible to change a lexer's rules and tokenstyles after it has
> been loaded without having a separate copy in my userhome? Similar to
> post_init letting me have customisation while keeping up with upstream
> changes.

Changing token styles is easy: just use the existing `buffer.property`
interface. For example:

     -- Change the style of Lua longstrings on the fly.
     buffer.property['style.longstring'] = '%(style.regex)'

Changing rules on the fly is only possible in the latest alpha. You cannot
do this in 7.0 and 7.1. First, use `lexer.load()` to get the lexer you
want to change. Even if the lexer was already loaded, the function returns
that lexer instead of loading it again. For example:

     local lua = lexer.load('lua')

In order to change token rules, simply alter the lexers `_RULES` table as
you see fit. (The django and makefile lexers do this.) If you want to
alter rule order, use the undocumented `_RULEORDER` table (look in
`lexers/lexer.lua` for reference).

I hope that helps.

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Thu 09 Jan 2014 - 14:27:43 EST

This archive was generated by hypermail 2.2.0 : Fri 10 Jan 2014 - 06:28:01 EST