mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Update
This commit is contained in:
@@ -23,11 +23,14 @@ if exists("*GetJuliaIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:skipPatterns = '\<julia\%(Comprehension\%(For\|If\)\|RangeKeyword\|Comment\%([LM]\|Delim\)\|\%([bsv]\|ip\|big\|MIME\|Shell\|Printf\|Doc\)\=String\|RegEx\|SymbolS\?\)\>'
|
||||
let s:skipPatternsBasic = '\<julia\%(Comment\%([LM]\|Delim\)\)\>'
|
||||
let s:skipPatterns = '\<julia\%(Comprehension\%(For\|If\)\|RangeKeyword\|Comment\%([LM]\|Delim\)\|\%([bs]\|Shell\|Printf\|Doc\)\?String\|StringPrefixed\|DocStringM\(Raw\)\?\|RegEx\|SymbolS\?\|Macro\|Dotted\)\>'
|
||||
|
||||
function JuliaMatch(lnum, str, regex, st, ...)
|
||||
let s = a:st
|
||||
let e = a:0 > 0 ? a:1 : -1
|
||||
let basic_skip = a:0 > 1 ? a:2 : 'all'
|
||||
let skip = basic_skip ==# 'basic' ? s:skipPatternsBasic : s:skipPatterns
|
||||
while 1
|
||||
let f = match(a:str, '\C' . a:regex, s)
|
||||
if e >= 0 && f >= e
|
||||
@@ -35,7 +38,8 @@ function JuliaMatch(lnum, str, regex, st, ...)
|
||||
endif
|
||||
if f >= 0
|
||||
let attr = synIDattr(synID(a:lnum,f+1,1),"name")
|
||||
if attr =~# s:skipPatterns
|
||||
let attrT = synIDattr(synID(a:lnum,f+1,0),"name")
|
||||
if attr =~# skip || attrT =~# skip
|
||||
let s = f+1
|
||||
continue
|
||||
endif
|
||||
@@ -53,8 +57,8 @@ function GetJuliaNestingStruct(lnum, ...)
|
||||
let blocks_stack = []
|
||||
let num_closed_blocks = 0
|
||||
while 1
|
||||
let fb = JuliaMatch(a:lnum, line, '[@.]\@<!\<\%(if\|else\%(if\)\?\|while\|for\|try\|catch\|finally\|\%(staged\)\?function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|let\|\%(bare\)\?module\|quote\|do\)\>', s, e)
|
||||
let fe = JuliaMatch(a:lnum, line, '[@.]\@<!\<end\>', s, e)
|
||||
let fb = JuliaMatch(a:lnum, line, '\<\%(if\|else\%(if\)\?\|while\|for\|try\|catch\|finally\|\%(staged\)\?function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|let\|\%(bare\)\?module\|quote\|do\)\>', s, e)
|
||||
let fe = JuliaMatch(a:lnum, line, '\<end\>', s, e)
|
||||
|
||||
if fb < 0 && fe < 0
|
||||
" No blocks found
|
||||
@@ -66,13 +70,13 @@ function GetJuliaNestingStruct(lnum, ...)
|
||||
" Note: some keywords (elseif,else,catch,finally) are both
|
||||
" closing blocks and opening new ones
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<if\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<if\>', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
call add(blocks_stack, 'if')
|
||||
continue
|
||||
endif
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<elseif\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<elseif\>', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
if len(blocks_stack) > 0 && blocks_stack[-1] == 'if'
|
||||
@@ -83,7 +87,7 @@ function GetJuliaNestingStruct(lnum, ...)
|
||||
endif
|
||||
continue
|
||||
endif
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<else\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<else\>', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
if len(blocks_stack) > 0 && blocks_stack[-1] =~# '\<\%(else\)\=if\>'
|
||||
@@ -95,13 +99,13 @@ function GetJuliaNestingStruct(lnum, ...)
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<try\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<try\>', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
call add(blocks_stack, 'try')
|
||||
continue
|
||||
endif
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<catch\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<catch\>', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
if len(blocks_stack) > 0 && blocks_stack[-1] == 'try'
|
||||
@@ -112,7 +116,7 @@ function GetJuliaNestingStruct(lnum, ...)
|
||||
endif
|
||||
continue
|
||||
endif
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<finally\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<finally\>', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
if len(blocks_stack) > 0 && (blocks_stack[-1] == 'try' || blocks_stack[-1] == 'catch')
|
||||
@@ -124,7 +128,7 @@ function GetJuliaNestingStruct(lnum, ...)
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<\%(bare\)\?module\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<\%(bare\)\?module\>', s)
|
||||
if i >= 0 && i == fb
|
||||
let s = i+1
|
||||
if i == 0
|
||||
@@ -135,7 +139,7 @@ function GetJuliaNestingStruct(lnum, ...)
|
||||
continue
|
||||
endif
|
||||
|
||||
let i = JuliaMatch(a:lnum, line, '[@.]\@<!\<\%(while\|for\|\%(staged\)\?function\|macro\|begin\|\%(mutable\s\+\)\?struct\|\%(abstract\|primitive\)\s\+type\|immutable\|let\|quote\|do\)\>', s)
|
||||
let i = JuliaMatch(a:lnum, line, '\<\%(while\|for\|function\|macro\|begin\|\%(mutable\s\+\)\?struct\|\%(abstract\|primitive\)\s\+type\|let\|quote\|do\)\>', s)
|
||||
if i >= 0 && i == fb
|
||||
if match(line, '\C\<\%(mutable\|abstract\|primitive\)', i) != -1
|
||||
let s = i+11
|
||||
@@ -278,7 +282,7 @@ endfunction
|
||||
|
||||
function IsInDocString(lnum)
|
||||
let stack = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
|
||||
call filter(stack, 'v:val =~# "\\<juliaDocString\\(Delim\\|M\\)\\?\\>"')
|
||||
call filter(stack, 'v:val =~# "\\<juliaDocString\\(Delim\\|M\\\(Raw\\)\\?\\)\\?\\>"')
|
||||
return len(stack) > 0
|
||||
endfunction
|
||||
|
||||
@@ -449,7 +453,7 @@ function GetJuliaIndent()
|
||||
" reference point
|
||||
let cind = JuliaMatch(lnum, prevline, ':', indent(lnum), lim)
|
||||
if cind >= 0
|
||||
let nonwhiteind = JuliaMatch(lnum, prevline, '\S', cind+1)
|
||||
let nonwhiteind = JuliaMatch(lnum, prevline, '\S', cind+1, -1, 'basic')
|
||||
if nonwhiteind >= 0
|
||||
" return match(prevline, '\S', cind+1) " a bit overkill...
|
||||
return cind + 2
|
||||
@@ -460,7 +464,7 @@ function GetJuliaIndent()
|
||||
let iind = JuliaMatch(lnum, prevline, '\<import\|using\|export\>', indent(lnum), lim)
|
||||
if iind >= 0
|
||||
" assuming whitespace after using... so no `using(XYZ)` please!
|
||||
let nonwhiteind = JuliaMatch(lnum, prevline, '\S', iind+6)
|
||||
let nonwhiteind = JuliaMatch(lnum, prevline, '\S', iind+6, -1, 'basic')
|
||||
if nonwhiteind >= 0
|
||||
return match(prevline, '\S', iind+6)
|
||||
endif
|
||||
|
||||
@@ -24,8 +24,8 @@ let s:comment_rx = '^\s*#'
|
||||
let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
|
||||
let s:continued_rule_rx = '^[^#:]*:\{1,2}\%([^=:]\|$\)'
|
||||
let s:continuation_rx = '\\$'
|
||||
let s:assignment_rx = '^\s*\h\w*\s*[+?]\==\s*\zs.*\\$'
|
||||
let s:folded_assignment_rx = '^\s*\h\w*\s*[+?]\=='
|
||||
let s:assignment_rx = '^\s*\h\w*\s*[+:?]\==\s*\zs.*\\$'
|
||||
let s:folded_assignment_rx = '^\s*\h\w*\s*[+:?]\=='
|
||||
" TODO: This needs to be a lot more restrictive in what it matches.
|
||||
let s:just_inserted_rule_rx = '^\s*[^#:]\+:\{1,2}$'
|
||||
let s:conditional_directive_rx = '^ *\%(ifn\=\%(eq\|def\)\|else\)\>'
|
||||
|
||||
@@ -6,6 +6,7 @@ endif
|
||||
" Language: Meson
|
||||
" License: VIM License
|
||||
" Maintainer: Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
|
||||
" Liam Beguin <liambeguin@gmail.com>
|
||||
" Original Authors: David Bustos <bustos@caltech.edu>
|
||||
" Bram Moolenaar <Bram@vim.org>
|
||||
" Last Change: 2015 Feb 23
|
||||
@@ -28,7 +29,7 @@ if exists("*GetMesonIndent")
|
||||
finish
|
||||
endif
|
||||
let s:keepcpo= &cpo
|
||||
setlocal cpo&vim
|
||||
set cpo&vim
|
||||
|
||||
" Come here when loading the script the first time.
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ endif
|
||||
" Language: Rmd
|
||||
" Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
|
||||
" Homepage: https://github.com/jalvesaq/R-Vim-runtime
|
||||
" Last Change: Sun Aug 19, 2018 09:14PM
|
||||
" Last Change: Sun Mar 28, 2021 08:05PM
|
||||
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
@@ -17,7 +17,7 @@ runtime indent/r.vim
|
||||
let s:RIndent = function(substitute(&indentexpr, "()", "", ""))
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal indentkeys=0{,0},:,!^F,o,O,e
|
||||
setlocal indentkeys=0{,0},<:>,!^F,o,O,e
|
||||
setlocal indentexpr=GetRmdIndent()
|
||||
|
||||
if exists("*GetRmdIndent")
|
||||
@@ -27,6 +27,21 @@ endif
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Simple Python indentation algorithm
|
||||
function s:GetPyIndent()
|
||||
let plnum = prevnonblank(v:lnum - 1)
|
||||
let pline = getline(plnum)
|
||||
let cline = getline(v:lnum)
|
||||
if pline =~ '^s```\s*{\s*python '
|
||||
return 0
|
||||
elseif pline =~ ':$'
|
||||
return indent(plnum) + &shiftwidth
|
||||
elseif cline =~ 'else:$'
|
||||
return indent(plnum) - &shiftwidth
|
||||
endif
|
||||
return indent(plnum)
|
||||
endfunction
|
||||
|
||||
function s:GetMdIndent()
|
||||
let pline = getline(v:lnum - 1)
|
||||
let cline = getline(v:lnum)
|
||||
@@ -41,13 +56,14 @@ function s:GetMdIndent()
|
||||
endfunction
|
||||
|
||||
function s:GetYamlIndent()
|
||||
let pline = getline(v:lnum - 1)
|
||||
let plnum = prevnonblank(v:lnum - 1)
|
||||
let pline = getline(plnum)
|
||||
if pline =~ ':\s*$'
|
||||
return indent(v:lnum) + shiftwidth()
|
||||
return indent(plnum) + shiftwidth()
|
||||
elseif pline =~ '^\s*- '
|
||||
return indent(v:lnum) + 2
|
||||
endif
|
||||
return indent(prevnonblank(v:lnum - 1))
|
||||
return indent(plnum)
|
||||
endfunction
|
||||
|
||||
function GetRmdIndent()
|
||||
@@ -56,9 +72,11 @@ function GetRmdIndent()
|
||||
endif
|
||||
if search('^[ \t]*```{r', "bncW") > search('^[ \t]*```$', "bncW")
|
||||
return s:RIndent()
|
||||
elseif v:lnum > 1 && search('^---$', "bnW") == 1 &&
|
||||
\ (search('^---$', "nW") > v:lnum || search('^...$', "nW") > v:lnum)
|
||||
elseif v:lnum > 1 && (search('^---$', "bnW") == 1 &&
|
||||
\ (search('^---$', "nW") > v:lnum || search('^\.\.\.$', "nW") > v:lnum))
|
||||
return s:GetYamlIndent()
|
||||
elseif search('^[ \t]*```{python', "bncW") > search('^[ \t]*```$', "bncW")
|
||||
return s:GetPyIndent()
|
||||
else
|
||||
return s:GetMdIndent()
|
||||
endif
|
||||
|
||||
@@ -44,7 +44,7 @@ function GetRSTIndent()
|
||||
let psnum = s:get_paragraph_start()
|
||||
if psnum != 0
|
||||
if getline(psnum) =~ s:note_pattern
|
||||
let ind = 3
|
||||
let ind = max([3, ind])
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user