Fold expression question

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fold expression question

Агибов Дмитрий
Hi all!

I want to thank developers for amazing editor. I use vim 6.2 for editing my sql files. Sql files contains stored
procedures. Code look like this

=======================
recreate procedure some_proc(input params)
  returns(output params)
as
  var argStr varChar(123);
begin
  call appendNum argStr, aInputParam1 retVal argStr;
  /* Do it for all input param */
  call logProcedureCall 'some_proc', argStr;
 ...
 /*  proc body goes here */
 ...
end^
========================

I want to fold my code like this
========================
+---- 40 lines: recreate procedure some_proc
========================

and inside this fold
========================
recreate procedure some_proc(input params)
  returns(output params)
as
  var argStr varChar(123);
begin
+---- 10 lines: call logProcedureCall
 ...
 /*  proc body goes here */
 ...
end^
========================

I use foldmethod=expr

function MyFoldExpr(line)
    let str = getline(a:line)
    if str =~ '^recreate \+procedure'
        return  '>1'
    elseif str =~ '^end^ *$'  
        return '<1'
"    elseif str =~'^ *call *append.*$' && foldlevel(a:line-1) == 1
"        return '>2'
"    elseif str =~ '^ *call *logProcedure.*$'    
"        return '<2'
    else
      return foldlevel(a:line-1)
    endif
endfun    
set foldmethod=expr
set foldexpr=MyFoldExpr(v:lnum)

Function MyFoldExpr do first thing.
If I uncomment code, fold work incorrect.

Can anybody say where I am wrong?

Thanks in advance,
Agibov Dmitry.