summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2015-12-17 10:47:00 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2015-12-17 10:47:00 +0100
commit7cbd509b6ca5522b33c8bf299468ec1be9052416 (patch)
tree129a1ab8dc1d1ecbcbb7797936a58d79fbd75851
parentf025e2778afb8bd324a7b8c6b7712346e7df0951 (diff)
downloadvim-polyglot-7cbd509b6ca5522b33c8bf299468ec1be9052416.tar.gz
vim-polyglot-7cbd509b6ca5522b33c8bf299468ec1be9052416.zip
Add nix support, closes #97
-rw-r--r--README.md1
-rwxr-xr-xbuild1
-rw-r--r--ftdetect/polyglot.vim4
-rw-r--r--ftplugin/nix.vim17
-rw-r--r--syntax/nix.vim131
5 files changed, 154 insertions, 0 deletions
diff --git a/README.md b/README.md
index 068631ee..5528f3d5 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
- [markdown](https://github.com/tpope/vim-markdown) (syntax, ftplugin, ftdetect)
- [nginx](https://github.com/nginx/nginx) (syntax, indent, ftdetect)
+- [nix](https://github.com/spwhitt/vim-nix) (syntax, ftplugin, ftdetect)
- [objc](https://github.com/b4winckler/vim-objc) (ftplugin, syntax, indent)
- [ocaml](https://github.com/jrk/vim-ocaml) (syntax, indent, ftplugin)
- [octave](https://github.com/vim-scripts/octave.vim--) (syntax)
diff --git a/build b/build
index e0c93c63..8f920c71 100755
--- a/build
+++ b/build
@@ -135,6 +135,7 @@ PACKS="
liquid:tpope/vim-liquid
markdown:tpope/vim-markdown
nginx:nginx/nginx::/contrib/vim/
+ nix:spwhitt/vim-nix
objc:b4winckler/vim-objc
ocaml:jrk/vim-ocaml
octave:vim-scripts/octave.vim--
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 9bd0f1c8..fdb540e2 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -254,6 +254,10 @@ au BufRead,BufNewFile */etc/nginx/* set ft=nginx
au BufRead,BufNewFile */usr/local/nginx/conf/* set ft=nginx
au BufRead,BufNewFile nginx.conf set ft=nginx
endif
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
+
+autocmd BufNewFile,BufRead *.nix setfiletype nix
+endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'opencl') == -1
au! BufRead,BufNewFile *.cl set filetype=opencl
diff --git a/ftplugin/nix.vim b/ftplugin/nix.vim
new file mode 100644
index 00000000..19d20977
--- /dev/null
+++ b/ftplugin/nix.vim
@@ -0,0 +1,17 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
+
+if exists("b:did_ftplugin")
+ finish
+endif
+let b:did_ftplugin=1
+
+setlocal comments=
+setlocal commentstring=#\ %s
+
+" Nixpkgs indent settings
+setlocal tabstop=2
+setlocal softtabstop=2
+setlocal shiftwidth=2
+setlocal expandtab
+
+endif
diff --git a/syntax/nix.vim b/syntax/nix.vim
new file mode 100644
index 00000000..9a275ea7
--- /dev/null
+++ b/syntax/nix.vim
@@ -0,0 +1,131 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nix') == -1
+
+"
+" Syntax file for Nix
+"
+" TODO:
+" Emphasize :
+" Deemphasize ;
+" Consistent ()
+" rec (red?)
+
+if exists("b:current_syntax")
+ finish
+endif
+
+" Operators
+syn match nixOperator "\V++"
+syn match nixOperator "\V+"
+syn match nixOperator "\V!"
+syn match nixOperator "\V=="
+syn match nixOperator "\V!="
+syn match nixOperator "\V&&"
+syn match nixOperator "\V||"
+syn match nixOperator "\V->"
+
+syn match nixOperator "\V-"
+syn match nixOperator "\V*"
+syn match nixOperator "\V/"
+syn match nixOperator "\V>"
+syn match nixOperator "\V<"
+
+" Keywords
+syn keyword nixKeyword let in or assert inherit null with rec
+syn keyword nixConditional if else then
+syn keyword nixBoolean true false
+
+" Builtins
+syn keyword nixBuiltin builtins abort add attrNames attrValues
+ \ baseNameOf compareVersions concatLists currentSystem deepSeq
+ \ derivation dirOf div elem elemAt filter filterSource fromJSON
+ \ getAttr getEnv hasAttr hashString head import intersectAttrs
+ \ isAttrs isList isFunction isString isInt isBool isNull length
+ \ lessThan listToAttrs map mul parseDrvNames pathExists readDir
+ \ readFile removeAttrs seq stringLength sub substring tail throw
+ \ toFile toJSON toPath toString toXML trace typeOf tryEval
+
+syn match nixpkgs "<nixpkgs>"
+syn match nixSpecialOper "\V@\|;\|,\|?\|..."
+
+" Attribute Lists
+"syn match nixBrace "\v[(){}\[\]]|rec\s*\{"
+syn region nixSet matchgroup=nixBraces start="{" end="}" contains=ALL
+syn region nixRecSet matchgroup=nixBraces start="rec\s*{" end="}" contains=ALL
+syn region nixList matchgroup=nixBraces start="\[" end="\]" contains=ALLBUT,nixAttr
+syn match nixAttr "\v[0-9A-Za-z\-\_]+\ze\s*\=" contained
+
+syn match nixInteger "\v<\d+>"
+
+" Functions
+syn match nixFuncArg "\v\zs\w+\ze\s*:"
+
+" TODO: Exclude ; and other illegal characters
+syn match nixPath "\v\S*/\S+|\S+/\S*"
+
+" This operator is placed after nixPath to override nixPath's highlighting
+syn match nixOperator "\V//"
+
+" Strings
+syn match nixStringIndentedEscapes +'''\|''\${\|''\\n\|''\\r\|''\\t+
+syn match nixStringEscapes +\\"\|\\\${\|\\n\|\\r\|\\t\|\\\\+
+syn region nixStringIndented
+ \ start=+''+
+ \ skip=+'''+
+ \ end=+''+
+ \ contains=nixAntiquotation,nixStringIndentedEscapes
+syn region nixString
+ \ start=+"+
+ \ skip=+\\"+
+ \ end=+"+
+ \ contains=nixAntiquotation,nixStringEscapes
+
+" If this contains nixBrace, it ignores its own closing brace and syntax gets
+" thrown way off contains=ALLBUT,nixBrace
+syn region nixAntiquotation start=+\${+ end=+}+ contains=nixAntiQuotation
+
+" Comments
+syn region nixMultiLineComment start=+/\*+ skip=+\\"+ end=+\*/+ contains=nixTodos
+syn match nixEndOfLineComment "#.*$" contains=nixTodos
+syntax keyword nixTodos TODO XXX FIXME NOTE TODOS contained
+
+" Special (Delimiter
+hi def link nixBraces Delimiter
+hi def link nixpkgs Special
+hi def link nixSpecialOper Special
+hi def link nixStringIndentedEscapes SpecialChar
+hi def link nixStringEscapes SpecialChar
+hi def link nixBuiltin Special
+hi def link nixOperator Operator
+
+" Constants
+hi def link nixBoolean Boolean
+hi def link nixInteger Number
+hi def link nixString String
+hi def link nixStringIndented String
+
+" Comments
+hi def link nixMultiLineComment Comment
+hi def link nixEndOfLineComment Comment
+
+" Identifiers
+hi def link nixConditional Conditional
+hi def link nixKeyword Keyword
+hi def link nixOperator Operator
+hi def link nixException Exception
+hi def link nixAttr Identifier
+hi def link nixFuncArg Identifier
+
+" PreProc
+hi def link nixAntiquotation Macro
+
+" Underlined (html links)
+hi def link nixPath Underlined
+
+" Error
+
+syn sync maxlines=20000
+syn sync minlines=50000
+
+let b:current_syntax = 'nix'
+
+endif