This commit is contained in:
Adam Stankiewicz
2019-09-06 14:25:42 +02:00
parent ae18284e5a
commit 66b769328c
5 changed files with 39 additions and 16 deletions

View File

@@ -25,6 +25,7 @@ function! elixir#indent#indent(lnum)
let handlers = [ let handlers = [
\'top_of_file', \'top_of_file',
\'starts_with_string_continuation',
\'following_trailing_binary_operator', \'following_trailing_binary_operator',
\'starts_with_pipe', \'starts_with_pipe',
\'starts_with_binary_operator', \'starts_with_binary_operator',
@@ -35,9 +36,14 @@ function! elixir#indent#indent(lnum)
\] \]
for handler in handlers for handler in handlers
call s:debug('testing handler elixir#indent#handle_'.handler) call s:debug('testing handler elixir#indent#handle_'.handler)
let context = {'lnum': lnum, 'text': text, 'prev_nb_lnum': prev_nb_lnum, 'prev_nb_text': prev_nb_text} let context = {'lnum': lnum, 'text': text, 'first_nb_char_idx': match(text, '\w'), 'prev_nb_lnum': prev_nb_lnum, 'prev_nb_text': prev_nb_text}
let indent = function('elixir#indent#handle_'.handler)(context) let indent = function('elixir#indent#handle_'.handler)(context)
if indent != -1 if indent == -2
" Keep indent the same
call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned -2; returning indent of -1')
call cursor(curs_lnum, curs_col)
return -1
elseif indent != -1
call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent) call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent)
call cursor(curs_lnum, curs_col) call cursor(curs_lnum, curs_col)
return indent return indent
@@ -102,7 +108,11 @@ endfunction
" Returns 0 or 1 based on whether or not the given line number and column " Returns 0 or 1 based on whether or not the given line number and column
" number pair is a string or comment " number pair is a string or comment
function! s:is_string_or_comment(line, col) function! s:is_string_or_comment(line, col)
return synIDattr(synID(a:line, a:col, 1), "name") =~ '\%(String\|Comment\)' return s:syntax_name(a:line, a:col) =~ '\%(String\|Comment\)'
endfunction
function! s:syntax_name(line, col)
return synIDattr(synID(a:line, a:col, 1), "name")
endfunction endfunction
" Skip expression for searchpair. Returns 0 or 1 based on whether the value " Skip expression for searchpair. Returns 0 or 1 based on whether the value
@@ -158,6 +168,14 @@ function! elixir#indent#handle_top_of_file(context)
end end
endfunction endfunction
function! elixir#indent#handle_starts_with_string_continuation(context)
if s:syntax_name(a:context.lnum, a:context.first_nb_char_idx) =~ '\(String\|Comment\)$'
return -2
else
return -1
end
endfunction
function! elixir#indent#handle_follow_prev_nb(context) function! elixir#indent#handle_follow_prev_nb(context)
return s:get_base_indent(a:context.prev_nb_lnum, a:context.prev_nb_text) return s:get_base_indent(a:context.prev_nb_lnum, a:context.prev_nb_text)
endfunction endfunction

View File

@@ -1,3 +1,8 @@
" Enable jsx syntax by default
if !exists('g:jsx_ext_required')
let g:jsx_ext_required = 0
endif
" Make csv loading faster " Make csv loading faster
if !exists('g:csv_start') if !exists('g:csv_start')
let g:csv_start = 1 let g:csv_start = 1

View File

@@ -90,7 +90,7 @@ endfunction
function! s:build_path(path) abort function! s:build_path(path) abort
let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',') let path = join(map(copy(a:path), 'v:val ==# "." ? "" : v:val'), ',')
if &g:path !~# '\v^\.%(,/%(usr|emx)/include)=,,$' if &g:path !~# '\v^%(\.,)=%(/%(usr|emx)/include,)=,$'
let path = substitute(&g:path,',,$',',','') . ',' . path let path = substitute(&g:path,',,$',',','') . ',' . path
endif endif
return path return path

View File

@@ -129,15 +129,15 @@ else
syn region elixirDocTest start="^\s*\%(iex\|\.\.\.\)\%((\d*)\)\?>\s" end="^\s*$" contained syn region elixirDocTest start="^\s*\%(iex\|\.\.\.\)\%((\d*)\)\?>\s" end="^\s*$" contained
endif endif
syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]\z(/\|\"\|'\||\)" end="\z1" skip="\\\\\|\\\z1" contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\(\s\|(\)\+\)\@<=\~[Ss]\z(/\|\"\|'\||\)" end="\z1" skip="\\\\\|\\\z1" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]{" end="}" skip="\\\\\|\\}" contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\(\s\|(\)\+\)\@<=\~[Ss]{" end="}" skip="\\\\\|\\}" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]<" end=">" skip="\\\\\|\\>" contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\(\s\|(\)\+\)\@<=\~[Ss]<" end=">" skip="\\\\\|\\>" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss]\[" end="\]" skip="\\\\\|\\\]" contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\(\s\|(\)\+\)\@<=\~[Ss]\[" end="\]" skip="\\\\\|\\\]" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\s\+\)\@<=\~[Ss](" end=")" skip="\\\\\|\\)" contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocSigilDelimiter start="\%(@\w*doc\(\s\|(\)\+\)\@<=\~[Ss](" end=")" skip="\\\\\|\\)" contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirDocStringDelimiter start=+\%(@\w*doc\s\+\)\@<=\z("\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=@elixirDocStringContained keepend syn region elixirDocString matchgroup=elixirDocStringDelimiter start=+\%(@\w*doc\(\s\|(\)\+\)\@<=\z("\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=@elixirDocStringContained keepend
syn region elixirDocString matchgroup=elixirDocStringDelimiter start=+\%(@\w*doc\s\+\)\@<=\z("""\)+ end=+^\s*\z1+ contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocStringDelimiter start=+\%(@\w*doc\(\s\|(\)\+\)\@<=\z("""\)+ end=+^\s*\z1+ contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirDocSigilDelimiter start=+\%(@\w*doc\s\+\)\@<=\~[Ss]\z('''\)+ end=+^\s*\z1+ contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocSigilDelimiter start=+\%(@\w*doc\(\s\|(\)\+\)\@<=\~[Ss]\z('''\)+ end=+^\s*\z1+ contains=@elixirDocStringContained fold keepend
syn region elixirDocString matchgroup=elixirDocSigilDelimiter start=+\%(@\w*doc\s\+\)\@<=\~[Ss]\z("""\)+ end=+^\s*\z1+ contains=@elixirDocStringContained fold keepend syn region elixirDocString matchgroup=elixirDocSigilDelimiter start=+\%(@\w*doc\(\s\|(\)\+\)\@<=\~[Ss]\z("""\)+ end=+^\s*\z1+ contains=@elixirDocStringContained fold keepend
" Defines " Defines
syn match elixirDefine '\<def\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl syn match elixirDefine '\<def\>\(:\)\@!' nextgroup=elixirFunctionDeclaration skipwhite skipnl

View File

@@ -12,9 +12,9 @@ if exists("b:current_syntax")
endif endif
let b:current_syntax = "zig" let b:current_syntax = "zig"
syn keyword zigStorage const var extern packed export pub noalias inline comptime nakedcc stdcallcc volatile allowzero align linksection threadlocal syn keyword zigStorage const var extern packed export pub noalias inline noinline comptime nakedcc stdcallcc volatile allowzero align linksection threadlocal
syn keyword zigStructure struct enum union error syn keyword zigStructure struct enum union error
syn keyword zigStatement break return continue asm defer errdefer unreachable try catch async await suspend resume syn keyword zigStatement break return continue asm defer errdefer unreachable try catch async noasync await suspend resume
syn keyword zigConditional if else switch and or orelse syn keyword zigConditional if else switch and or orelse
syn keyword zigRepeat while for syn keyword zigRepeat while for
@@ -41,7 +41,7 @@ syn match zigBuiltinFn "\v\@(frameAddress|import|inlineCall|newStackCall|asyncCa
syn match zigBuiltinFn "\v\@(maxValue|memberCount|memberName|memberType)>" syn match zigBuiltinFn "\v\@(maxValue|memberCount|memberName|memberType)>"
syn match zigBuiltinFn "\v\@(memcpy|memset|minValue|mod|mulWithOverflow)>" syn match zigBuiltinFn "\v\@(memcpy|memset|minValue|mod|mulWithOverflow)>"
syn match zigBuiltinFn "\v\@(noInlineCall|bitOffsetOf|byteOffsetOf|OpaqueType|panic|ptrCast)>" syn match zigBuiltinFn "\v\@(noInlineCall|bitOffsetOf|byteOffsetOf|OpaqueType|panic|ptrCast)>"
syn match zigBuiltinFn "\v\@(ptrToInt|rem|returnAddress|setCold)>" syn match zigBuiltinFn "\v\@(ptrToInt|rem|returnAddress|setCold|Type)>"
syn match zigBuiltinFn "\v\@(setRuntimeSafety|setEvalBranchQuota|setFloatMode)>" syn match zigBuiltinFn "\v\@(setRuntimeSafety|setEvalBranchQuota|setFloatMode)>"
syn match zigBuiltinFn "\v\@(setGlobalLinkage|setGlobalSection|shlExact|This|hasDecl|hasField)>" syn match zigBuiltinFn "\v\@(setGlobalLinkage|setGlobalSection|shlExact|This|hasDecl|hasField)>"
syn match zigBuiltinFn "\v\@(shlWithOverflow|shrExact|sizeOf|sqrt|byteSwap|subWithOverflow|intCast|floatCast|intToFloat|floatToInt|boolToInt|errSetCast)>" syn match zigBuiltinFn "\v\@(shlWithOverflow|shrExact|sizeOf|sqrt|byteSwap|subWithOverflow|intCast|floatCast|intToFloat|floatToInt|boolToInt|errSetCast)>"