Hi Thore,

I've never tried folding like this before, and unfortunately I don't have time
to try out this 'optimized' version, but it may work faster for you (I've just
replaced the regex matches with stridx and rearranged the code flow):

  set foldexpr=GetFoldLevel()

  function! GetFoldLevel()
    let line_text = getline(v:lnum)

    let left_idx = (stridx(line_text, '{') >= 0)
    let right_idx = (stridx(line_text, '}') >= 0)

    if left_idx
      if ! right_idx
        return 'a1'
      endif
    elseif right_idx
      return 's1'
    endif

    return '='
  endfunction


HTH,
Peter



--- "Thore B. Karlsen" <[EMAIL PROTECTED]> wrote:

>
> I use foldmethod=expr with the following foldexpr:
>
> set foldexpr=GetFoldLevel(v:lnum)
>
> function! GetFoldLevel(line)
>    let line_text = getline(a:line)
>    if (line_text =~ '\%({.*}\)\|\%(}.*{\)')
>       return '='
>    elseif (line_text =~ '{')
>       return "a1"
>    elseif (line_text =~ '}')
>       return "s1"
>    endif
>    return '='
> endfunction
>
> What I want to do is similar to foldmethod=marker with foldmarker={,},
> but if I use foldmethod=marker vim gets confused by lines that contain
> both { and } like these:
>
>   string s = String.Format("{0}", v);
>   string[] sa = new string[] { "a", "b" };
>
> GetFoldLevel() above fixes that, in that it keeps the same fold level
> if both { and } are found on the same line, but it is horribly slow.
> Even in pretty small files (1k lines long), it can take several
> seconds for characters to appear when I'm typing in insert mode.
>
> Is there a way to optimize the above, or an alternative way of doing
> this? It is very frustrating to have my folds get out of whack with
> foldmethod=marker, but the slowness of this foldexpr is unbearable.
>
> --
> Be seeing you.
>
>


Send instant messages to your online friends http://au.messenger.yahoo.com 

Reply via email to