Re: [code] Recursive fold_all

From: Carlos Pita <carlosjosepita.att.gmail.com>
Date: Wed, 4 Mar 2015 01:15:17 -0300

Mhh, this snippet seems to do the trick:

for line = 0, buffer.line_count do
  if bit32.band(line, buffer.FOLDLEVELHEADERFLAG) and
     bit32.band(line, buffer.FOLDLEVELBASE) then
    buffer:fold_children(line, buffer.FOLDACTION_CONTRACT)
  end
end

or as a toggle:

local folds_expanded = true
keys['a*'] = function()
  local action = folds_expanded
    and buffer.FOLDACTION_CONTRACT
    or buffer.FOLDACTION_EXPAND
  folds_expanded = not folds_expanded
  for line = 0, buffer.line_count do
    if bit32.band(line, buffer.FOLDLEVELHEADERFLAG) and
       bit32.band(line, buffer.FOLDLEVELBASE) then
      buffer:fold_children(line, action)
    end
  end
end

I think it captures the idea you suggested. As I'm pretty new to both
lua and ta, any correction would be welcomed.

Cheers

--
Carlos
On Tue, Mar 3, 2015 at 6:09 PM, Mitchell <m.att.foicica.com> wrote:
> Hi Carlos,
>
>
> On Tue, 3 Mar 2015, Carlos Pita wrote:
>
>> Hi all,
>>
>> Not sure whether this is intended or not. Say I do a fold_all contract
>> in a buffer with a structure like this:
>>
>> fold_1:
>>     fold_11:
>>         ....
>>     fold_12:
>>         ....
>>
>> I get:
>>
>> +fold_1...
>>
>> which is fine. Now if I press C-* over the fold, I get:
>>
>> fold_1:
>>     fold_11:
>>         ....
>>     fold_12:
>>         ....
>>
>>
>> again (that is, all subfolds expanded). But if I manually toggle
>> fold_11, fold_12 and fold_1, in that order, using C-*, so that I get:
>>
>> +fold_1...
>>
>> as before, now pressing C-* over the fold returns:
>>
>> fold_1:
>>     +fold_11...
>>     +fold_12...
>>
>> I would like to use fold_all in order to get an outline of the buffer
>> and then selectively unfold the branch of the tree I'm interested in.
>> But fold_all seems not to fold recursively but just the top level.
>>
>> Is this intended? Am I doing something wrong?
>
>
> After looking at Scintilla's source, the behavior you describe looks
> intentional: fold_all collapse doesn't fold recursively, just all folds with
> the level of the current line. If you want to collapse every fold, you'll
> have to iterate over all lines, and then call fold_children collapse on
> top-level folds (fold headers with a fold level of 0). This may help[1], but
> I can't tell right away if it does exactly what you want.
>
> Cheers,
> Mitchell
>
> [1]:
> http://sourceforge.net/p/scintilla/scite/ci/default/tree/src/SciTEBase.cxx#l3669
> --
> 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.
>
-- 
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 03 Mar 2015 - 23:15:17 EST

This archive was generated by hypermail 2.2.0 : Wed 04 Mar 2015 - 06:46:30 EST