summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2017-03-23 11:43:41 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2017-03-23 11:43:41 +0100
commit461de4cc216cac858ccc4f2dd99644e6ea43589d (patch)
tree4ea2373904a594c143b029d279218f9650b6833c
parentba758909360bbd037cea06fd4e4eec8da7bf8751 (diff)
downloadvim-polyglot-461de4cc216cac858ccc4f2dd99644e6ea43589d.tar.gz
vim-polyglot-461de4cc216cac858ccc4f2dd99644e6ea43589d.zip
Add caddyfile support, closes #195
-rw-r--r--README.md1
-rwxr-xr-xbuild1
-rw-r--r--ftdetect/polyglot.vim7
-rw-r--r--ftplugin/caddyfile.vim28
-rw-r--r--indent/caddyfile.vim46
-rw-r--r--syntax/caddyfile.vim33
6 files changed, 116 insertions, 0 deletions
diff --git a/README.md b/README.md
index 703bf729..ad2ae6ac 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 030afb14..1f84e9c2 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 57255ac5..a80ec608 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 00000000..e26f73f0
--- /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 <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
diff --git a/indent/caddyfile.vim b/indent/caddyfile.vim
new file mode 100644
index 00000000..2f38c0db
--- /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 00000000..17d95658
--- /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 <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