mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Add nix support, closes #97
This commit is contained in:
@@ -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)
|
||||
|
||||
1
build
1
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--
|
||||
|
||||
@@ -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
|
||||
|
||||
17
ftplugin/nix.vim
Normal file
17
ftplugin/nix.vim
Normal file
@@ -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
|
||||
131
syntax/nix.vim
Normal file
131
syntax/nix.vim
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user