2

Got this:

let Func = function(folding_function) "folding_function is name of function
setlocal foldexpr=call(Func(v:lnum))

This is so user can set a custom function for folding in their config file. I can't get it to work, though.

Also tried:

call(Func, v:lnum)

and

call(Func, 'v:lnum')

Code in context

" Set settings which are local to a window. In a new tab they would be reset to
" Vim defaults. So we enforce our settings here when the cursor enters a
" Vimwiki buffer.
function! s:set_windowlocal_options()
  if !&diff   " if Vim is currently in diff mode, don't interfere with its folding
    let foldmethod = vimwiki#vars#get_global('folding')
    if foldmethod =~? '^expr.*'
      setlocal foldmethod=expr
      let custom = vimwiki#vars#get_global('custom_fold_func')
      if custom
        let Func = function('VimwikiFoldLevelCustom')
        setlocal foldexpr=Func(v:lnum)
"        setlocal foldexpr=VimwikiFoldLevelCustom(v:lnum)
      else
        setlocal foldexpr=VimwikiFoldLevel(v:lnum)
      endif
      setlocal foldtext=VimwikiFoldText()
    elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*'
      setlocal foldmethod=expr
      setlocal foldexpr=VimwikiFoldListLevel(v:lnum)
      setlocal foldtext=VimwikiFoldText()
    elseif foldmethod =~? '^syntax.*'
      setlocal foldmethod=syntax
      setlocal foldtext=VimwikiFoldText()
    elseif foldmethod =~? '^custom.*'
      " do nothing
    else
      setlocal foldmethod=manual
      normal! zE
    endif
  endif

  if vimwiki#vars#get_global('conceallevel') && exists("+conceallevel")
    let &conceallevel = vimwiki#vars#get_global('conceallevel')
  endif

  if vimwiki#vars#get_global('auto_chdir')
    exe 'lcd' vimwiki#vars#get_wikilocal('path')
  endif
endfunction
StevieD
  • 1,492
  • 1
  • 16
  • 24

1 Answers1

3

The value of the foldexpr option is evaluated to get the foldlevel of a line. You don't need to add extra call to it. You can copy following code in a new file and source it to check how it works.

" vim:set foldmethod=expr noexpandtab:

function! FoldingFunction(lnum)
  return getline(v:lnum)[0]==#"\t"
endfunction
let Func = function('FoldingFunction') "FoldingFunction is name of function
setlocal foldexpr=Func(v:lnum)

finish

    fold
    fold
    fold
    fold
    fold

update

Your code doesn't work because your Func is a function local variable, change it to g:Func fix the problem.

dedowsdi
  • 6,248
  • 1
  • 18
  • 31