diff --git a/README.md b/README.md index 703bf72..ad2ae6a 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ If you need full functionality of any plugin, please use it directly with your p - [blade](https://github.com/jwalton512/vim-blade) (syntax, indent, ftplugin, ftdetect) - [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax) - [c/c++](https://github.com/vim-jp/vim-cpp) (syntax) +- [caddyfile](https://github.com/joshglendenning/vim-caddyfile) (syntax, indent, ftplugin, ftdetect) - [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin) - [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect) - [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect) diff --git a/build b/build index 030afb1..1f84e9c 100755 --- a/build +++ b/build @@ -108,6 +108,7 @@ PACKS=" blade:jwalton512/vim-blade c++11:octol/vim-cpp-enhanced-highlight c/c++:vim-jp/vim-cpp + caddyfile:joshglendenning/vim-caddyfile cjsx:mtscout6/vim-cjsx clojure:guns/vim-clojure-static coffee-script:kchmck/vim-coffee-script diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 57255ac..a80ec60 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -47,6 +47,13 @@ autocmd BufNewFile,BufRead *.blade.php set filetype=blade endif +" ftdetect/caddyfile.vim +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1 + +au BufNewFile,BufRead Caddyfile set ft=caddyfile + +endif + " ftdetect/cjsx.vim if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cjsx') == -1 diff --git a/ftplugin/caddyfile.vim b/ftplugin/caddyfile.vim new file mode 100644 index 0000000..e26f73f --- /dev/null +++ b/ftplugin/caddyfile.vim @@ -0,0 +1,28 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1 + +" Language: Caddyfile +" Author: Josh Glendenning + +if exists('b:did_ftplugin') + finish +endif +let b:did_ftplugin = 1 + +setlocal commentstring=#\ %s + +" Add NERDCommenter delimiters +let s:delimiters = {'left': '#'} +if exists('g:NERDDelimiterMap') + if !has_key(g:NERDDelimiterMap, 'caddyfile') + let g:NERDDelimiterMap.caddyfile = s:delimiters + endif +elseif exists('g:NERDCustomDelimiters') + if !has_key(g:NERDCustomDelimiters, 'caddyfile') + let g:NERDDelimiterMap.caddyfile = s:delimiters + endif +else + let g:NERDCustomDelimiters = {'caddyfile': s:delimiters} +endif +unlet s:delimiters + +endif diff --git a/indent/caddyfile.vim b/indent/caddyfile.vim new file mode 100644 index 0000000..2f38c0d --- /dev/null +++ b/indent/caddyfile.vim @@ -0,0 +1,46 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1 + +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +setlocal nolisp +setlocal autoindent +setlocal indentexpr=GetCaddyfileIndent(v:lnum) +setlocal indentkeys+=<:>,0=},0=) +" setlocal cindent + +if exists('*shiftwidth') + func s:sw() + return shiftwidth() + endfunc +else + func s:sw() + return &sw + endfunc +endif + +function! GetCaddyfileIndent(lnum) + let prevlnum = prevnonblank(a:lnum-1) + if prevlnum == 0 + return 0 + endif + + let thisl = substitute(getline(a:lnum), '#.*$', '', '') + let prevl = substitute(getline(prevlnum), '#.*$', '', '') + + let ind = indent(prevlnum) + + if prevl =~ '{\s*$' + let ind += s:sw() + endif + + if thisl =~ '^\s*}\s*$' + let ind -= s:sw() + endif + + return ind +endfunction + +endif diff --git a/syntax/caddyfile.vim b/syntax/caddyfile.vim new file mode 100644 index 0000000..17d9565 --- /dev/null +++ b/syntax/caddyfile.vim @@ -0,0 +1,33 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1 + +" Language: Caddyfile +" Author: Josh Glendenning + +if exists("b:current_syntax") + finish +endif + +syn match caddyDirective "^\s*\([a-z]\+\)" nextgroup=caddyDirectiveArgs skipwhite +syn region caddyDirectiveArgs start="" end="\({\|#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString nextgroup=caddyDirectiveBlock skipwhite +syn region caddyDirectiveBlock start="{" skip="\\}" end="}" contained contains=caddySubdirective,caddyComment + +syn match caddySubdirective "^\s*\([a-zA-Z0-9_]\+\)" contained nextgroup=caddySubdirectiveArgs skipwhite +syn region caddySubdirectiveArgs start="" end="\(#\|$\)"me=s-1 oneline contained contains=caddyPlaceholder,caddyString + +syn match caddyHost "\(https\?:\/\/\)\?\(\(\w\{1,}\.\)\(\w\{2,}\.\?\)\+\|localhost\)\(:[0-9]\{1,5}\)\?" nextgroup=caddyHostBlock skipwhite +syn region caddyHostBlock start="{" skip="\\}" end="}" contained contains=caddyDirective,caddyComment + +syn region caddyPlaceholder start="{" skip="\\}" end="}" oneline contained +syn region caddyString start='"' skip='\\\\\|\\"' end='"' oneline +syn match caddyComment "#.*$" + +hi link caddyDirective Keyword +hi link caddySubdirective Structure +hi link caddyHost Identifier +hi link caddyPlaceholder Special +hi link caddyString String +hi link caddyComment Comment + +let b:current_syntax = "caddyfile" + +endif