Added git submodule for vim-endwise

This commit is contained in:
Andrew R. M 2017-04-06 10:35:03 -04:00
parent 2ba478a674
commit 7d4784c58f
5 changed files with 4 additions and 239 deletions

3
.gitmodules vendored
View File

@ -19,3 +19,6 @@
[submodule "vim/.vim/bundle/pathogen"] [submodule "vim/.vim/bundle/pathogen"]
path = vim/.vim/bundle/pathogen path = vim/.vim/bundle/pathogen
url = https://github.com/tpope/vim-pathogen url = https://github.com/tpope/vim-pathogen
[submodule "vim/.vim/bundle/endwise"]
path = vim/.vim/bundle/endwise
url = https://github.com/tpope/vim-endwise

@ -0,0 +1 @@
Subproject commit d5655263af8b3611a2bcb907a9963831a88d154b

View File

@ -1 +0,0 @@
See the [contribution guidelines for pathogen.vim](https://github.com/tpope/vim-pathogen/blob/master/CONTRIBUTING.markdown).

View File

@ -1,42 +0,0 @@
# endwise.vim
This is a simple plugin that helps to end certain structures
automatically. In Ruby, this means adding `end` after `if`, `do`, `def`
and several other keywords. In Vimscript, this amounts to appropriately
adding `endfunction`, `endif`, etc. There's also Bourne shell, VB
(don't ask), C/C++ preprocessor, and Lua support.
A primary guiding principle in designing this plugin was that an
erroneous insertion is never acceptable. The behavior is only triggered
once pressing enter on the end of the line. When this happens, endwise
searches for a matching end structure and only adds one if none is
found.
While the goal was to make it customizable, this turned out to be a tall
order. Every language has vastly different requirements. Nonetheless,
for those bold enough to attempt it, you can follow the model of the
autocmds in the plugin to set the three magic variables governing
endwise's behavior.
## Installation
If you don't have a preferred installation method, I recommend
installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and
then simply copy and paste:
cd ~/.vim/bundle
git clone git://github.com/tpope/vim-endwise.git
## Self-Promotion
Like endwise.vim? Follow the repository on
[GitHub](https://github.com/tpope/vim-endwise) and vote for it on
[vim.org](http://www.vim.org/scripts/script.php?script_id=2386). And if
you're feeling especially charitable, follow [tpope](http://tpo.pe/) on
[Twitter](http://twitter.com/tpope) and
[GitHub](https://github.com/tpope).
## License
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
See `:help license`.

View File

@ -1,196 +0,0 @@
" Location: plugin/endwise.vim
" Author: Tim Pope <http://tpo.pe/>
" Version: 1.2
" License: Same as Vim itself. See :help license
" GetLatestVimScripts: 2386 1 :AutoInstall: endwise.vim
if exists("g:loaded_endwise") || &cp
finish
endif
let g:loaded_endwise = 1
augroup endwise " {{{1
autocmd!
autocmd FileType lua
\ let b:endwise_addition = 'end' |
\ let b:endwise_words = 'function,do,then' |
\ let b:endwise_pattern = '^\s*\zs\%(\%(local\s\+\)\=function\)\>\%(.*\<end\>\)\@!\|\<\%(then\|do\)\ze\s*$' |
\ let b:endwise_syngroups = 'luaFunction,luaStatement,luaCond'
autocmd FileType elixir
\ let b:endwise_addition = 'end' |
\ let b:endwise_words = 'do,fn' |
\ let b:endwise_pattern = '.*[^.:@$]\zs\<\%(do\(:\)\@!\|fn\)\>\ze\%(.*[^.:@$]\<end\>\)\@!' |
\ let b:endwise_syngroups = 'elixirBlockDefinition'
autocmd FileType ruby
\ let b:endwise_addition = 'end' |
\ let b:endwise_words = 'module,class,def,if,unless,case,while,until,begin,do' |
\ let b:endwise_pattern = '^\(.*=\)\?\s*\%(private\s\+\|protected\s\+\|public\s\+\|module_function\s\+\)*\zs\%(module\|class\|def\|if\|unless\|case\|while\|until\|for\|\|begin\)\>\%(.*[^.:@$]\<end\>\)\@!\|\<do\ze\%(\s*|.*|\)\=\s*$' |
\ let b:endwise_syngroups = 'rubyModule,rubyClass,rubyDefine,rubyControl,rubyConditional,rubyRepeat'
autocmd FileType crystal
\ let b:endwise_addition = 'end' |
\ let b:endwise_words = 'module,class,lib,macro,struct,union,enum,def,if,unless,ifdef,case,while,until,for,begin,do' |
\ let b:endwise_pattern = '^\(.*=\)\?\s*\%(private\s\+\|protected\s\+\|public\s\+\|abstract\s\+\)*\zs\%(module\|class\|lib\|macro\|struct\|union\|enum\|def\|if\|unless\|ifdef\|case\|while\|until\|for\|begin\)\>\%(.*[^.:@$]\<end\>\)\@!\|\<do\ze\%(\s*|.*|\)\=\s*$' |
\ let b:endwise_syngroups = 'crystalModule,crystalClass,crystalLib,crystalMacro,crystalStruct,crystalDefine,crystalConditional,crystalRepeat,crystalControl'
autocmd FileType sh,zsh
\ let b:endwise_addition = '\=submatch(0)=="then" ? "fi" : submatch(0)=="case" ? "esac" : "done"' |
\ let b:endwise_words = 'then,case,do' |
\ let b:endwise_pattern = '\%(^\s*\zscase\>\ze\|\zs\<\%(do\|then\)\ze\s*$\)' |
\ let b:endwise_syngroups = 'shConditional,shLoop,shIf,shFor,shRepeat,shCaseEsac,zshConditional,zshRepeat,zshDelimiter'
autocmd FileType vb,vbnet,aspvbs
\ let b:endwise_addition = 'End &' |
\ let b:endwise_words = 'Function,Sub,Class,Module,Enum,Namespace' |
\ let b:endwise_pattern = '\%(\<End\>.*\)\@<!\<&\>' |
\ let b:endwise_syngroups = 'vbStatement,vbnetStorage,vbnetProcedure,vbnet.*Words,AspVBSStatement'
autocmd FileType vim
\ let b:endwise_addition = '\=submatch(0)=="augroup" ? submatch(0) . " END" : "end" . submatch(0)' |
\ let b:endwise_words = 'fu,fun,func,function,wh,while,if,for,try,au,augroup' |
\ let b:endwise_syngroups = 'vimFuncKey,vimNotFunc,vimCommand,vimAugroupKey'
autocmd FileType c,cpp,xdefaults,haskell
\ let b:endwise_addition = '#endif' |
\ let b:endwise_words = 'if,ifdef,ifndef' |
\ let b:endwise_pattern = '^\s*#\%(if\|ifdef\|ifndef\)\>' |
\ let b:endwise_syngroups = 'cPreCondit,cPreConditMatch,cCppInWrapper,xdefaultsPreProc'
autocmd FileType objc
\ let b:endwise_addition = '@end' |
\ let b:endwise_words = 'interface,implementation' |
\ let b:endwise_pattern = '^\s*@\%(interface\|implementation\)\>' |
\ let b:endwise_syngroups = 'objcObjDef'
autocmd FileType matlab
\ let b:endwise_addition = 'end' |
\ let b:endwise_words = 'function,if,for' |
\ let b:endwise_syngroups = 'matlabStatement,matlabFunction,matlabConditional,matlabRepeat'
autocmd FileType htmldjango
\ let b:endwise_addition = '{% end& %}' |
\ let b:endwise_words = 'autoescape,block\(\s\+\S*\)\?,blocktrans,cache,comment,filter,for,if,ifchanged,ifequal,ifnotequal,language,spaceless,verbatim,with' |
\ let b:endwise_syngroups = 'djangoTagBlock,djangoStatement'
autocmd FileType snippets
\ let b:endwise_addition = 'endsnippet' |
\ let b:endwise_words = 'snippet' |
\ let b:endwise_syngroups = 'snipSnippet,snipSnippetHeader,snipSnippetHeaderKeyword'
autocmd FileType * call s:abbrev()
augroup END " }}}1
function! s:abbrev()
if exists('g:endwise_abbreviations')
for word in split(get(b:, 'endwise_words', ''), ',')
execute 'iabbrev <buffer><script>' word word.'<CR><SID>DiscretionaryEnd<Space><C-U><BS>'
endfor
endif
endfunction
function! s:teardownMappings()
inoremap <buffer> <C-X><CR> <C-X><CR>
inoremap <buffer> <CR> <CR>
endfunction
" Functions {{{1
function! EndwiseDiscretionary()
return <SID>crend(0)
endfunction
function! EndwiseAlways()
return <SID>crend(1)
endfunction
" }}}1
" Maps {{{1
if maparg("<Plug>DiscretionaryEnd") == ""
inoremap <silent> <SID>DiscretionaryEnd <C-R>=<SID>crend(0)<CR>
inoremap <silent> <SID>AlwaysEnd <C-R>=<SID>crend(1)<CR>
imap <script> <Plug>DiscretionaryEnd <SID>DiscretionaryEnd
imap <script> <Plug>AlwaysEnd <SID>AlwaysEnd
endif
if !exists('g:endwise_no_mappings')
if maparg('<CR>','i') =~# '<C-R>=.*crend(.)<CR>\|<\%(Plug\|SNR\|SID\)>.*End'
" Already mapped
elseif maparg('<CR>','i') =~ '<CR>'
exe "imap <script> <C-X><CR> ".maparg('<CR>','i')."<SID>AlwaysEnd"
exe "imap <script> <CR> ".maparg('<CR>','i')."<SID>DiscretionaryEnd"
elseif maparg('<CR>','i') =~ '<Plug>\w\+CR'
exe "imap <C-X><CR> ".maparg('<CR>', 'i')."<Plug>AlwaysEnd"
exe "imap <CR> ".maparg('<CR>', 'i')."<Plug>DiscretionaryEnd"
else
imap <script> <C-X><CR> <CR><SID>AlwaysEnd
imap <CR> <CR><Plug>DiscretionaryEnd
endif
autocmd endwise CmdwinEnter * call s:teardownMappings()
endif
" }}}1
" Code {{{1
function! s:mysearchpair(beginpat,endpat,synpat)
let g:endwise_syntaxes = ""
let s:lastline = line('.')
call s:synname()
let line = searchpair(a:beginpat,'',a:endpat,'Wn','<SID>synname() !~# "^'.substitute(a:synpat,'\\','\\\\','g').'$"',line('.')+50)
return line
endfunction
function! s:crend(always)
let n = ""
if !exists("b:endwise_addition") || !exists("b:endwise_words") || !exists("b:endwise_syngroups")
return n
end
let synpat = '\%('.substitute(b:endwise_syngroups,',','\\|','g').'\)'
let wordchoice = '\%('.substitute(b:endwise_words,',','\\|','g').'\)'
if exists("b:endwise_pattern")
let beginpat = substitute(b:endwise_pattern,'&',substitute(wordchoice,'\\','\\&','g'),'g')
else
let beginpat = '\<'.wordchoice.'\>'
endif
let lnum = line('.') - 1
let space = matchstr(getline(lnum),'^\s*')
let col = match(getline(lnum),beginpat) + 1
let word = matchstr(getline(lnum),beginpat)
let endword = substitute(word,'.*',b:endwise_addition,'')
let y = n.endword."\<C-O>O"
if b:endwise_addition[0:1] ==# '\='
let endpat = '\w\@<!'.endword.'\w\@!'
else
let endpat = '\w\@<!'.substitute('\w\+', '.*', b:endwise_addition, '').'\w\@!'
endif
if a:always
return y
elseif col <= 0 || synIDattr(synID(lnum,col,1),'name') !~ '^'.synpat.'$'
return n
elseif getline('.') !~ '^\s*#\=$'
return n
endif
let line = s:mysearchpair(beginpat,endpat,synpat)
" even is false if no end was found, or if the end found was less
" indented than the current line
let even = strlen(matchstr(getline(line),'^\s*')) >= strlen(space)
if line == 0
let even = 0
endif
if !even && line == line('.') + 1
return y
endif
if even
return n
endif
return y
endfunction
function! s:synname()
" Checking this helps to force things to stay in sync
while s:lastline < line('.')
let s = synIDattr(synID(s:lastline,indent(s:lastline)+1,1),'name')
let s:lastline = nextnonblank(s:lastline + 1)
endwhile
let s = synIDattr(synID(line('.'),col('.'),1),'name')
let g:endwise_syntaxes = g:endwise_syntaxes . line('.').','.col('.')."=".s."\n"
let s:lastline = line('.')
return s
endfunction
" }}}1
" vim:set sw=2 sts=2: