Commits

Ben Baker-Smith committed 5612cd1

refactoring to use autoload and improve scoping; script no longer modifies g:liquidfold_words

  • Participants
  • Parent commits 54e79f0

Comments (0)

Files changed (1)

File autoload/liquidfold.vim

+" set defaults if g:liquidfold_words hasn't been defined in .vimrc
+"
+function! s:_getFoldWords()
+  if exists('g:liquidfold_words')
+    let words = g:liquidfold_words
+  else
+    let words = "comment,raw,if,case,for,tablerow,block"
+  endif
+  return words
+endfunction
+
+
+" define fold regions
+"
+function! s:_markFolds()
+  " format fold words into regex 'or' block
+  let words = s:_getFoldWords()
+  let foldwords = '\('.join(split(words,","),'\|').'\)'
+
+  " regexes to find start and end tags
+  let startmatch = '.*{%\s\?'.foldwords
+  let endmatch = '.*{%\s\?end'.foldwords
+
+  " exclude lines with both an open and close tag
+  let foldstart = '^'.startmatch.'\('.endmatch.'\)\@!.*$'
+  let foldend = '^\('.startmatch.'\)\@!'.endmatch.'.*$'
+
+  " create and execute command string
+  let foldcommand = "syn region LiquidFold start='".foldstart."' end='".foldend."' fold transparent keepend extend"
+  execute foldcommand
+endfunction
+
+
+" initialize syntax folding
+"
+function! liquidfold#Init()
+  setlocal foldmethod=syntax
+  call s:_markFolds()
+  syn sync fromstart
+endfunction