Add caddyfile support, closes #195

This commit is contained in:
Adam Stankiewicz 2017-03-23 11:43:41 +01:00
parent ba75890936
commit 461de4cc21
No known key found for this signature in database
GPG Key ID: A62480DCEAC884DF
6 changed files with 116 additions and 0 deletions

View File

@ -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) - [blade](https://github.com/jwalton512/vim-blade) (syntax, indent, ftplugin, ftdetect)
- [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax) - [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax)
- [c/c++](https://github.com/vim-jp/vim-cpp) (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) - [cjsx](https://github.com/mtscout6/vim-cjsx) (ftdetect, syntax, ftplugin)
- [clojure](https://github.com/guns/vim-clojure-static) (syntax, indent, autoload, ftplugin, ftdetect) - [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) - [coffee-script](https://github.com/kchmck/vim-coffee-script) (syntax, indent, compiler, autoload, ftplugin, ftdetect)

1
build
View File

@ -108,6 +108,7 @@ PACKS="
blade:jwalton512/vim-blade blade:jwalton512/vim-blade
c++11:octol/vim-cpp-enhanced-highlight c++11:octol/vim-cpp-enhanced-highlight
c/c++:vim-jp/vim-cpp c/c++:vim-jp/vim-cpp
caddyfile:joshglendenning/vim-caddyfile
cjsx:mtscout6/vim-cjsx cjsx:mtscout6/vim-cjsx
clojure:guns/vim-clojure-static clojure:guns/vim-clojure-static
coffee-script:kchmck/vim-coffee-script coffee-script:kchmck/vim-coffee-script

View File

@ -47,6 +47,13 @@ autocmd BufNewFile,BufRead *.blade.php set filetype=blade
endif 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 " ftdetect/cjsx.vim
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cjsx') == -1 if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'cjsx') == -1

28
ftplugin/caddyfile.vim Normal file
View File

@ -0,0 +1,28 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1
" Language: Caddyfile
" Author: Josh Glendenning <josh@isobit.io>
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

46
indent/caddyfile.vim Normal file
View File

@ -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

33
syntax/caddyfile.vim Normal file
View File

@ -0,0 +1,33 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'caddyfile') == -1
" Language: Caddyfile
" Author: Josh Glendenning <josh@isobit.io>
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