Commits

Ben Baker-Smith committed 95b3e18

refactor

  • Participants
  • Parent commits 29415a9

Comments (0)

Files changed (1)

File plugin/liquidfold.vim

-" set defaults if g:liquidfold_words hasn't been defined in .vimrc
-"
-if !exists('g:liquidfold_words')
-  let g:liquidfold_words = "comment,raw,if,case,for,tablerow,block"
-endif
+function! LiquidFold()
 
+  let folder = {}
 
-" define fold regions using foldwords
-"
-function! MarkLiquidFolds()
-  let foldwords = '\('.join(split(g:liquidfold_words,","),'\|').'\)'
-  let foldstart = '^.*{%\s\?'.foldwords.'.*%}.*$'
-  let foldend = '^.*{%\s\?end'.foldwords.'.*%}.*$' 
-  let foldcommand = "syn region LiquidFold start='".foldstart."' end='".foldend."' fold transparent keepend extend"
-  execute foldcommand
-endfunction
 
+  function! folder._setFoldWords()
+    " set defaults if g:liquidfold_words hasn't been defined in .vimrc
+    "
+    if !exists('g:liquidfold_words')
+      let g:liquidfold_words = "comment,raw,if,case,for,tablerow,block"
+    endif
+  endfunction
 
-" initialize syntax folding
-"
-function! InitLiquidFolds()
+
+  function! folder._markLiquidFolds()
+    " define fold regions using foldwords
+    "
+    let foldwords = '\('.join(split(g:liquidfold_words,","),'\|').'\)'
+    let foldstart = '^.*{%\s\?'.foldwords.'.*%}.*$'
+    let foldend = '^.*{%\s\?end'.foldwords.'.*%}.*$' 
+    let foldcommand = "syn region LiquidFold start='".foldstart."' end='".foldend."' fold transparent keepend extend"
+    execute foldcommand
+  endfunction
+
+
+  function! folder.execute()
+    " folder's public method for initializing syntax folding
+    "
+    call folder._setFoldWords()
+    call folder._markLiquidFolds()
+  endfunction
+
+
+  " initialize syntax folding
+  "
   setlocal foldmethod=syntax
-  call MarkLiquidFolds()
+  call folder.execute()
   syn sync fromstart
+  
 endfunction
 
 
-" avoid conflicts with other liquid autocommands
+" avoid conflicts with other autocommands and automatically fold liquid files
 "
 augroup ft_liquid
   au!
   au BufNewFile,BufRead *.liquid set filetype=liquid
-  au FileType liquid silent! call InitLiquidFolds()
+  au FileType liquid silent! call LiquidFold()
 augroup END