Commits

Ben Baker-Smith  committed b16f53c

exclude single-line statements

  • Participants
  • Parent commits a775e8a

Comments (0)

Files changed (1)

File plugin/liquidfold.vim

 function! LiquidFold()
 
-
+  " set defaults if g:liquidfold_words hasn't been defined in .vimrc
+  "
   function! a:_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
 
 
-  function! a:_markLiquidFolds()
-    " define fold regions using a:foldwords
-    "
+  " define fold regions
+  "
+  function! a:_markFolds()
+    " format foldwords into regex 'or' block
     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.'.*$'
+    " exclude lines with both an open and close tag
+    let a:foldstart = '^'.a:startmatch.'\('.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
 
 
+  " initialize syntax folding
+  "
   function! a:execute()
-    " initialize syntax folding
-    "
     setlocal foldmethod=syntax
     call a:_setFoldWords()
-    call a:_markLiquidFolds()
+    call a:_markFolds()
     syn sync fromstart
   endfunction
 
 augroup ft_liquid
   au!
   au BufNewFile,BufRead *.liquid set filetype=liquid
-  au FileType liquid call LiquidFold()
-  " au FileType liquid silent! call LiquidFold()
+  au FileType liquid silent! call LiquidFold()
 augroup END