[prev in list] [next in list] [prev in thread] [next in thread]
List: vim
Subject: Re: Automatically updating foldcolumn based on open folds
From: Paul Jolly <paul () myitcv ! org ! uk>
Date: 2004-02-27 0:00:09
Message-ID: 403E8889.9020409 () myitcv ! org ! uk
[Download RAW message or body]
Paul Jolly wrote:
[...]
>>> function! FindFoldcolumn()
>>> let pos = 1
>>> let max_depth = 0
>>> while pos < line("$")
The above line is obviously very inefficient (line("$") probably called
in each loop unless Vim has some massively clever optimisation of line
calls). Replace with:
let file_size = line("$")
while pos < file_size
>>> let res = foldclosedend(pos)
>>>
>>> " are we inside an open fold?
>>> if res >= 0
>>> " no. move just beyond the end of
>>> " the fold
>>> let pos = res + 1
>>> else
>>> " yes
>>> let current_depth = foldlevel(pos)
>>>
>>> " are we in the deepest fold yet?
>>> if max_depth < current_depth
>>> " yes
>>> let max_depth = current_depth
>>> endif
>>> let pos = pos + 1
>>> endif
>>> endwhile
>>> return max_depth
>>> endfunction
[...]
Paul
--
Department of Computing, Imperial College London
http://myitcv.org.uk/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic