syntax: Move TaskwikiFoldText to autoload

Avoids useless reloading of the function. In practice, probably
harmless, but it doesn't belong there, and neither does setting
foldmethod/foldtext, and that is actually harmful (see further commits).
This commit is contained in:
Tomas Janousek 2020-12-18 16:13:00 +00:00 committed by Tomas Babej
parent 94409fd372
commit 2ab876a80a
2 changed files with 15 additions and 14 deletions

View file

@ -56,19 +56,6 @@ if !exists('g:taskwiki_disable_concealcursor')
endif
" Configure custom FoldText function
" Altered version of the VimwikiFoldText
setlocal foldmethod=syntax
setlocal foldtext=taskwiki#FoldText()
setlocal viewoptions-=options
function! TaskwikiFoldText()
let line = getline(v:foldstart)
let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '')
let short_text = substitute(main_text, '|[^=]* =', '=', '')
let short_text = substitute(short_text, '@[^=]* =', '=', '')
let short_text = substitute(short_text, ' @[A-Za-z0-9]\+', '', '')
let fold_len = v:foldend - v:foldstart + 1
let len_text = ' ['.fold_len.'] '
return short_text.len_text.repeat(' ', 500)
endfunction
setlocal foldtext=TaskwikiFoldText()

14
autoload/taskwiki.vim Normal file
View file

@ -0,0 +1,14 @@
if exists('g:loaded_taskwiki_auto') | finish | endif
let g:loaded_taskwiki_auto = 1
" Altered version of the VimwikiFoldText, strips viewport params
function! taskwiki#FoldText()
let line = getline(v:foldstart)
let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '')
let short_text = substitute(main_text, '|[^=]* =', '=', '')
let short_text = substitute(short_text, '@[^=]* =', '=', '')
let short_text = substitute(short_text, ' @[A-Za-z0-9]\+', '', '')
let fold_len = v:foldend - v:foldstart + 1
let len_text = ' ['.fold_len.'] '
return short_text.len_text.repeat(' ', 500)
endfunction