Re: [code] Still wrestling with oddball folds.

From: Mitchell <m.att.foicica.com>
Date: Tue, 7 Jan 2014 13:40:08 -0500 (Eastern Standard Time)

Hi Michael,

On Tue, 7 Jan 2014, Michael Richter wrote:

> I have some code that looks like this: https://gist.github.com/8295648
>
> I want to fold from the beginning at ":-" to the end at "integer_dot(int)."
> (Ignore the line comments; the line comment folding is enough for that for
> now.)
>
> Now given the following code, the fold ends at the "." in "
> io_error(io.error)" which makes a certain amount of sense given the rules
> provided, but is obviously not what's desired:
>
> M._foldsymbols = {
> _patterns = { '%:%-', '%.', },
> [l.OPERATOR] = {
> [':-'] = 1,
> ['.'] = -1,
> },
> }
>
> Making the _pattern for closing be something like '%.%s' (and several other
> attempts along those lines) gives me folds that close only at the end of
> the file.

This does not work because your match does not have one single style, it
has two: operator and whitespace.

> What trick am I missing for making this work the desired way?

You should be using a function to determine the end of the fold point
because I don't see a good pattern rule. This seems to work for me:

   M._foldsymbols = {
     _patterns = { '%:%-', '%.', },
     [l.OPERATOR] = {
       [':-'] = 1,
       ['.'] = function(text, pos, line, s, match)
         return line:find('%.%f[%s]', s) and -1 or 0
       end,
     },
   }

It checks to see if the next character after '.' (if it exists) is a
whitespace character. Documentation on such functions is here[1].

Cheers,
Mitchell

[1]: http://foicica.com/textadept/api/lexer.html#Code.Folding

-- 
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 Tue 07 Jan 2014 - 13:40:08 EST

This archive was generated by hypermail 2.2.0 : Wed 08 Jan 2014 - 06:44:35 EST