diff options
author | Bram Moolenaar <Bram@vim.org> | 2005-09-16 21:55:43 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2005-09-16 21:55:43 +0000 |
commit | 60a795aad6ade281146a5343b416f21825af5364 (patch) | |
tree | f38bf3d5e39bd321b2ff7b4d9bdf0367c8bec00b /runtime | |
parent | 6b730e111c329caccbb16f08c5b6bbc41d3b5690 (diff) |
updated for version 7.0148v7.0148
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/autoload/zip.vim | 226 | ||||
-rw-r--r-- | runtime/compiler/eruby.vim | 38 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 7 | ||||
-rw-r--r-- | runtime/doc/filetype.txt | 5 | ||||
-rw-r--r-- | runtime/doc/tags | 1 | ||||
-rw-r--r-- | runtime/doc/todo.txt | 4 | ||||
-rw-r--r-- | runtime/doc/version7.txt | 5 | ||||
-rw-r--r-- | runtime/doc/zip.txt | 31 | ||||
-rw-r--r-- | runtime/ftplugin/ruby.vim | 125 | ||||
-rw-r--r-- | runtime/indent/ruby.vim | 385 | ||||
-rw-r--r-- | runtime/keymap/tamil_tscii.vim | 572 | ||||
-rw-r--r-- | runtime/syntax/eruby.vim | 12 |
12 files changed, 1355 insertions, 56 deletions
diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim new file mode 100644 index 0000000000..751b1a1dcc --- /dev/null +++ b/runtime/autoload/zip.vim @@ -0,0 +1,226 @@ +" zip.vim: Handles browsing zipfiles +" AUTOLOAD PORTION +" Date: Sep 16, 2005 +" Version: 2 +" Maintainer: Charles E Campbell, Jr <drchipNOSPAM at campbellfamily dot biz> +" License: Vim License (see vim's :help license) +" Copyright: Copyright (C) 2005 Charles E. Campbell, Jr. {{{1 +" Permission is hereby granted to use and distribute this code, +" with or without modifications, provided that this copyright +" notice is copied with it. Like anything else that's free, +" zipPlugin.vim is provided *as is* and comes with no warranty +" of any kind, either expressed or implied. By using this +" plugin, you agree that in no event will the copyright +" holder be liable for any damages resulting from the use +" of this software. + +" --------------------------------------------------------------------- +" Initialization: {{{1 +let s:keepcpo= &cpo +set cpo&vim +if exists("g:loaded_zip") + finish +endif + +let g:loaded_zip= "v2" + +" ---------------- +" Functions: {{{1 +" ---------------- + +" --------------------------------------------------------------------- +" zip#Browse: {{{2 +fun! zip#Browse(zipfile) +" call Dfunc("zip#Browse(zipfile<".a:zipfile.">)") + + " sanity checks + if !executable("unzip") + echohl Error | echo "***error*** (zip#Browse) unzip not available on your system" + call inputsave()|call input("Press <cr> to continue")|call inputrestore() +" call Dret("zip#Browse") + return + endif + if !filereadable(a:zipfile) + echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None + call inputsave()|call input("Press <cr> to continue")|call inputrestore() +" call Dret("zip#Browse") + return + endif + if &ma != 1 + set ma + endif + let w:zipfile= a:zipfile + + setlocal noswapfile + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal nobuflisted + setlocal nowrap + set ft=tar + + " give header + exe "$put ='".'\"'." zip.vim version ".g:loaded_zip."'" + exe "$put ='".'\"'." Browsing zipfile ".a:zipfile."'" + exe "$put ='".'\"'." Select a file with cursor and press ENTER"."'" + $put ='' + 0d + $ + + exe "silent r! unzip -l ".a:zipfile + $d + silent 4,$v/^\s\+\d\+\s\{0,5}\d/d + silent 4,$s/^\%(.*\)\s\+\(\S\)/\1/ + + setlocal noma nomod ro + noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr> + +" call Dret("zip#Browse") +endfun + +" --------------------------------------------------------------------- +" ZipBrowseSelect: {{{2 +fun! s:ZipBrowseSelect() +" call Dfunc("ZipBrowseSelect() zipfile<".w:zipfile.">") + let fname= getline(".") + + " sanity check + if fname =~ '^"' +" call Dret("ZipBrowseSelect") + return + endif + if fname =~ '/$' + echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None + call inputsave()|call input("Press <cr> to continue")|call inputrestore() +" call Dret("ZipBrowseSelect") + return + endif + +" call Decho("fname<".fname.">") + + " get zipfile to the new-window + let zipfile= substitute(w:zipfile,'.zip$','','e') + + new + wincmd _ + exe "e zipfile:".zipfile.':'.fname + filetype detect + +" call Dret("ZipBrowseSelect") +endfun + +" --------------------------------------------------------------------- +" zip#Read: {{{2 +fun! zip#Read(fname,mode) +" call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")") + let zipfile = substitute(a:fname,'zipfile:\(.\{-}\):.*$','\1','') + let fname = substitute(a:fname,'zipfile:.\{-}:\(.*\)$','\1','') +" call Decho("zipfile<".zipfile."> fname<".fname.">") + + exe "r! unzip -p ".zipfile." ".fname + + " cleanup + 0d + set nomod + +" call Dret("zip#Read") +endfun + +" --------------------------------------------------------------------- +" zip#Write: {{{2 +fun! zip#Write(fname) +" call Dfunc("zip#Write(fname<".a:fname.")") + + " sanity checks + if !executable("zip") + echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the zip pgm" | echohl None + call inputsave()|call input("Press <cr> to continue")|call inputrestore() +" call Dret("zip#Write") + return + endif + if !exists("*mkdir") + echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None + call inputsave()|call input("Press <cr> to continue")|call inputrestore() +" call Dret("zip#Write") + return + endif + + let curdir= getcwd() + let tmpdir= tempname() +" call Decho("orig tempname<".tmpdir.">") + if tmpdir =~ '\.' + let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') + endif +" call Decho("tmpdir<".tmpdir.">") + call mkdir(tmpdir,"p") + + " attempt to change to the indicated directory + try + exe "cd ".escape(tmpdir,' \') + catch /^Vim\%((\a\+)\)\=:E344/ + echohl Error | echo "***error*** (zip#Write) cannot cd to temporary directory" | Echohl None + call inputsave()|call input("Press <cr> to continue")|call inputrestore() +" call Dret("zip#Write") + return + endtry +" call Decho("current directory now: ".getcwd()) + + " place temporary files under .../_ZIPVIM_/ + if isdirectory("_ZIPVIM_") + call s:Rmdir("_ZIPVIM_") + endif + call mkdir("_ZIPVIM_") + cd _ZIPVIM_ +" call Decho("current directory now: ".getcwd()) + + let zipfile = substitute(a:fname,'zipfile:\(.\{-}\):.*$','\1','') + let fname = substitute(a:fname,'zipfile:.\{-}:\(.*\)$','\1','') + let dirpath = substitute(fname,'/[^/]\+$','','e') + if zipfile !~ '/' + let zipfile= curdir.'/'.zipfile + endif +" call Decho("zipfile<".zipfile."> fname<".fname.">") + + call mkdir(dirpath,"p") + exe "w! ".fname + if executable("cygpath") + let dirpath = substitute(system("cygpath ".dirpath),'\n','','e') + let zipfile = substitute(system("cygpath ".zipfile),'\n','','e') + endif + +" call Decho("zip -u ".zipfile.".zip ".fname) + call system("zip -u ".zipfile.".zip ".fname) + if v:shell_error != 0 + echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None + call inputsave()|call input("Press <cr> to continue")|call inputrestore() + endif + + " cleanup and restore current directory + cd .. + call s:Rmdir("_ZIPVIM_") + exe "cd ".escape(curdir,' \') + setlocal nomod + +" call Dret("zip#Write") +endfun + +" --------------------------------------------------------------------- +" Rmdir: {{{2 +fun! s:Rmdir(fname) +" call Dfunc("Rmdir(fname<".a:fname.">)") + if has("unix") + call system("/bin/rm -rf ".a:fname) + elseif has("win32") || has("win95") || has("win64") || has("win16") + if &shell =~? "sh$" + call system("/bin/rm -rf ".a:fname) + else + call system("del /S ".a:fname) + endif + endif +" call Dret("Rmdir") +endfun + +" ------------------------------------------------------------------------ +" Modelines And Restoration: {{{1 +let &cpo= s:keepcpo +unlet s:keepcpo +" vim:ts=8 fdm=marker diff --git a/runtime/compiler/eruby.vim b/runtime/compiler/eruby.vim new file mode 100644 index 0000000000..5d85bf14f2 --- /dev/null +++ b/runtime/compiler/eruby.vim @@ -0,0 +1,38 @@ +" Vim compiler file +" Language: eRuby +" Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au> +" Info: $Id$ +" URL: http://vim-ruby.sourceforge.net +" Anon CVS: See above site +" Licence: GPL (http://www.gnu.org) +" Disclaimer: +" This program is distributed in the hope that it will be useful, +" but WITHOUT ANY WARRANTY; without even the implied warranty of +" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +" GNU General Public License for more details. +" ---------------------------------------------------------------------------- + +if exists("current_compiler") + finish +endif +let current_compiler = "eruby" + +if exists(":CompilerSet") != 2 " older Vim always used :setlocal + command -nargs=* CompilerSet setlocal <args> +endif + +let s:cpo_save = &cpo +set cpo-=C + +CompilerSet makeprg=eruby + +CompilerSet errorformat=eruby:\ %f:%l:%m, + \%E%f:%l:\ %m, + \%-Z%p^, + \%C%m, + \%-G%.%# + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: nowrap sw=2 sts=2 ts=8 ff=unix: diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 6e3d26cf53..368b444746 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,4 +1,4 @@ -*eval.txt* For Vim version 7.0aa. Last change: 2005 Sep 12 +*eval.txt* For Vim version 7.0aa. Last change: 2005 Sep 15 VIM REFERENCE MANUAL by Bram Moolenaar @@ -4972,7 +4972,7 @@ then define the function like this: > echo "Done!" endfunction -The file name and the name used before the colon in the function must match +The file name and the name used before the # in the function must match exactly, and the defined function must have the name exactly as it will be called. @@ -4983,9 +4983,6 @@ a path separator. Thus when calling a function: > Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'. -The name before the first colon must be at least two characters long, -otherwise it looks like a scope, such as "s:". - This also works when reading a variable that has not been set yet: > :let l = foo#bar#lvar diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index e68b75a164..07d4425178 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -1,4 +1,4 @@ -*filetype.txt* For Vim version 7.0aa. Last change: 2005 Aug 30 +*filetype.txt* For Vim version 7.0aa. Last change: 2005 Sep 16 VIM REFERENCE MANUAL by Bram Moolenaar @@ -184,7 +184,8 @@ A. If you want to overrule all default file type checks. < 3. To use the new filetype detection you must restart Vim. The files in the "ftdetect" directory are used after all the default - checks, thus they can overrule a previously detected file type. + checks, thus they can overrule a previously detected file type. But you + can also use |:setfiletype| to keep a previously detected filetype. B. If you want to detect your file after the default file type checks. diff --git a/runtime/doc/tags b/runtime/doc/tags index 4dc0414856..451212233d 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -5294,7 +5294,6 @@ hebrew hebrew.txt /*hebrew* hebrew.txt hebrew.txt /*hebrew.txt* help various.txt /*help* help-context help.txt /*help-context* -help-tags tags 1 help-translated various.txt /*help-translated* help-xterm-window various.txt /*help-xterm-window* help.txt help.txt /*help.txt* diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index 65e76b93b4..cbd77d0ae3 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -1,4 +1,4 @@ -*todo.txt* For Vim version 7.0aa. Last change: 2005 Sep 14 +*todo.txt* For Vim version 7.0aa. Last change: 2005 Sep 16 VIM REFERENCE MANUAL by Bram Moolenaar @@ -30,6 +30,8 @@ be worked on, but only if you sponsor Vim development. See |sponsor|. *known-bugs* -------------------- Known bugs and current work ----------------------- +Test11 fails sometimes. (athena, huge features) + ccomplete: - How to use a popup menu? - When a typedef or struct is local to a file only use it in that file? diff --git a/runtime/doc/version7.txt b/runtime/doc/version7.txt index ce0b32b4b4..e4e981bb6c 100644 --- a/runtime/doc/version7.txt +++ b/runtime/doc/version7.txt @@ -1,4 +1,4 @@ -*version7.txt* For Vim version 7.0aa. Last change: 2005 Sep 13 +*version7.txt* For Vim version 7.0aa. Last change: 2005 Sep 15 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1361,4 +1361,7 @@ searching for "qa" instead of quitting all windows. GUI: When scrolling with the scrollbar and there is a line that doesn't fit redrawing may fail. Make sure w_skipcol is valid before redrawing. +"dFxd;" deleted the character under the cursor, "d;" didn't remember the +exclusiveness of the motion. + vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/zip.txt b/runtime/doc/zip.txt new file mode 100644 index 0000000000..aa95460afc --- /dev/null +++ b/runtime/doc/zip.txt @@ -0,0 +1,31 @@ +*zip.txt* Zip File Interface Sep 16, 2005 + +Author: Charles E. Campbell, Jr. <NdrOchip@ScampbellPfamily.AbizM> + (remove NOSPAM from Campbell's email first) +Copyright: Copyright (C) 2005 Charles E. Campbell, Jr. {{{1 *zip-copyright* + Permission is hereby granted to use and distribute this code, + with or without modifications, provided that this copyright + notice is copied with it. Like anything else that's free, + zip.vim and zipPlugin.vim are provided *as is* and comes with no + warranty of any kind, either expressed or implied. By using this + plugin, you agree that in no event will the copyright holder be + liable for any damages resulting from the use of this software. + +============================================================================== +1. Contents *zip* *zip-contents* + 1. Contents..................................................|zip-contents| + 2. Usage.....................................................|zip-usage| + 3. History...................................................|zip-history| + +============================================================================== +2. Usage *zip-usage* *zip-manual* + +============================================================================== +3. History *zip-history* + v2 Sep 16, 2005 * silenced some commands (avoiding hit-enter prompt) + * began testing under Windows; works thus far + * filetype detection fixed + v1 Sep 15, 2005 * Initial release, had browsin, reading, and writing + +============================================================================== +vim:tw=78:ts=8:ft=help diff --git a/runtime/ftplugin/ruby.vim b/runtime/ftplugin/ruby.vim index e21afeee5d..b262258d85 100644 --- a/runtime/ftplugin/ruby.vim +++ b/runtime/ftplugin/ruby.vim @@ -1,14 +1,125 @@ " Vim filetype plugin -" Language: Ruby -" Maintainer: Gavin Sinclair <gsinclair@soyabean.com.au> -" Last Change: 2002/08/12 -" URL: www.soyabean.com.au/gavin/vim/index.html +" Language: Ruby +" Maintainer: Gavin Sinclair <gsinclair at soyabean.com.au> +" Info: $Id$ +" URL: http://vim-ruby.sourceforge.net +" Anon CVS: See above site +" Licence: GPL (http://www.gnu.org) +" Disclaimer: +" This program is distributed in the hope that it will be useful, +" but WITHOUT ANY WARRANTY; without even the implied warranty of +" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +" GNU General Public License for more details. +" ---------------------------------------------------------------------------- +" +" Original matchit support thanks to Ned Konz. See his ftplugin/ruby.vim at +" http://bike-nomad.com/vim/ruby.vim. +" ---------------------------------------------------------------------------- " Only do this when not done yet for this buffer if (exists("b:did_ftplugin")) - finish + finish endif let b:did_ftplugin = 1 -" There are no known setting particularly appropriate for Ruby. Please -" contact the maintainer if you think of some. +let s:cpo_save = &cpo +set cpo&vim + +" Matchit support +if exists("loaded_matchit") && !exists("b:match_words") + let b:match_ignorecase = 0 + + " TODO: improve optional do loops + let b:match_words = + \ '\%(' . + \ '\%(\%(\.\|\:\:\)\s*\)\@<!\<\%(class\|module\|begin\|def\|case\|for\|do\)\>' . + \ '\|' . + \ '\%(\%(^\|\.\.\.\=\|[\,;=([<>~\*/%!&^|+-]\)\s*\)\@<=\%(if\|unless\|until\|while\)\>' . + \ '\)' . + \ ':' . + \ '\%(' . + \ '\%(\%(\.\|\:\:\)\s*\)\@<!\<\%(else\|elsif\|ensure\|when\)\>' . + \ '\|' . + \ '\%(\%(^\|;\)\s*\)\@<=\<rescue\>' . + \ '\)' . + \ ':' . + \ '\%(\%(\.\|\:\:\)\s*\)\@<!\<end\>' + + let b:match_skip = + \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '" . + \ "\\<ruby\\%(String\\|StringDelimiter\\|ASCIICode\\|Interpolation\\|" . + \ "NoInterpolation\\|Escape\\|Comment\\|Documentation\\)\\>'" + +endif + +setlocal formatoptions-=t formatoptions+=croql + +setlocal include=^\\s*\\<\\(load\\\|\w*require\\)\\> +setlocal includeexpr=substitute(substitute(v:fname,'::','/','g'),'$','.rb','') +setlocal suffixesadd=.rb + +" TODO: +"setlocal define=^\\s*def + +setlocal comments=:# +setlocal commentstring=#\ %s + +if !exists("s:rubypath") + if executable("ruby") + if &shellxquote == "'" + let s:rubypath = system('ruby -e "puts (begin; require %q{rubygems}; Gem.all_load_paths; rescue LoadError; []; end + $:).join(%q{,})"') + else + let s:rubypath = system("ruby -e 'puts (begin; require %q{rubygems}; Gem.all_load_paths; rescue LoadError; []; end + $:).join(%q{,})'") + endif + let s:rubypath = substitute(s:rubypath,',.$',',,','') + else + " If we can't call ruby to get its path, just default to using the + " current directory and the directory of the current file. + let s:rubypath = ".,," + endif +endif + +let &l:path = s:rubypath + +if has("gui_win32") && !exists("b:browsefilter") + let b:browsefilter = "Ruby Source Files (*.rb)\t*.rb\n" . + \ "All Files (*.*)\t*.*\n" +endif + +let b:undo_ftplugin = "setl fo< inc< inex< sua< def< com< cms< path< " + \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip" + +let &cpo = s:cpo_save +unlet s:cpo_save + +" +" Instructions for enabling "matchit" support: +" +" 1. Look for the latest "matchit" plugin at +" +" http://www.vim.org/scripts/script.php?script_id=39 +" +" It is also packaged with Vim, in the $VIMRUNTIME/macros directory. +" +" 2. Copy "matchit.txt" into a "doc" directory (e.g. $HOME/.vim/doc). +" +" 3. Copy "matchit.vim" into a "plugin" directory (e.g. $HOME/.vim/plugin). +" +" 4. Ensure this file (ftplugin/ruby.vim) is installed. +" +" 5. Ensure you have this line in your $HOME/.vimrc: +" filetype plugin on +" +" 6. Restart Vim and create the matchit documentation: +" +" :helptags ~/.vim/doc +" +" Now you can do ":help matchit", and you should be able to use "%" on Ruby +" keywords. Try ":echo b:match_words" to be sure. +" +" Thanks to Mark J. Reed for the instructions. See ":help vimrc" for the +" locations of plugin directories, etc., as there are several options, and it +" differs on Windows. Email gsinclair@soyabean.com.au if you need help. +" + +" vim: nowrap sw=2 sts=2 ts=8 ff=unix: diff --git a/runtime/indent/ruby.vim b/runtime/indent/ruby.vim index ce078f2a08..ff22bbb41c 100644 --- a/runtime/indent/ruby.vim +++ b/runtime/indent/ruby.vim @@ -1,11 +1,20 @@ " Vim indent file -" Language: Ruby -" Maintainer: Gavin Sinclair <gsinclair@soyabean.com.au> -" Last Change: 2003 May 11 -" URL: www.soyabean.com.au/gavin/vim/index.html -" Changes: (since vim 6.1) -" - indentation after a line ending in comma, etc, (even in a comment) was -" broken, now fixed (2002/08/14) +" Language: Ruby +" Maintainer: Gavin Sinclair <gsinclair at soyabean.com.au> +" Developer: Nikolai Weibull <source at pcppopper.org> +" Info: $Id$ +" URL: http://vim-ruby.rubyforge.org/ +" Anon CVS: See above site +" Licence: GPL (http://www.gnu.org) +" Disclaimer: +" This program is distributed in the hope that it will be useful, +" but WITHOUT ANY WARRANTY; without even the implied warranty of +" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +" GNU General Public License for more details. +" ---------------------------------------------------------------------------- + +" 0. Initialization {{{1 +" ================= " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -13,55 +22,363 @@ if exists("b:did_indent") endif let b:did_indent = 1 +" Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetRubyIndent() -setlocal nolisp -setlocal nosmartindent -setlocal autoindent -setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue +setlocal indentkeys=0{,0},0),0],!^F,o,O,e +setlocal indentkeys+==end,=elsif,=when,=ensure,=rescue,==begin,==end " Only define the function once. if exists("*GetRubyIndent") finish endif +let s:cpo_save = &cpo +set cpo&vim + +" 1. Variables {{{1 +" ============ + +" Regex of syntax group names that are or delimit string or are comments. +let s:syng_strcom = '\<ruby\%(String\|StringDelimiter\|ASCIICode' . + \ '\|Interpolation\|NoInterpolation\|Escape\|Comment\|Documentation\)\>' + +" Regex of syntax group names that are strings or comments. +let s:syng_strcom2 = '\<ruby\%(String' . + \ '\|Interpolation\|NoInterpolation\|Escape\|Comment\|Documentation\)\>' + +" Regex of syntax group names that are strings. +let s:syng_string = + \ '\<ruby\%(String\|Interpolation\|NoInterpolation\|Escape\)\>' + +" Regex of syntax group names that are strings or documentation. +let s:syng_stringdoc = + \'\<ruby\%(String\|Interpolation\|NoInterpolation\|Escape\|Documentation\)\>' + +" Expression used to check whether we should skip a match with searchpair(). +let s:skip_expr = + \ "synIDattr(synID(line('.'),col('.'),0),'name') =~ '".s:syng_strcom."'" + +" Regex used for words that, at the start of a line, add a level of indent. +let s:ruby_indent_keywords = '^\s*\zs\<\%(module\|class\|def\|if\|for' . + \ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure' . + \ '\|rescue\)\>' . + \ '\|\%([*+/,=:-]\|<<\|>>\)\s*\zs' . + \ '\<\%(if\|for\|while\|until\|case\|unless\|begin\)\>' + +" Regex used for words that, at the start of a line, remove a level of indent. +let s:ruby_deindent_keywords = + \ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\)\>' + +" Regex that defines the start-match for the 'end' keyword. +"let s:end_start_regex = '\%(^\|[^.]\)\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\|do\)\>' +" TODO: the do here should be restricted somewhat (only at end of line)? +let s:end_start_regex = '^\s*\zs\<\%(module\|class\|def\|if\|for' . + \ '\|while\|until\|case\|unless\|begin\)\>' . + \ '\|\%([*+/,=:-]\|<<\|>>\)\s*\zs' . + \ '\<\%(if\|for\|while\|until\|case\|unless\|begin\)\>' . + \ '\|\<do\>' + +" Regex that defines the middle-match for the 'end' keyword. +let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue\>\|when\|elsif\)\>' + +" Regex that defines the end-match for the 'end' keyword. +let s:end_end_regex = '\%(^\|[^.]\)\@<=\<end\>' + +" Expression used for searchpair() call for finding match for 'end' keyword. +let s:end_skip_expr = s:skip_expr . + \ ' || (expand("<cword>") == "do"' . + \ ' && getline(".") =~ "^\\s*\\<while\\|until\\|for\\>")' + +" Regex that defines continuation lines, not including (, {, or [. +let s:continuation_regex = '\%([\\*+/.,=:-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$' + +" Regex that defines continuation lines. +" TODO: this needs to deal with if ...: and so on +let s:continuation_regex2 = + \ '\%([\\*+/.,=:({[-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$' + +" Regex that defines blocks. +let s:block_regex = + \ '\%(\<do\>\|{\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=\s*\%(#.*\)\=$' + +" 2. Auxiliary Functions {{{1 +" ====================== + +" Check if the character at lnum:col is inside a string, comment, or is ascii. +function s:IsInStringOrComment(lnum, col) + return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_strcom +endfunction + +" Check if the character at lnum:col is inside a string or comment. +function s:IsInStringOrComment2(lnum, col) + return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_strcom2 +endfunction + +" Check if the character at lnum:col is inside a string. +function s:IsInString(lnum, col) + return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_string +endfunction + +" Check if the character at lnum:col is inside a string or documentation. +function s:IsInStringOrDocumentation(lnum, col) + return synIDattr(synID(a:lnum, a:col, 0), 'name') =~ s:syng_stringdoc +endfunction + +" Find line above 'lnum' that isn't empty, in a comment, or in a string. +function s:PrevNonBlankNonString(lnum) + let in_block = 0 + let lnum = prevnonblank(a:lnum) + while lnum > 0 + " Go in and out of blocks comments as necessary. + " If the line isn't empty (with opt. comment) or in a string, end search. + let line = getline(lnum) + if line =~ '^=begin$' + if in_block + let in_block = 0 + else + break + endif + elseif !in_block && line =~ '^=end$' + let in_block = 1 + elseif !in_block && line !~ '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1) + \ && s:IsInStringOrComment(lnum, strlen(line))) + break + endif + let lnum = prevnonblank(lnum - 1) + endwhile + return lnum +endfunction + +" Find line above 'lnum' that started the continuation 'lnum' may be part of. +function s:GetMSL(lnum) + " Start on the line we're at and use its indent. + let msl = a:lnum + let lnum = s:PrevNonBlankNonString(a:lnum - 1) + while lnum > 0 + " If we have a continuation line, or we're in a string, use line as MSL. + " Otherwise, terminate search as we have found our MSL already. + let line = getline(lnum) + let col = match(line, s:continuation_regex2) + 1 + if (col > 0 && !s:IsInStringOrComment(lnum, col)) + \ || s:IsInString(lnum, strlen(line)) + let msl = lnum + else + break + endif + let lnum = s:PrevNonBlankNonString(lnum - 1) + endwhile + return msl +endfunction + +" Check if line 'lnum' has more opening brackets than closing ones. +function s:LineHasOpeningBrackets(lnum) + let open_0 = 0 + let open_2 = 0 + let open_4 = 0 + let line = getline(a:lnum) + let pos = match(line, '[][(){}]', 0) + while pos != -1 + if !s:IsInStringOrComment(a:lnum, pos + 1) + let idx = stridx('(){}[]', line[pos]) + if idx % 2 == 0 + let open_{idx} = open_{idx} + 1 + else + let open_{idx - 1} = open_{idx - 1} - 1 + endif + endif + let pos = match(line, '[][(){}]', pos + 1) + endwhile + return (open_0 > 0) . (open_2 > 0) . (open_4 > 0) +endfunction + +function s:Match(lnum, regex) + let col = match(getline(a:lnum), a:regex) + 1 + return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 +endfunction + +function s:MatchLast(lnum, regex) + let line = getline(a:lnum) + let col = match(line, '.*\zs' . a:regex) + while col != -1 && s:IsInStringOrComment(a:lnum, col) + let line = strpart(line, 0, col) + let col = match(line, '.*' . a:regex) + endwhile + return col + 1 +endfunction + +" 3. GetRubyIndent Function {{{1 +" ========================= + function GetRubyIndent() - " Find a non-blank line above the current line. - let lnum = prevnonblank(v:lnum - 1) + " 3.1. Setup {{{2 + " ---------- + + " Set up variables for restoring position in file. Could use v:lnum here. + let vcol = col('.') + + " 3.2. Work on the current line {{{2 + " ----------------------------- + + " Get the current line. + let line = getline(v:lnum) + let ind = -1 + + " If we got a closing bracket on an empty line, find its match and indent + " according to it. For parentheses we indent to its column - 1, for the + " others we indent to the containing line's MSL's level. Return -1 if fail. + let col = matchend(line, '^\s*[]})]') + if col > 0 && !s:IsInStringOrComment(v:lnum, col) + call cursor(v:lnum, col) + let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2) + if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0 + let ind = line[col-1]==')' ? virtcol('.')-1 : indent(s:GetMSL(line('.'))) + endif + return ind + endif + + " If we have a =begin or =end set indent to first column. + if match(line, '^\s*\%(=begin\|=end\)$') != -1 + return 0 + endif + + " If we have a deindenting keyword, find its match and indent to its level. + " TODO: this is messy + if s:Match(v:lnum, s:ruby_deindent_keywords) +" let lnum = s:PrevNonBlankNonString(v:lnum - 1) +" +" if lnum == 0 +" return 0 +" endif +" +" return indent(v:lnum) - &sw + call cursor(v:lnum, 1) + if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW', + \ s:end_skip_expr) > 0 + if strpart(getline('.'), 0, col('.') - 1) =~ '=\s*' + let ind = virtcol('.') - 1 + else + let ind = indent('.') + endif + endif + return ind + endif + + " If we are in a multi-line string or line-comment, don't do anything to it. + if s:IsInStringOrDocumentation(v:lnum, matchend(line, '^\s*') + 1) + return indent('.') + endif + + " 3.3. Work on the previous line. {{{2 + " ------------------------------- + + " Find a non-blank, non-multi-line string line above the current line. + let lnum = s:PrevNonBlankNonString(v:lnum - 1) " At the start of the file use zero indent. if lnum == 0 return 0 endif - " If the line trailed with [*+,.(] - but not in a comment - trust the user - if getline(lnum) =~ '\(\[^#\].*\)?\(\*\|\.\|+\|,\|(\)\(\s*#.*\)\=$' - return -1 + " Set up variables for current line. + let line = getline(lnum) + let ind = indent(lnum) + + " If the previous line ended with a block opening, add a level of indent. + if s:Match(lnum, s:block_regex) + return indent(s:GetMSL(lnum)) + &sw + endif + + " If the previous line contained an opening bracket, and we are still in it, + " add indent depending on the bracket type. + if line =~ '[[({]' + let counts = s:LineHasOpeningBrackets(lnum) + if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0 + return virtcol('.') + elseif counts[1] == '1' || counts[2] == '1' + return ind + &sw + else + call cursor(v:lnum, vcol) + end endif - " Add a 'shiftwidth' after lines beginning with: - " module, class, dev, if, for, while, until, else, elsif, case, when, { - let ind = indent(lnum) - let flag = 0 - if getline(lnum) =~ '^\s*\(module\>\|class\>\|def\>\|if\>\|for\>\|while\>\|until\>\|else\>\|elsif\>\|case\>\|when\>\|unless\|begin\|ensure\>\|rescue\>\)' - \ || getline(lnum) =~ '{\s*$' - \ || getline(lnum) =~ '\({\|\<do\>\).*|.*|\s*$' - \ || getline(lnum) =~ '\<do\>\(\s*#.*\)\=$' - let ind = ind + &sw - let flag = 1 + " If the previous line ended with an "end", match that "end"s beginning's + " indent. + let col = s:Match(lnum, '\%(^\|[^.]\)\<end\>\s*\%(#.*\)\=$') + if col > 0 + call cursor(lnum, col) + if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW', + \ s:end_skip_expr) > 0 + let n = line('.') + let ind = indent('.') + let msl = s:GetMSL(n) + if msl != n + let ind = indent(msl) + end + return ind + endif + end + + let col = s:Match(lnum, s:ruby_indent_keywords) + if col > 0 + call cursor(lnum, col) + let ind = virtcol('.') - 1 + &sw +" let ind = indent(lnum) + &sw + " TODO: make this better (we need to count them) (or, if a searchpair + " fails, we know that something is lacking an end and thus we indent a + " level + if s:Match(lnum, s:end_end_regex) + let ind = indent('.') + endif + return ind endif - " Subtract a 'shiftwidth' after lines ending with - " "end" when they begin with while, if, for, until - if flag == 1 && getline(lnum) =~ '\<end\>\(\s*#.*\)\=$' - let ind = ind - &sw + " 3.4. Work on the MSL line. {{{2 + " -------------------------- + + " Set up variables to use and search for MSL to the previous line. + let p_lnum = lnum + let lnum = s:GetMSL(lnum) + + " If the previous line wasn't a MSL and is continuation return its indent. + " TODO: the || s:IsInString() thing worries me a bit. + if |