Loading ...
Sorry, an error occurred while loading the content.

Re: Automatically updating foldcolumn based on open folds

Expand Messages
  • Paul Jolly
    Paul Jolly wrote: [...] ... The above line is obviously very inefficient (line( $ ) probably called in each loop unless Vim has some massively clever
    Message 1 of 6 , Feb 26, 2004
    • 0 Attachment
      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/
    Your message has been successfully submitted and would be delivered to recipients shortly.