Commits

Ben Baker-Smith committed a775e8a

broken, but better organized

  • Participants
  • Parent commits f6ac4e9

Comments (0)

Files changed (1)

File plugin/liquidfold.vim

 function! LiquidFold()
 
-  let folder = {}
 
-
-  function! folder._setFoldWords()
+  function! a:_setFoldWords()
     " set defaults if g:liquidfold_words hasn't been defined in .vimrc
     "
     if !exists('g:liquidfold_words')
   endfunction
 
 
-  function! folder._markLiquidFolds()
-    " define fold regions using foldwords
+  function! a:_markLiquidFolds()
+    " define fold regions using a:foldwords
     "
-    let foldwords = '\('.join(split(g:liquidfold_words,","),'\|').'\)'
-    " exclude lines with both a close tag
-    let foldstart = '^.*{%\s\?\'.foldwords.'\(.*{%\s\?end'.foldwords.'.*\)\@!.*$'
-    " TODO exclude lines with an open tag
-    let foldend = '^.*{%\s\?end'.foldwords.'.*%}.*$' 
-    let foldcommand = "syn region LiquidFold start='".foldstart."' end='".foldend."' fold transparent keepend extend"
-    execute foldcommand
+    let a:foldwords = '\('.join(split(g:liquidfold_words,","),'\|').'\)'
+
+    " regexes to find start and end tags
+    let a:startmatch = '.*{%\s\?'.a:foldwords
+    let a:endmatch = '.*{%\s\?end'.a:foldwords
+
+    " exclude lines with a close tag
+    let a:foldstart = '^'.a:startmatch.'.*$'
+    " let a:foldstart = '^'.a:startmatch.'\('.a:endmatch.'\)\@!.*$'
+
+    " exclude lines with an open tag
+    let a:foldend = '^'.a:endmatch.'.*$'
+    " let a:foldend = '^\('.a:startmatch.'\)\@!'.a:endmatch.'.*$'
+
+    " create and execute final command
+    let a:foldcommand = "syn region LiquidFold start='".a:foldstart."' end='".a:foldend."' fold transparent keepend extend"
+
+echo a:foldcommand
+    execute a:foldcommand
   endfunction
 
 
-  function! folder.execute()
-    " folder's public method for initializing syntax folding
+  function! a:execute()
+    " initialize syntax folding
     "
-    call folder._setFoldWords()
-    call folder._markLiquidFolds()
+    setlocal foldmethod=syntax
+    call a:_setFoldWords()
+    call a:_markLiquidFolds()
+    syn sync fromstart
   endfunction
 
 
-  " initialize syntax folding
-  "
-  setlocal foldmethod=syntax
-  call folder.execute()
-  syn sync fromstart
-  
+  call a:execute()
+
 endfunction
 
 
 augroup ft_liquid
   au!
   au BufNewFile,BufRead *.liquid set filetype=liquid
-  au FileType liquid silent! call LiquidFold()
+  au FileType liquid call LiquidFold()
+  " au FileType liquid silent! call LiquidFold()
 augroup END