diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2019-10-16 14:57:13 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2019-10-16 14:57:13 +0200 |
commit | 31c55b85a03d96252bba14d64911cc78a20369a1 (patch) | |
tree | af2595225bd0e6d6c4b318c0c02cb3657e6d166d /indent | |
parent | 199846c6d87c9ea60eb5f9f8f68e2d9ea4f02b2a (diff) | |
download | vim-polyglot-4.1.0.tar.gz vim-polyglot-4.1.0.zip |
Change octave provider, closes #436v4.1.0
Diffstat (limited to 'indent')
-rw-r--r-- | indent/octave.vim | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/indent/octave.vim b/indent/octave.vim new file mode 100644 index 00000000..3a6a2e78 --- /dev/null +++ b/indent/octave.vim @@ -0,0 +1,77 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'octave') == -1 + +" Vim indent file +" Language: Octave +" Maintainer: Nguyễn Gia Phong <vn.mcsinyx@gmail.com> +" Original Maintainer: Marcus Aurelius Farias <marcus.cf@bol.com.br> +" First Author: Max Ischenko <mfi@ukr.net> +" Last Change: 2019-10-11 + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +let s:beginBlock = ['for', 'parfor', 'function', 'if', 'switch', + \'try', 'unwind_protect', 'while', 'do', 'classdef', + \'enumeration', 'events', 'methods', 'properties'] +let s:midBlock = ['case', 'catch', 'else', 'elseif', 'otherwise', + \'unwind_protect_cleanup'] +let s:endBlock = ['end', 'endfor', 'endparfor', 'endfunction', 'endif', + \'end_try_catch', 'end_unwind_protect', 'endwhile', + \'endclassdef', 'endenumeration', 'endevents', + \'endproperties', 'endswitch', 'until', 'endmethods'] +let s:openBlock = s:beginBlock + s:midBlock +let s:closeBlock = s:midBlock + s:endBlock + +" To make Vim call GetOctaveIndent() when it finds a block closer +" on the current line ('else' is default and includes 'elseif'). +setlocal indentkeys+=0=end,0=until,0=case,0=catch,0=otherwise +setlocal indentkeys+=0=unwind_protect_cleanup + +" Only define the function once. +if exists("*GetOctaveIndent") + finish +endif + +function! GetOctaveIndent() + " Find a non-blank line above the current line. + let prevlnum = prevnonblank(v:lnum - 1) + + " Hit the start of the file, use zero indent. + if prevlnum == 0 + return 0 + endif + + let ind = indent(prevlnum) + let prevl = getline(prevlnum) + let l = getline(v:lnum) + + " Add a 'shiftwidth' after lines starting a block: + let openCol = match(prevl, '^\s*\%(' . join(s:openBlock, '\>\|') . '\>\)') + 1 + let hasNoEnd = prevl !~ ('\<' . join(s:endBlock, '\>\|\<') . '\>') + if openCol && hasNoEnd + let openSynID = synID(prevlnum, openCol, 1) + if synIDattr(openSynID, "name") != "octaveComment" + let ind = ind + shiftwidth() + endif + endif + + " Subtract a 'shiftwidth' on closure of blocks, + " i.e. the part that required 'indentkeys'. + let closeCol = match(l, '^\s*\%(' . join(s:closeBlock, '\>\|') . '\>\)') + 1 + if closeCol + let closeSynID = synID(v:lnum, closeCol, 1) + if synIDattr(closeSynID, "name") != "octaveComment" + let ind = ind - shiftwidth() + endif + endif + + return ind +endfunction + +setlocal indentexpr=GetOctaveIndent() +setlocal autoindent + +endif |