mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0823d2068 | ||
|
|
b4a6290b42 | ||
|
|
c324a086b2 |
@@ -66,7 +66,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)
|
||||
- [nim](https://github.com/zah/nim.vim) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
|
||||
- [nim](https://github.com/zah/nim.vim) (syntax, compiler, 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)
|
||||
@@ -96,7 +96,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
|
||||
- [tmux](https://github.com/tejr/vim-tmux) (syntax, ftdetect)
|
||||
- [tomdoc](https://github.com/wellbredgrapefruit/tomdoc.vim) (syntax)
|
||||
- [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin, ftdetect)
|
||||
- [twig](https://github.com/beyondwords/vim-twig) (syntax, ftplugin, ftdetect)
|
||||
- [twig](https://github.com/evidens/vim-twig) (syntax, ftplugin)
|
||||
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [vala](https://github.com/tkztmk/vim-vala) (syntax, indent, ftdetect)
|
||||
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
|
||||
|
||||
232
autoload/nim.vim
232
autoload/nim.vim
@@ -1,232 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
|
||||
|
||||
let g:nim_log = []
|
||||
let s:plugin_path = escape(expand('<sfile>:p:h'), ' \')
|
||||
|
||||
if !exists("g:nim_caas_enabled")
|
||||
let g:nim_caas_enabled = 0
|
||||
endif
|
||||
|
||||
if !executable('nim')
|
||||
echoerr "the Nim compiler must be in your system's PATH"
|
||||
endif
|
||||
|
||||
exe 'pyfile ' . fnameescape(s:plugin_path) . '/nim_vim.py'
|
||||
|
||||
fun! nim#init()
|
||||
let cmd = printf("nim --dump.format:json --verbosity:0 dump %s", s:CurrentNimFile())
|
||||
let raw_dumpdata = system(cmd)
|
||||
if !v:shell_error
|
||||
let dumpdata = eval(substitute(raw_dumpdata, "\n", "", "g"))
|
||||
|
||||
let b:nim_project_root = dumpdata['project_path']
|
||||
let b:nim_defined_symbols = dumpdata['defined_symbols']
|
||||
let b:nim_caas_enabled = g:nim_caas_enabled || index(dumpdata['defined_symbols'], 'forcecaas') != -1
|
||||
|
||||
for path in dumpdata['lib_paths']
|
||||
if finddir(path) == path
|
||||
let &l:path = path . "," . &l:path
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
let b:nim_caas_enabled = 0
|
||||
endif
|
||||
endf
|
||||
|
||||
fun! s:UpdateNimLog()
|
||||
setlocal buftype=nofile
|
||||
setlocal bufhidden=hide
|
||||
setlocal noswapfile
|
||||
|
||||
for entry in g:nim_log
|
||||
call append(line('$'), split(entry, "\n"))
|
||||
endfor
|
||||
|
||||
let g:nim_log = []
|
||||
|
||||
match Search /^nim\ .*/
|
||||
endf
|
||||
|
||||
augroup NimVim
|
||||
au!
|
||||
au BufEnter log://nim call s:UpdateNimLog()
|
||||
" au QuitPre * :py nimTerminateAll()
|
||||
au VimLeavePre * :py nimTerminateAll()
|
||||
augroup END
|
||||
|
||||
command! NimLog :e log://nim
|
||||
|
||||
command! NimTerminateService
|
||||
\ :exe printf("py nimTerminateService('%s')", b:nim_project_root)
|
||||
|
||||
command! NimRestartService
|
||||
\ :exe printf("py nimRestartService('%s')", b:nim_project_root)
|
||||
|
||||
fun! s:CurrentNimFile()
|
||||
let save_cur = getpos('.')
|
||||
call cursor(0, 0, 0)
|
||||
|
||||
let PATTERN = "\\v^\\#\\s*included from \\zs.*\\ze"
|
||||
let l = search(PATTERN, "n")
|
||||
|
||||
if l != 0
|
||||
let f = matchstr(getline(l), PATTERN)
|
||||
let l:to_check = expand('%:h') . "/" . f
|
||||
else
|
||||
let l:to_check = expand("%")
|
||||
endif
|
||||
|
||||
call setpos('.', save_cur)
|
||||
return l:to_check
|
||||
endf
|
||||
|
||||
let g:nim_symbol_types = {
|
||||
\ 'skParam': 'v',
|
||||
\ 'skVar': 'v',
|
||||
\ 'skLet': 'v',
|
||||
\ 'skTemp': 'v',
|
||||
\ 'skForVar': 'v',
|
||||
\ 'skConst': 'v',
|
||||
\ 'skResult': 'v',
|
||||
\ 'skGenericParam': 't',
|
||||
\ 'skType': 't',
|
||||
\ 'skField': 'm',
|
||||
\ 'skProc': 'f',
|
||||
\ 'skMethod': 'f',
|
||||
\ 'skIterator': 'f',
|
||||
\ 'skConverter': 'f',
|
||||
\ 'skMacro': 'f',
|
||||
\ 'skTemplate': 'f',
|
||||
\ 'skEnumField': 'v',
|
||||
\ }
|
||||
|
||||
fun! NimExec(op)
|
||||
let isDirty = getbufvar(bufnr('%'), "&modified")
|
||||
if isDirty
|
||||
let tmp = tempname() . bufname("%") . "_dirty.nim"
|
||||
silent! exe ":w " . tmp
|
||||
|
||||
let cmd = printf("idetools %s --trackDirty:\"%s,%s,%d,%d\" \"%s\"",
|
||||
\ a:op, tmp, expand('%:p'), line('.'), col('.')-1, s:CurrentNimFile())
|
||||
else
|
||||
let cmd = printf("idetools %s --track:\"%s,%d,%d\" \"%s\"",
|
||||
\ a:op, expand('%:p'), line('.'), col('.')-1, s:CurrentNimFile())
|
||||
endif
|
||||
|
||||
if b:nim_caas_enabled
|
||||
exe printf("py nimExecCmd('%s', '%s', False)", b:nim_project_root, cmd)
|
||||
let output = l:py_res
|
||||
else
|
||||
let output = system("nim " . cmd)
|
||||
endif
|
||||
|
||||
call add(g:nim_log, "nim " . cmd . "\n" . output)
|
||||
return output
|
||||
endf
|
||||
|
||||
fun! NimExecAsync(op, Handler)
|
||||
let result = NimExec(a:op)
|
||||
call a:Handler(result)
|
||||
endf
|
||||
|
||||
fun! NimComplete(findstart, base)
|
||||
if b:nim_caas_enabled == 0
|
||||
return -1
|
||||
endif
|
||||
|
||||
if a:findstart
|
||||
if synIDattr(synIDtrans(synID(line("."),col("."),1)), "name") == 'Comment'
|
||||
return -1
|
||||
endif
|
||||
return col('.')
|
||||
else
|
||||
let result = []
|
||||
let sugOut = NimExec("--suggest")
|
||||
for line in split(sugOut, '\n')
|
||||
let lineData = split(line, '\t')
|
||||
if len(lineData) > 0 && lineData[0] == "sug"
|
||||
let kind = get(g:nim_symbol_types, lineData[1], '')
|
||||
let c = { 'word': lineData[2], 'kind': kind, 'menu': lineData[3], 'dup': 1 }
|
||||
call add(result, c)
|
||||
endif
|
||||
endfor
|
||||
return result
|
||||
endif
|
||||
endf
|
||||
|
||||
if !exists("g:neocomplcache_omni_patterns")
|
||||
let g:neocomplcache_omni_patterns = {}
|
||||
endif
|
||||
|
||||
let g:neocomplcache_omni_patterns['nim'] = '[^. *\t]\.\w*'
|
||||
let g:nim_completion_callbacks = {}
|
||||
|
||||
fun! NimAsyncCmdComplete(cmd, output)
|
||||
call add(g:nim_log, a:output)
|
||||
echom g:nim_completion_callbacks
|
||||
if has_key(g:nim_completion_callbacks, a:cmd)
|
||||
let Callback = get(g:nim_completion_callbacks, a:cmd)
|
||||
call Callback(a:output)
|
||||
" remove(g:nim_completion_callbacks, a:cmd)
|
||||
else
|
||||
echom "ERROR, Unknown Command: " . a:cmd
|
||||
endif
|
||||
return 1
|
||||
endf
|
||||
|
||||
fun! GotoDefinition_nim_ready(def_output)
|
||||
if v:shell_error
|
||||
echo "nim was unable to locate the definition. exit code: " . v:shell_error
|
||||
" echoerr a:def_output
|
||||
return 0
|
||||
endif
|
||||
|
||||
let rawDef = matchstr(a:def_output, 'def\t\([^\n]*\)')
|
||||
if rawDef == ""
|
||||
echo "the current cursor position does not match any definitions"
|
||||
return 0
|
||||
endif
|
||||
|
||||
let defBits = split(rawDef, '\t')
|
||||
let file = defBits[4]
|
||||
let line = defBits[5]
|
||||
exe printf("e +%d %s", line, file)
|
||||
return 1
|
||||
endf
|
||||
|
||||
fun! GotoDefinition_nim()
|
||||
call NimExecAsync("--def", function("GotoDefinition_nim_ready"))
|
||||
endf
|
||||
|
||||
fun! FindReferences_nim()
|
||||
setloclist()
|
||||
endf
|
||||
|
||||
" Syntastic syntax checking
|
||||
fun! SyntaxCheckers_nim_nim_GetLocList()
|
||||
let makeprg = 'nim check --hints:off --listfullpaths ' . s:CurrentNimFile()
|
||||
let errorformat = &errorformat
|
||||
|
||||
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
|
||||
endf
|
||||
|
||||
function! SyntaxCheckers_nim_nim_IsAvailable()
|
||||
return executable("nim")
|
||||
endfunction
|
||||
|
||||
if exists("g:SyntasticRegistry")
|
||||
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
||||
\ 'filetype': 'nim',
|
||||
\ 'name': 'nim'})
|
||||
endif
|
||||
|
||||
if !exists("g:quickrun_config")
|
||||
let g:quickrun_config = {}
|
||||
endif
|
||||
|
||||
if !exists("g:quickrun_config.nim")
|
||||
let g:quickrun_config.nim = { "exec": "nim c --run --verbosity:0 %S" }
|
||||
endif
|
||||
|
||||
|
||||
endif
|
||||
4
build
4
build
@@ -137,7 +137,7 @@ PACKS="
|
||||
liquid:tpope/vim-liquid
|
||||
markdown:tpope/vim-markdown
|
||||
nginx:nginx/nginx::/contrib/vim/
|
||||
nim:zah/nim.vim
|
||||
nim:zah/nim.vim:_BASIC
|
||||
nix:spwhitt/vim-nix
|
||||
objc:b4winckler/vim-objc
|
||||
ocaml:jrk/vim-ocaml
|
||||
@@ -167,7 +167,7 @@ PACKS="
|
||||
tmux:tejr/vim-tmux
|
||||
tomdoc:wellbredgrapefruit/tomdoc.vim
|
||||
toml:cespare/vim-toml
|
||||
twig:beyondwords/vim-twig
|
||||
twig:evidens/vim-twig
|
||||
typescript:leafgarland/typescript-vim
|
||||
vala:tkztmk/vim-vala
|
||||
vbnet:vim-scripts/vbnet.vim
|
||||
|
||||
@@ -450,11 +450,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'toml') == -1
|
||||
autocmd BufNewFile,BufRead *.toml set filetype=toml
|
||||
autocmd BufNewFile,BufRead Cargo.lock set filetype=toml
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'twig') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.twig set filetype=twig
|
||||
autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig
|
||||
endif
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'typescript') == -1
|
||||
|
||||
autocmd BufNewFile,BufRead *.ts,*.tsx setlocal filetype=typescript
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'nim') == -1
|
||||
|
||||
if exists("b:nim_loaded")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:nim_loaded = 1
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
call nim#init()
|
||||
|
||||
setlocal formatoptions-=t formatoptions+=croql
|
||||
setlocal comments=:##,:#
|
||||
setlocal commentstring=#\ %s
|
||||
setlocal omnifunc=NimComplete
|
||||
setlocal suffixesadd=.nim
|
||||
setlocal expandtab "Make sure that only spaces are used
|
||||
|
||||
compiler nim
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
|
||||
endif
|
||||
@@ -8,14 +8,15 @@ if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! ftplugin/html.vim ftplugin/html*.vim ftplugin/html/*.vim
|
||||
unlet! b:did_ftplugin
|
||||
|
||||
setlocal comments=s:{#,ex:#}
|
||||
setlocal formatoptions+=tcqln
|
||||
" setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+
|
||||
|
||||
let b:undo_ftplugin .= "|setl cms< com< fo<"
|
||||
if exists("b:did_ftplugin")
|
||||
let b:undo_ftplugin .= "|setlocal comments< formatoptions<"
|
||||
else
|
||||
let b:undo_ftplugin = "setlocal comments< formatoptions<"
|
||||
endif
|
||||
|
||||
" vim:set sw=2:
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ function! GetErubyIndent(...)
|
||||
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
||||
let ind = ind + sw
|
||||
endif
|
||||
if line !~# '^\s*<%' && line =~# '%>\s*$'
|
||||
if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>'
|
||||
let ind = ind - sw
|
||||
endif
|
||||
if cline =~# '^\s*[-=]\=%>\s*$'
|
||||
|
||||
@@ -20,14 +20,20 @@ unlet! b:current_syntax
|
||||
if !exists('g:markdown_fenced_languages')
|
||||
let g:markdown_fenced_languages = []
|
||||
endif
|
||||
let s:done_include = {}
|
||||
for s:type in map(copy(g:markdown_fenced_languages),'matchstr(v:val,"[^=]*$")')
|
||||
if has_key(s:done_include, matchstr(s:type,'[^.]*'))
|
||||
continue
|
||||
endif
|
||||
if s:type =~ '\.'
|
||||
let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*')
|
||||
endif
|
||||
exe 'syn include @markdownHighlight'.substitute(s:type,'\.','','g').' syntax/'.matchstr(s:type,'[^.]*').'.vim'
|
||||
unlet! b:current_syntax
|
||||
let s:done_include[matchstr(s:type,'[^.]*')] = 1
|
||||
endfor
|
||||
unlet! s:type
|
||||
unlet! s:done_include
|
||||
|
||||
syn sync minlines=10
|
||||
syn case ignore
|
||||
@@ -93,10 +99,16 @@ syn match markdownFootnote "\[^[^\]]\+\]"
|
||||
syn match markdownFootnoteDefinition "^\[^[^\]]\+\]:"
|
||||
|
||||
if main_syntax ==# 'markdown'
|
||||
let s:done_include = {}
|
||||
for s:type in g:markdown_fenced_languages
|
||||
if has_key(s:done_include, matchstr(s:type,'[^.]*'))
|
||||
continue
|
||||
endif
|
||||
exe 'syn region markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*```*\s*'.matchstr(s:type,'[^=]*').'\>.*$" end="^\s*```*\ze\s*$" keepend contains=@markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g')
|
||||
let s:done_include[matchstr(s:type,'[^.]*')] = 1
|
||||
endfor
|
||||
unlet! s:type
|
||||
unlet! s:done_include
|
||||
endif
|
||||
|
||||
syn match markdownEscape "\\[][\\`*_{}()<>#+.!-]"
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'twig') == -1
|
||||
|
||||
" Vim syntax file
|
||||
" Language: Twig template
|
||||
" Maintainer: Gabriel Gosselin <gabrielNOSPAM@evidens.ca>
|
||||
" Last Change: 2011 July 27
|
||||
" Version: 1.0
|
||||
" Language: Twig template
|
||||
" Maintainer: Gabriel Gosselin <gabrielNOSPAM@evidens.ca>
|
||||
" Last Change: 2014 December 15
|
||||
" Version: 1.1
|
||||
"
|
||||
" Based Jinja syntax by: Armin Ronacher <armin.ronacher@active-4.com>
|
||||
"
|
||||
" With modifications by Benji Fisher, Ph.D.
|
||||
"
|
||||
" Known Bugs:
|
||||
" because of odd limitations dicts and the modulo operator
|
||||
" appear wrong in the template.
|
||||
@@ -16,11 +17,21 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'twig') == -1
|
||||
"
|
||||
" 2008 May 9: Added support for Jinja2 changes (new keyword rules)
|
||||
" 2011 July 27: Changed all references of jinja tp twig
|
||||
" 2014 December 4: Do not assume that the base filetype is HTML.
|
||||
|
||||
if exists('b:main_syntax')
|
||||
finish
|
||||
endif
|
||||
if exists('b:current_syntax')
|
||||
let b:main_syntax = b:current_syntax
|
||||
else
|
||||
let b:main_syntax = 'twig'
|
||||
endif
|
||||
|
||||
syntax case match
|
||||
|
||||
" Jinja template built-in tags and parameters (without filter, macro, is and raw, they
|
||||
" have special threatment)
|
||||
" Twig template built-in tags and parameters (without filter, macro, is and
|
||||
" raw, they have special treatment)
|
||||
syn keyword twigStatement containedin=twigVarBlock,twigTagBlock,twigNested contained and if else in not or recursive as import
|
||||
|
||||
syn keyword twigStatement containedin=twigVarBlock,twigTagBlock,twigNested contained is filter skipwhite nextgroup=twigFilter
|
||||
@@ -37,7 +48,7 @@ syn match twigFilter contained skipwhite /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
syn match twigFunction contained skipwhite /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
syn match twigBlockName contained skipwhite /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
|
||||
" Jinja template constants
|
||||
" Twig template constants
|
||||
syn region twigString containedin=twigVarBlock,twigTagBlock,twigNested contained start=/"/ skip=/\\"/ end=/"/
|
||||
syn region twigString containedin=twigVarBlock,twigTagBlock,twigNested contained start=/'/ skip=/\\'/ end=/'/
|
||||
syn match twigNumber containedin=twigVarBlock,twigTagBlock,twigNested contained /[0-9]\+\(\.[0-9]\+\)\?/
|
||||
@@ -48,7 +59,7 @@ syn match twigPunctuation containedin=twigVarBlock,twigTagBlock,twigNested conta
|
||||
syn match twigOperator containedin=twigVarBlock,twigTagBlock,twigNested contained /\./ nextgroup=twigAttribute
|
||||
syn match twigAttribute contained /[a-zA-Z_][a-zA-Z0-9_]*/
|
||||
|
||||
" Jinja template tag and variable blocks
|
||||
" Twig template tag and variable blocks
|
||||
syn region twigNested matchgroup=twigOperator start="(" end=")" transparent display containedin=twigVarBlock,twigTagBlock,twigNested contained
|
||||
syn region twigNested matchgroup=twigOperator start="\[" end="\]" transparent display containedin=twigVarBlock,twigTagBlock,twigNested contained
|
||||
syn region twigNested matchgroup=twigOperator start="{" end="}" transparent display containedin=twigVarBlock,twigTagBlock,twigNested contained
|
||||
@@ -56,10 +67,10 @@ syn region twigTagBlock matchgroup=twigTagDelim start=/{%-\?/ end=/-\?%}/ skipwh
|
||||
|
||||
syn region twigVarBlock matchgroup=twigVarDelim start=/{{-\?/ end=/-\?}}/ containedin=ALLBUT,twigTagBlock,twigVarBlock,twigRaw,twigString,twigNested,twigComment
|
||||
|
||||
" Jinja template 'raw' tag
|
||||
" Twig template 'raw' tag
|
||||
syn region twigRaw matchgroup=twigRawDelim start="{%\s*raw\s*%}" end="{%\s*endraw\s*%}" containedin=ALLBUT,twigTagBlock,twigVarBlock,twigString,twigComment
|
||||
|
||||
" Jinja comments
|
||||
" Twig comments
|
||||
syn region twigComment matchgroup=twigCommentDelim start="{#" end="#}" containedin=ALLBUT,twigTagBlock,twigVarBlock,twigString
|
||||
|
||||
" Block start keywords. A bit tricker. We only highlight at the start of a
|
||||
@@ -107,7 +118,4 @@ if version >= 508 || !exists("did_twig_syn_inits")
|
||||
delcommand HiLink
|
||||
endif
|
||||
|
||||
let b:current_syntax = "twig"
|
||||
|
||||
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user