summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbuild2
-rw-r--r--ftdetect/polyglot.vim6
-rw-r--r--ftplugin/handlebars.vim22
-rw-r--r--ftplugin/mustache.vim107
-rw-r--r--syntax/handlebars.vim93
-rw-r--r--syntax/mustache.vim89
6 files changed, 200 insertions, 119 deletions
diff --git a/build b/build
index 422e7f6a..51cb4304 100755
--- a/build
+++ b/build
@@ -79,7 +79,7 @@ PACKS="
git:tpope/vim-git
go:jnwhiteh/vim-golang
haml:tpope/vim-haml
- handlebars:nono/vim-handlebars
+ handlebars:mustache/vim-mustache-handlebars
haskell:travitch/hasksyn
html5:othree/html5.vim
jade:digitaltoad/vim-jade
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 0a909262..62821fce 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -50,9 +50,6 @@ au BufReadPost *.go call s:gofiletype_post()
autocmd BufNewFile,BufRead *.haml,*.hamlbars setf haml
autocmd BufNewFile,BufRead *.sass setf sass
autocmd BufNewFile,BufRead *.scss setf scss
-if has("autocmd")
- au BufNewFile,BufRead *.{handlebars,hb,hbs,hbt}{,.erb} set ft=handlebars.html syntax=handlebars | runtime! ftplugin/handlebars.vim ftplugin/handlebars*.vim ftplugin/handlebars/*.vim
-endif
autocmd BufNewFile,BufReadPost *.jade set filetype=jade
au BufNewFile,BufRead *.js setf javascript
au BufNewFile,BufRead *.jsm setf javascript
@@ -84,6 +81,9 @@ autocmd BufRead *.html
\ if getline(1) =~ '^\(%\|<[%&].*>\)' |
\ set filetype=mason |
\ endif
+if has("autocmd")
+ au BufNewFile,BufRead *.mustache,*.handlebars,*.hbs,*.hogan,*.hulk,*.hjs set filetype=html syntax=mustache | runtime! ftplugin/mustache.vim ftplugin/mustache*.vim ftplugin/mustache/*.vim
+endif
au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/*,*/nginx/vhosts.d/*,nginx.conf if &ft == '' | setfiletype nginx | endif
autocmd BufNewFile,BufRead *.proto setfiletype proto
au BufRead,BufNewFile *.pp set filetype=puppet
diff --git a/ftplugin/handlebars.vim b/ftplugin/handlebars.vim
deleted file mode 100644
index c4a5dace..00000000
--- a/ftplugin/handlebars.vim
+++ /dev/null
@@ -1,22 +0,0 @@
-" Taken from https://github.com/juvenn/mustache.vim/blob/master/ftplugin/mustache.vim
-
-let s:cpo_save = &cpo
-set cpo&vim
-
-" Matchit support for Handlebars
-" extending HTML matchit groups
-if exists("loaded_matchit") && exists("b:match_words")
- let b:match_words = b:match_words
- \ . ',{:},[:],(:),'
- \ . '\%({{\)\@<=#\s*\%(if\|unless\)\s*.\{-}}}'
- \ . ':'
- \ . '\%({{\)\@<=\s*else\s*}}'
- \ . ':'
- \ . '\%({{\)\@<=/\s*\%(if\|unless\)\s*}},'
- \ . '\%({{\)\@<=[#^]\s*\([-0-9a-zA-Z_?!/.]\+\).\{-}}}'
- \ . ':'
- \ . '\%({{\)\@<=/\s*\1\s*}}'
-endif
-
-let &cpo = s:cpo_save
-unlet s:cpo_save
diff --git a/ftplugin/mustache.vim b/ftplugin/mustache.vim
new file mode 100644
index 00000000..38901654
--- /dev/null
+++ b/ftplugin/mustache.vim
@@ -0,0 +1,107 @@
+let s:cpo_save = &cpo
+set cpo&vim
+
+" Matchit support for Mustache & Handlebars
+" extending HTML matchit groups
+if exists("loaded_matchit") && exists("b:match_words")
+ let b:match_words = b:match_words
+ \ . ',{:},[:],(:),'
+ \ . '\%({{\)\@<=#\s*\%(if\|unless\)\s*.\{-}}}'
+ \ . ':'
+ \ . '\%({{\)\@<=\s*else\s*}}'
+ \ . ':'
+ \ . '\%({{\)\@<=/\s*\%(if\|unless\)\s*}},'
+ \ . '\%({{\)\@<=[#^]\s*\([-0-9a-zA-Z_?!/.]\+\).\{-}}}'
+ \ . ':'
+ \ . '\%({{\)\@<=/\s*\1\s*}}'
+endif
+
+if exists("g:mustache_abbreviations")
+ inoremap <buffer> {{{ {{{}}}<left><left><left>
+ inoremap <buffer> {{ {{}}<left><left>
+ inoremap <buffer> {{! {{!}}<left><left>
+ inoremap <buffer> {{< {{<}}<left><left>
+ inoremap <buffer> {{> {{>}}<left><left>
+ inoremap <buffer> {{# {{#}}<cr>{{/}}<up><left><left>
+ inoremap <buffer> {{if {{#if }}<cr>{{/if}}<up><left>
+ inoremap <buffer> {{ife {{#if }}<cr>{{else}}<cr>{{/if}}<up><up><left>
+endif
+
+
+" Section movement
+" Adapted from vim-ruby - many thanks to the maintainers of that plugin
+
+function! s:sectionmovement(pattern,flags,mode,count)
+ norm! m'
+ if a:mode ==# 'v'
+ norm! gv
+ endif
+ let i = 0
+ while i < a:count
+ let i = i + 1
+ " saving current position
+ let line = line('.')
+ let col = col('.')
+ let pos = search(a:pattern,'W'.a:flags)
+ " if there's no more matches, return to last position
+ if pos == 0
+ call cursor(line,col)
+ return
+ endif
+ endwhile
+endfunction
+
+nnoremap <silent> <buffer> [[ :<C-U>call <SID>sectionmovement('{{','b','n',v:count1)<CR>
+nnoremap <silent> <buffer> ]] :<C-U>call <SID>sectionmovement('{{','' ,'n',v:count1)<CR>
+xnoremap <silent> <buffer> [[ :<C-U>call <SID>sectionmovement('{{','b','v',v:count1)<CR>
+xnoremap <silent> <buffer> ]] :<C-U>call <SID>sectionmovement('{{','' ,'v',v:count1)<CR>
+
+
+" Operator pending mappings
+
+onoremap <silent> <buffer> ie :<C-U>call <SID>wrap_inside()<CR>
+onoremap <silent> <buffer> ae :<C-U>call <SID>wrap_around()<CR>
+xnoremap <silent> <buffer> ie :<C-U>call <SID>wrap_inside()<CR>
+xnoremap <silent> <buffer> ae :<C-U>call <SID>wrap_around()<CR>
+
+function! s:wrap_around()
+ " If the cursor is at the end of the tag element, move back
+ " so that the end tag can be detected.
+ while getline('.')[col('.')-1] ==# '}'
+ execute 'norm h'
+ endwhile
+
+ " Moves to the end of the closing tag
+ let pos = search('}}','We')
+ if pos != 0
+ if getline('.')[col('.')] ==# '}'
+ " Ending tag contains 3 closing brackets '}}}',
+ " move to the last bracket.
+ execute 'norm l'
+ endif
+
+ " select the whole tag
+ execute 'norm v%'
+ endif
+endfunction
+
+function! s:wrap_inside()
+ " If the cursor is at the end of the tag element, move back
+ " so that the end tag can be detected.
+ while getline('.')[col('.')-1] ==# '}'
+ execute 'norm h'
+ endwhile
+
+ " Moves to the end of the closing tag
+ let pos = search('}}','W')
+ if pos != 0
+ " select only inside the tag
+ execute 'norm v%loho'
+ endif
+endfunction
+
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" vim: nofoldenable
diff --git a/syntax/handlebars.vim b/syntax/handlebars.vim
deleted file mode 100644
index 706a4501..00000000
--- a/syntax/handlebars.vim
+++ /dev/null
@@ -1,93 +0,0 @@
-" Handlebars syntax
-" Language: Handlebars
-" Maintainer: Bruno Michel <brmichel@free.fr>
-" Last Change: Mar 8th, 2013
-" Version: 0.3
-" URL: https://github.com/nono/vim-handlebars
-
-if version < 600
- syntax clear
-elseif exists("b:current_syntax")
- finish
-endif
-
-if !exists("main_syntax")
- let main_syntax = 'html'
-endif
-
-ru! syntax/html.vim
-unlet b:current_syntax
-
-
-syn region hbsInside start=/{{/ end=/}}/ keepend
-
-syn keyword hbsTodo TODO FIXME XXX contained
-
-syn match hbsError /}}}\?/
-syn match hbsInsideError /{{[{#<>=!\/]\?/ contained containedin=@hbsInside
-
-syn match hbsHandlebars "{{\|}}" contained containedin=hbsInside
-syn match hbsUnescape "{{{\|}}}" contained containedin=hbsInside extend
-syn match hbsOperators "=\|\.\|/" contained containedin=hbsInside
-
-syn region hbsSection start="{{[#/]"lc=2 end=/}}/me=e-2 contained containedin=hbsInside
-syn region hbsPartial start=/{{[<>]/lc=2 end=/}}/me=e-2 contained containedin=hbsInside
-syn region hbsMarkerSet start=/{{=/lc=2 end=/=}}/me=e-2 contained containedin=hbsInside
-
-syn region hbsComment start=/{{!/rs=s+2 end=/}}/re=e-2 contained containedin=hbsInside contains=hbsTodo,Todo
-syn region hbsBlockComment start=/{{!--/rs=s+2 end=/--}}/re=e-2 contained containedin=hbsInside contains=hbsTodo,Todo extend
-syn region hbsQString start=/'/ skip=/\\'/ end=/'/ contained containedin=hbsInside
-syn region hbsDQString start=/"/ skip=/\\"/ end=/"/ contained containedin=hbsInside
-
-syn match hbsConditionals "\([/#]\(if\|unless\)\|else\)" contained containedin=hbsInside
-syn match hbsHelpers "[/#]\(with\|each\)" contained containedin=hbsInside
-
-syn cluster allHbsItems add=hbsTodo,hbsError,hbsInsideError,hbsInside,hbsHandlebars,
-\ hbsUnescape,hbsOperators,hbsSection,hbsPartial,hbsMarkerSet,
-\ hbsComment,hbsBlockComment,hbsQString,hbsDQString,hbsConditionals,
-\ hbsHelpers,hbsPartial,hbsMarkerSet,hbsComment,hbsBlockComment,
-\ hbsQString,hbsDQString,hbsConditionals,hbsHelpers
-
-syn cluster htmlAdditional add=htmlTag,htmlEndTag,htmlTagName,htmlSpecialChar
-
-syn region hbsScriptTemplate start=+<script [^>]*type *=[^>]*text/x-handlebars-template[^>]*>+
-\ end=+</script>+me=s-1 keepend contains=@htmlHbsContainer,@allHbsItems,@htmlAdditional
-
-
-" Define the default highlighting.
-" For version 5.7 and earlier: only when not done already
-" For version 5.8 and later: only when an item doesn't have highlighting yet
-if version >= 508 || !exists("did_lisp_syntax_inits")
- if version < 508
- let did_lisp_syntax_inits = 1
- command -nargs=+ HiLink hi link <args>
- else
- command -nargs=+ HiLink hi def link <args>
- endif
-
- HiLink hbsTodo Todo
-
- HiLink hbsError Error
- HiLink hbsInsideError Error
-
- HiLink hbsHandlebars Identifier
- HiLink hbsUnescape Special
- HiLink hbsOperators Operator
-
- HiLink hbsConditionals Conditional
- HiLink hbsHelpers Repeat
-
- HiLink hbsSection Number
- HiLink hbsPartial Include
- HiLink hbsMarkerSet Number
-
- HiLink hbsBlockComment Comment
- HiLink hbsComment Comment
- HiLink hbsQString String
- HiLink hbsDQString String
-
- delcommand HiLink
-endif
-
-
-let b:current_syntax = 'handlebars'
diff --git a/syntax/mustache.vim b/syntax/mustache.vim
new file mode 100644
index 00000000..cae672ca
--- /dev/null
+++ b/syntax/mustache.vim
@@ -0,0 +1,89 @@
+" Mustache & Handlebars syntax
+" Language: Mustache, Handlebars
+" Maintainer: Juvenn Woo <machese@gmail.com>
+" Screenshot: http://imgur.com/6F408
+" Version: 2
+" Last Change: Oct 26th 2013
+" Remark:
+" It lexically hilights embedded mustaches (exclusively) in html file.
+" While it was written for Ruby-based Mustache template system, it should
+" work for Google's C-based *ctemplate* as well as Erlang-based *et*. All
+" of them are, AFAIK, based on the idea of ctemplate.
+" References:
+" [Mustache](http://github.com/defunkt/mustache)
+" [Handlebars](https://github.com/wycats/handlebars.js)
+" [ctemplate](http://code.google.com/p/google-ctemplate/)
+" [ctemplate doc](http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html)
+" [et](http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html)
+" TODO: Feedback is welcomed.
+
+
+" Read the HTML syntax to start with
+if version < 600
+ so <sfile>:p:h/html.vim
+else
+ runtime! syntax/html.vim
+ unlet b:current_syntax
+endif
+
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+" Standard HiLink will not work with included syntax files
+if version < 508
+ command! -nargs=+ HtmlHiLink hi link <args>
+else
+ command! -nargs=+ HtmlHiLink hi def link <args>
+endif
+
+syntax match mustacheError '}}}\?'
+syntax match mustacheInsideError '{{[{#<>=!\/]\?'
+syntax region mustacheInside start=/{{/ end=/}}}\?/ keepend containedin=TOP,@htmlMustacheContainer
+syntax match mustacheOperators '=\|\.\|/' contained containedin=mustacheInside,@htmlMustacheContainer
+syntax region mustacheSection start='{{[#/]'lc=2 end=/}}/me=e-2 contained containedin=mustacheInside,@htmlMustacheContainer
+syntax region mustachePartial start=/{{[<>]/lc=2 end=/}}/me=e-2 contained containedin=mustacheInside,@htmlMustacheContainer
+syntax region mustacheMarkerSet start=/{{=/lc=2 end=/=}}/me=e-2 contained containedin=mustacheInside,@htmlMustacheContainer
+syntax match mustacheHandlebars '{{\|}}' contained containedin=mustacheInside,@htmlMustacheContainer
+syntax match mustacheUnescape '{{{\|}}}' contained containedin=mustacheInside,@htmlMustacheContainer
+syntax match mustacheConditionals '\([/#]\(if\|unless\)\|else\)' contained containedin=mustacheInside
+syntax match mustacheHelpers '[/#]\(with\|each\)' contained containedin=mustacheSection
+syntax region mustacheComment start=/{{!/rs=s+2 end=/}}/re=e-2 contains=Todo contained containedin=mustacheInside,@htmlMustacheContainer
+syntax region mustacheBlockComment start=/{{!--/rs=s+2 end=/--}}/re=e-2 contains=Todo
+syntax region mustacheQString start=/'/ skip=/\\'/ end=/'/ contained containedin=mustacheInside
+syntax region mustacheDQString start=/"/ skip=/\\"/ end=/"/ contained containedin=mustacheInside
+
+" Clustering
+syntax cluster htmlMustacheContainer add=htmlHead,htmlTitle,htmlString,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,htmlLink,htmlBold,htmlUnderline,htmlItalic,htmlValue
+
+
+" Hilighting
+" mustacheInside hilighted as Number, which is rarely used in html
+" you might like change it to Function or Identifier
+HtmlHiLink mustacheVariable Number
+HtmlHiLink mustacheVariableUnescape Number
+HtmlHiLink mustachePartial Number
+HtmlHiLink mustacheSection Number
+HtmlHiLink mustacheMarkerSet Number
+
+HtmlHiLink mustacheComment Comment
+HtmlHiLink mustacheBlockComment Comment
+HtmlHiLink mustacheError Error
+HtmlHiLink mustacheInsideError Error
+
+HtmlHiLink mustacheHandlebars Special
+HtmlHiLink mustacheUnescape Identifier
+HtmlHiLink mustacheOperators Operator
+HtmlHiLink mustacheConditionals Conditional
+HtmlHiLink mustacheHelpers Repeat
+HtmlHiLink mustacheQString String
+HtmlHiLink mustacheDQString String
+
+syn region mustacheScriptTemplate start=+<script [^>]*type *=[^>]*text/\(mustache\|x-handlebars-template\)[^>]*>+
+\ end=+</script>+me=s-1 keepend
+\ contains=mustacheInside,@htmlMustacheContainer,htmlTag,htmlEndTag,htmlTagName,htmlSpecialChar
+
+let b:current_syntax = "mustache"
+delcommand HtmlHiLink