utils 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +68 -0
- data/VERSION +1 -0
- data/bin/chroot-exec +12 -0
- data/bin/chroot-libs +18 -0
- data/bin/classify +37 -0
- data/bin/discover +137 -0
- data/bin/edit +74 -0
- data/bin/errf +32 -0
- data/bin/git-empty +8 -0
- data/bin/myex +90 -0
- data/bin/number_files +26 -0
- data/bin/same_files +37 -0
- data/bin/search +205 -0
- data/bin/sedit +3 -0
- data/bin/sshscreen +68 -0
- data/bin/term +21 -0
- data/bin/unquarantine_apps +8 -0
- data/bin/untest +17 -0
- data/bin/utils-install-config +10 -0
- data/bin/vacuum_firefox_sqlite +22 -0
- data/bin/xmp +74 -0
- data/lib/utils.rb +8 -0
- data/lib/utils/config.rb +23 -0
- data/lib/utils/config/gdb/asm +179 -0
- data/lib/utils/config/gdb/ruby +528 -0
- data/lib/utils/config/gdbinit +8 -0
- data/lib/utils/config/irbrc +455 -0
- data/lib/utils/config/rdebugrc +2 -0
- data/lib/utils/config/screenrc +143 -0
- data/lib/utils/config/vim/autoload/Align.vim +1029 -0
- data/lib/utils/config/vim/autoload/AlignMaps.vim +330 -0
- data/lib/utils/config/vim/autoload/rails.vim +4744 -0
- data/lib/utils/config/vim/autoload/rubycomplete.vim +801 -0
- data/lib/utils/config/vim/autoload/sqlcomplete.vim +741 -0
- data/lib/utils/config/vim/autoload/vimball.vim +750 -0
- data/lib/utils/config/vim/colors/flori.vim +113 -0
- data/lib/utils/config/vim/compiler/eruby.vim +40 -0
- data/lib/utils/config/vim/compiler/ruby.vim +67 -0
- data/lib/utils/config/vim/compiler/rubyunit.vim +34 -0
- data/lib/utils/config/vim/ftdetect/ragel.vim +2 -0
- data/lib/utils/config/vim/ftdetect/ruby.vim +17 -0
- data/lib/utils/config/vim/ftplugin/eruby.vim +100 -0
- data/lib/utils/config/vim/ftplugin/ruby.vim +260 -0
- data/lib/utils/config/vim/ftplugin/xml.vim +941 -0
- data/lib/utils/config/vim/indent/IndentAnything_html.vim +35 -0
- data/lib/utils/config/vim/indent/eruby.vim +77 -0
- data/lib/utils/config/vim/indent/javascript.vim +116 -0
- data/lib/utils/config/vim/indent/ruby.vim +377 -0
- data/lib/utils/config/vim/plugin/AlignMapsPlugin.vim +242 -0
- data/lib/utils/config/vim/plugin/AlignPlugin.vim +41 -0
- data/lib/utils/config/vim/plugin/Decho.vim +592 -0
- data/lib/utils/config/vim/plugin/IndentAnything.vim +675 -0
- data/lib/utils/config/vim/plugin/bufexplorer.vim +1144 -0
- data/lib/utils/config/vim/plugin/cecutil.vim +482 -0
- data/lib/utils/config/vim/plugin/fugitive.vim +1703 -0
- data/lib/utils/config/vim/plugin/lusty-explorer.vim +1509 -0
- data/lib/utils/config/vim/plugin/rails.vim +340 -0
- data/lib/utils/config/vim/plugin/rubyextra.vim +193 -0
- data/lib/utils/config/vim/plugin/surround.vim +628 -0
- data/lib/utils/config/vim/plugin/taglist.vim +4546 -0
- data/lib/utils/config/vim/plugin/test/IndentAnything/test.js +131 -0
- data/lib/utils/config/vim/plugin/vimballPlugin.vim +40 -0
- data/lib/utils/config/vim/syntax/Decho.vim +101 -0
- data/lib/utils/config/vim/syntax/eruby.vim +73 -0
- data/lib/utils/config/vim/syntax/javascript.vim +246 -0
- data/lib/utils/config/vim/syntax/ragel.vim +165 -0
- data/lib/utils/config/vim/syntax/ruby.vim +367 -0
- data/lib/utils/config/vimrc +461 -0
- data/lib/utils/file.rb +49 -0
- data/lib/utils/find.rb +54 -0
- data/lib/utils/md5.rb +23 -0
- data/lib/utils/patterns.rb +34 -0
- data/lib/utils/version.rb +8 -0
- data/utils.gemspec +33 -0
- metadata +183 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
" Source the standard indentation file, since we only want to adjust the
|
3
|
+
" default indentation.
|
4
|
+
sou $VIMRUNTIME/indent/html.vim
|
5
|
+
|
6
|
+
" Set the default indentation to be that of the standard indent file.
|
7
|
+
let b:defaultIndentExpr = &indentexpr
|
8
|
+
|
9
|
+
" Use IndentAnything
|
10
|
+
setlocal indentexpr=IndentAnything()
|
11
|
+
|
12
|
+
" Echo info about indentations
|
13
|
+
let b:indent_anything_echo = 1
|
14
|
+
|
15
|
+
"
|
16
|
+
" Adjust the default indentation for comments. Set the comments for html to
|
17
|
+
" look like this:
|
18
|
+
"
|
19
|
+
" <!--
|
20
|
+
" - comment here
|
21
|
+
" -->
|
22
|
+
"
|
23
|
+
setl comments=sr:<!--,m:-,e:-->
|
24
|
+
let b:blockCommentStartRE = '<!--'
|
25
|
+
let b:blockCommentMiddleRE = '-'
|
26
|
+
let b:blockCommentEndRE = '-->'
|
27
|
+
let b:blockCommentMiddleExtra = 3
|
28
|
+
|
29
|
+
" Specify the syntax names for html comments and strings
|
30
|
+
let b:blockCommentRE = 'htmlComment'
|
31
|
+
let b:commentRE = b:blockCommentRE
|
32
|
+
|
33
|
+
let b:stringRE = 'htmlString'
|
34
|
+
let b:singleQuoteStringRE = b:stringRE
|
35
|
+
let b:doubleQuoteStringRE = b:stringRE
|
@@ -0,0 +1,77 @@
|
|
1
|
+
" Vim indent file
|
2
|
+
" Language: eRuby
|
3
|
+
" Maintainer: Tim Pope <vimNOSPAM@tpope.info>
|
4
|
+
" URL: http://vim-ruby.rubyforge.org
|
5
|
+
" Anon CVS: See above site
|
6
|
+
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
7
|
+
|
8
|
+
if exists("b:did_indent")
|
9
|
+
finish
|
10
|
+
endif
|
11
|
+
|
12
|
+
runtime! indent/ruby.vim
|
13
|
+
unlet! b:did_indent
|
14
|
+
setlocal indentexpr=
|
15
|
+
|
16
|
+
if exists("b:eruby_subtype")
|
17
|
+
exe "runtime! indent/".b:eruby_subtype.".vim"
|
18
|
+
else
|
19
|
+
runtime! indent/html.vim
|
20
|
+
endif
|
21
|
+
unlet! b:did_indent
|
22
|
+
|
23
|
+
if &l:indentexpr == ''
|
24
|
+
if &l:cindent
|
25
|
+
let &l:indentexpr = 'cindent(v:lnum)'
|
26
|
+
else
|
27
|
+
let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
|
28
|
+
endif
|
29
|
+
endif
|
30
|
+
let b:eruby_subtype_indentexpr = &l:indentexpr
|
31
|
+
|
32
|
+
let b:did_indent = 1
|
33
|
+
|
34
|
+
setlocal indentexpr=GetErubyIndent()
|
35
|
+
setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=rescue,=ensure,=when
|
36
|
+
|
37
|
+
" Only define the function once.
|
38
|
+
if exists("*GetErubyIndent")
|
39
|
+
finish
|
40
|
+
endif
|
41
|
+
|
42
|
+
function! GetErubyIndent(...)
|
43
|
+
if a:0 && a:1 == '.'
|
44
|
+
let v:lnum = line('.')
|
45
|
+
elseif a:0 && a:1 =~ '^\d'
|
46
|
+
let v:lnum = a:1
|
47
|
+
endif
|
48
|
+
let vcol = col('.')
|
49
|
+
call cursor(v:lnum,1)
|
50
|
+
let inruby = searchpair('<%','','%>','W')
|
51
|
+
call cursor(v:lnum,vcol)
|
52
|
+
if inruby && getline(v:lnum) !~ '^<%\|^\s*-\=%>'
|
53
|
+
let ind = GetRubyIndent()
|
54
|
+
else
|
55
|
+
exe "let ind = ".b:eruby_subtype_indentexpr
|
56
|
+
endif
|
57
|
+
let lnum = prevnonblank(v:lnum-1)
|
58
|
+
let line = getline(lnum)
|
59
|
+
let cline = getline(v:lnum)
|
60
|
+
if cline =~# '<%-\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%(-\=%>\|$\)'
|
61
|
+
let ind = ind - &sw
|
62
|
+
endif
|
63
|
+
if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*-\=%>'
|
64
|
+
let ind = ind + &sw
|
65
|
+
elseif line =~# '<%-\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
|
66
|
+
let ind = ind + &sw
|
67
|
+
endif
|
68
|
+
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
|
69
|
+
let ind = ind + &sw
|
70
|
+
endif
|
71
|
+
if cline =~# '^\s*-\=%>\s*$'
|
72
|
+
let ind = ind - &sw
|
73
|
+
endif
|
74
|
+
return ind
|
75
|
+
endfunction
|
76
|
+
|
77
|
+
" vim:set sw=2 sts=2 ts=8 noet:
|
@@ -0,0 +1,116 @@
|
|
1
|
+
"
|
2
|
+
" Copyright 2006 Tye Zdrojewski
|
3
|
+
"
|
4
|
+
" Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
5
|
+
" use this file except in compliance with the License. You may obtain a copy of
|
6
|
+
" the License at
|
7
|
+
"
|
8
|
+
" http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
"
|
10
|
+
" Unless required by applicable law or agreed to in writing, software distributed
|
11
|
+
" under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
12
|
+
" CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
13
|
+
" specific language governing permissions and limitations under the License.
|
14
|
+
"
|
15
|
+
"
|
16
|
+
"
|
17
|
+
" Script:
|
18
|
+
"
|
19
|
+
" Javascript Indentation
|
20
|
+
"
|
21
|
+
" Version: 1.1.2
|
22
|
+
"
|
23
|
+
" Description:
|
24
|
+
"
|
25
|
+
" Indentation for Javascript. This script uses the IndentAnything plugin.
|
26
|
+
"
|
27
|
+
"
|
28
|
+
" Installation:
|
29
|
+
"
|
30
|
+
" Place this file in your home directory under ~/.vim/indent/, or replace
|
31
|
+
" the system indent/javascript.vim file to affect all users.
|
32
|
+
"
|
33
|
+
" Maintainer: Tye Z. <zdro@yahoo.com>
|
34
|
+
"
|
35
|
+
"
|
36
|
+
" History:
|
37
|
+
"
|
38
|
+
" 1.1.1 - Added license
|
39
|
+
" 1.1.2 - Added indentation for [...] pairs
|
40
|
+
" 1.1.3 - Fixed silly syntax error
|
41
|
+
"
|
42
|
+
"
|
43
|
+
|
44
|
+
let IndentAnything_Dbg = 0
|
45
|
+
let IndentAnything_Dbg = 1
|
46
|
+
|
47
|
+
" Only load this indent file when no other was loaded.
|
48
|
+
if exists("b:did_indent") && ! IndentAnything_Dbg
|
49
|
+
finish
|
50
|
+
endif
|
51
|
+
|
52
|
+
let b:did_indent = 1
|
53
|
+
|
54
|
+
setlocal indentexpr=IndentAnything()
|
55
|
+
setlocal indentkeys+=0),0},),;
|
56
|
+
|
57
|
+
" Only define the function once.
|
58
|
+
if exists("*IndentAnything") && ! IndentAnything_Dbg
|
59
|
+
finish
|
60
|
+
endif
|
61
|
+
|
62
|
+
setlocal indentexpr=IndentAnything()
|
63
|
+
|
64
|
+
""" BEGIN IndentAnything specification
|
65
|
+
|
66
|
+
"
|
67
|
+
" Syntax name REs for comments and strings.
|
68
|
+
"
|
69
|
+
let b:commentRE = 'javaScript\(Line\)\?Comment'
|
70
|
+
let b:lineCommentRE = 'javaScriptLineComment'
|
71
|
+
let b:blockCommentRE = 'javaScriptComment'
|
72
|
+
let b:stringRE = 'javaScriptString\(S\|D\)'
|
73
|
+
let b:singleQuoteStringRE = 'javaScriptStringS'
|
74
|
+
let b:doubleQuoteStringRE = 'javaScriptStringD'
|
75
|
+
|
76
|
+
|
77
|
+
"
|
78
|
+
" Setup for C-style comment indentation.
|
79
|
+
"
|
80
|
+
let b:blockCommentStartRE = '/\*'
|
81
|
+
let b:blockCommentMiddleRE = '\*'
|
82
|
+
let b:blockCommentEndRE = '\*/'
|
83
|
+
let b:blockCommentMiddleExtra = 1
|
84
|
+
|
85
|
+
"
|
86
|
+
" Indent another level for each non-closed paren/'(' , bracket/'[', and
|
87
|
+
" brace/'{' on the previous line.
|
88
|
+
|
89
|
+
let b:indentTrios = [
|
90
|
+
\ [ '(', '', ')' ],
|
91
|
+
\ [ '{', '\(default:\|case.*:\)', '}' ],
|
92
|
+
\ [ '\[', '', '\]' ]
|
93
|
+
\]
|
94
|
+
|
95
|
+
|
96
|
+
"
|
97
|
+
" Line continuations. Lines that are continued on the next line are
|
98
|
+
" if/for/while statements that are NOT followed by a '{' block and operators
|
99
|
+
" at the end of a line.
|
100
|
+
"
|
101
|
+
let b:lineContList = [
|
102
|
+
\ { 'pattern' : '^\s*\(if\|for\|while\)\s*(.*)\s*\(\(//.*\)\|/\*.*\*/\s*\)\?\_$\(\_s*{\)\@!' },
|
103
|
+
\ { 'pattern' : '^\s*else' . '\s*\(\(//.*\)\|/\*.*\*/\s*\)\?\_$\(\_s*{\)\@!' },
|
104
|
+
\ { 'pattern' : '\(+\|=\|+=\|-=\)\s*\(\(//.*\)\|/\*.*\*/\s*\)\?$' }
|
105
|
+
\]
|
106
|
+
|
107
|
+
"
|
108
|
+
" If a continued line and its continuation can have line-comments between
|
109
|
+
" them, then this should be true. For example,
|
110
|
+
"
|
111
|
+
" if (x)
|
112
|
+
" // comment here
|
113
|
+
" statement
|
114
|
+
"
|
115
|
+
let b:contTraversesLineComments = 1
|
116
|
+
|
@@ -0,0 +1,377 @@
|
|
1
|
+
" Vim indent file
|
2
|
+
" Language: Ruby
|
3
|
+
" Maintainer: Nikolai Weibull <now at bitwi.se>
|
4
|
+
" URL: http://vim-ruby.rubyforge.org
|
5
|
+
" Anon CVS: See above site
|
6
|
+
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
|
7
|
+
|
8
|
+
" 0. Initialization {{{1
|
9
|
+
" =================
|
10
|
+
|
11
|
+
" Only load this indent file when no other was loaded.
|
12
|
+
if exists("b:did_indent")
|
13
|
+
finish
|
14
|
+
endif
|
15
|
+
let b:did_indent = 1
|
16
|
+
|
17
|
+
setlocal nosmartindent
|
18
|
+
|
19
|
+
" Now, set up our indentation expression and keys that trigger it.
|
20
|
+
setlocal indentexpr=GetRubyIndent()
|
21
|
+
setlocal indentkeys=0{,0},0),0],!^F,o,O,e
|
22
|
+
setlocal indentkeys+==end,=elsif,=when,=ensure,=rescue,==begin,==end
|
23
|
+
|
24
|
+
" Only define the function once.
|
25
|
+
if exists("*GetRubyIndent")
|
26
|
+
finish
|
27
|
+
endif
|
28
|
+
|
29
|
+
let s:cpo_save = &cpo
|
30
|
+
set cpo&vim
|
31
|
+
|
32
|
+
" 1. Variables {{{1
|
33
|
+
" ============
|
34
|
+
|
35
|
+
" Regex of syntax group names that are or delimit string or are comments.
|
36
|
+
let s:syng_strcom = '\<ruby\%(String\|StringEscape\|ASCIICode' .
|
37
|
+
\ '\|Interpolation\|NoInterpolation\|Comment\|Documentation\)\>'
|
38
|
+
|
39
|
+
" Regex of syntax group names that are strings.
|
40
|
+
let s:syng_string =
|
41
|
+
\ '\<ruby\%(String\|Interpolation\|NoInterpolation\|StringEscape\)\>'
|
42
|
+
|
43
|
+
" Regex of syntax group names that are strings or documentation.
|
44
|
+
let s:syng_stringdoc =
|
45
|
+
\'\<ruby\%(String\|Interpolation\|NoInterpolation\|StringEscape\|Documentation\)\>'
|
46
|
+
|
47
|
+
" Expression used to check whether we should skip a match with searchpair().
|
48
|
+
let s:skip_expr =
|
49
|
+
\ "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
|
50
|
+
|
51
|
+
" Regex used for words that, at the start of a line, add a level of indent.
|
52
|
+
let s:ruby_indent_keywords = '^\s*\zs\<\%(module\|class\|def\|if\|for' .
|
53
|
+
\ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure' .
|
54
|
+
\ '\|rescue\)\>' .
|
55
|
+
\ '\|\%([*+/,=-]\|<<\|>>\|:\s\)\s*\zs' .
|
56
|
+
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\)\>'
|
57
|
+
|
58
|
+
" Regex used for words that, at the start of a line, remove a level of indent.
|
59
|
+
let s:ruby_deindent_keywords =
|
60
|
+
\ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\)\>'
|
61
|
+
|
62
|
+
" Regex that defines the start-match for the 'end' keyword.
|
63
|
+
"let s:end_start_regex = '\%(^\|[^.]\)\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\|do\)\>'
|
64
|
+
" TODO: the do here should be restricted somewhat (only at end of line)?
|
65
|
+
let s:end_start_regex = '^\s*\zs\<\%(module\|class\|def\|if\|for' .
|
66
|
+
\ '\|while\|until\|case\|unless\|begin\)\>' .
|
67
|
+
\ '\|\%([*+/,=-]\|<<\|>>\|:\s\)\s*\zs' .
|
68
|
+
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\)\>' .
|
69
|
+
\ '\|\<do\>'
|
70
|
+
|
71
|
+
" Regex that defines the middle-match for the 'end' keyword.
|
72
|
+
let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue\>\|when\|elsif\)\>'
|
73
|
+
|
74
|
+
" Regex that defines the end-match for the 'end' keyword.
|
75
|
+
let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end\>'
|
76
|
+
|
77
|
+
" Expression used for searchpair() call for finding match for 'end' keyword.
|
78
|
+
let s:end_skip_expr = s:skip_expr .
|
79
|
+
\ ' || (expand("<cword>") == "do"' .
|
80
|
+
\ ' && getline(".") =~ "^\\s*\\<\\(while\\|until\\|for\\)\\>")'
|
81
|
+
|
82
|
+
" Regex that defines continuation lines, not including (, {, or [.
|
83
|
+
let s:continuation_regex = '\%([\\*+/.,:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
|
84
|
+
|
85
|
+
" Regex that defines continuation lines.
|
86
|
+
" TODO: this needs to deal with if ...: and so on
|
87
|
+
let s:continuation_regex2 =
|
88
|
+
\ '\%([\\*+/.,:({[]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$'
|
89
|
+
|
90
|
+
" Regex that defines blocks.
|
91
|
+
let s:block_regex =
|
92
|
+
\ '\%(\<do\>\|{\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=\s*\%(#.*\)\=$'
|
93
|
+
|
94
|
+
" 2. Auxiliary Functions {{{1
|
95
|
+
" ======================
|
96
|
+
|
97
|
+
" Check if the character at lnum:col is inside a string, comment, or is ascii.
|
98
|
+
function s:IsInStringOrComment(lnum, col)
|
99
|
+
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
|
100
|
+
endfunction
|
101
|
+
|
102
|
+
" Check if the character at lnum:col is inside a string.
|
103
|
+
function s:IsInString(lnum, col)
|
104
|
+
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
|
105
|
+
endfunction
|
106
|
+
|
107
|
+
" Check if the character at lnum:col is inside a string or documentation.
|
108
|
+
function s:IsInStringOrDocumentation(lnum, col)
|
109
|
+
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_stringdoc
|
110
|
+
endfunction
|
111
|
+
|
112
|
+
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
|
113
|
+
function s:PrevNonBlankNonString(lnum)
|
114
|
+
let in_block = 0
|
115
|
+
let lnum = prevnonblank(a:lnum)
|
116
|
+
while lnum > 0
|
117
|
+
" Go in and out of blocks comments as necessary.
|
118
|
+
" If the line isn't empty (with opt. comment) or in a string, end search.
|
119
|
+
let line = getline(lnum)
|
120
|
+
if line =~ '^=begin$'
|
121
|
+
if in_block
|
122
|
+
let in_block = 0
|
123
|
+
else
|
124
|
+
break
|
125
|
+
endif
|
126
|
+
elseif !in_block && line =~ '^=end$'
|
127
|
+
let in_block = 1
|
128
|
+
elseif !in_block && line !~ '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1)
|
129
|
+
\ && s:IsInStringOrComment(lnum, strlen(line)))
|
130
|
+
break
|
131
|
+
endif
|
132
|
+
let lnum = prevnonblank(lnum - 1)
|
133
|
+
endwhile
|
134
|
+
return lnum
|
135
|
+
endfunction
|
136
|
+
|
137
|
+
" Find line above 'lnum' that started the continuation 'lnum' may be part of.
|
138
|
+
function s:GetMSL(lnum)
|
139
|
+
" Start on the line we're at and use its indent.
|
140
|
+
let msl = a:lnum
|
141
|
+
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
142
|
+
while lnum > 0
|
143
|
+
" If we have a continuation line, or we're in a string, use line as MSL.
|
144
|
+
" Otherwise, terminate search as we have found our MSL already.
|
145
|
+
let line = getline(lnum)
|
146
|
+
let col = match(line, s:continuation_regex2) + 1
|
147
|
+
if (col > 0 && !s:IsInStringOrComment(lnum, col))
|
148
|
+
\ || s:IsInString(lnum, strlen(line))
|
149
|
+
let msl = lnum
|
150
|
+
else
|
151
|
+
break
|
152
|
+
endif
|
153
|
+
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
154
|
+
endwhile
|
155
|
+
return msl
|
156
|
+
endfunction
|
157
|
+
|
158
|
+
" Check if line 'lnum' has more opening brackets than closing ones.
|
159
|
+
function s:LineHasOpeningBrackets(lnum)
|
160
|
+
let open_0 = 0
|
161
|
+
let open_2 = 0
|
162
|
+
let open_4 = 0
|
163
|
+
let line = getline(a:lnum)
|
164
|
+
let pos = match(line, '[][(){}]', 0)
|
165
|
+
while pos != -1
|
166
|
+
if !s:IsInStringOrComment(a:lnum, pos + 1)
|
167
|
+
let idx = stridx('(){}[]', line[pos])
|
168
|
+
if idx % 2 == 0
|
169
|
+
let open_{idx} = open_{idx} + 1
|
170
|
+
else
|
171
|
+
let open_{idx - 1} = open_{idx - 1} - 1
|
172
|
+
endif
|
173
|
+
endif
|
174
|
+
let pos = match(line, '[][(){}]', pos + 1)
|
175
|
+
endwhile
|
176
|
+
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
|
177
|
+
endfunction
|
178
|
+
|
179
|
+
function s:Match(lnum, regex)
|
180
|
+
let col = match(getline(a:lnum), a:regex) + 1
|
181
|
+
return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
|
182
|
+
endfunction
|
183
|
+
|
184
|
+
function s:MatchLast(lnum, regex)
|
185
|
+
let line = getline(a:lnum)
|
186
|
+
let col = match(line, '.*\zs' . a:regex)
|
187
|
+
while col != -1 && s:IsInStringOrComment(a:lnum, col)
|
188
|
+
let line = strpart(line, 0, col)
|
189
|
+
let col = match(line, '.*' . a:regex)
|
190
|
+
endwhile
|
191
|
+
return col + 1
|
192
|
+
endfunction
|
193
|
+
|
194
|
+
" 3. GetRubyIndent Function {{{1
|
195
|
+
" =========================
|
196
|
+
|
197
|
+
function GetRubyIndent()
|
198
|
+
" 3.1. Setup {{{2
|
199
|
+
" ----------
|
200
|
+
|
201
|
+
" Set up variables for restoring position in file. Could use v:lnum here.
|
202
|
+
let vcol = col('.')
|
203
|
+
|
204
|
+
" 3.2. Work on the current line {{{2
|
205
|
+
" -----------------------------
|
206
|
+
|
207
|
+
" Get the current line.
|
208
|
+
let line = getline(v:lnum)
|
209
|
+
let ind = -1
|
210
|
+
|
211
|
+
" If we got a closing bracket on an empty line, find its match and indent
|
212
|
+
" according to it. For parentheses we indent to its column - 1, for the
|
213
|
+
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
214
|
+
let col = matchend(line, '^\s*[]})]')
|
215
|
+
if col > 0 && !s:IsInStringOrComment(v:lnum, col)
|
216
|
+
call cursor(v:lnum, col)
|
217
|
+
let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
|
218
|
+
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
|
219
|
+
if line[col-1]==')' && col('.') != col('$') - 1
|
220
|
+
let ind = virtcol('.')-1
|
221
|
+
else
|
222
|
+
let ind = indent(s:GetMSL(line('.')))
|
223
|
+
endif
|
224
|
+
endif
|
225
|
+
return ind
|
226
|
+
endif
|
227
|
+
|
228
|
+
" If we have a =begin or =end set indent to first column.
|
229
|
+
if match(line, '^\s*\%(=begin\|=end\)$') != -1
|
230
|
+
return 0
|
231
|
+
endif
|
232
|
+
|
233
|
+
" If we have a deindenting keyword, find its match and indent to its level.
|
234
|
+
" TODO: this is messy
|
235
|
+
if s:Match(v:lnum, s:ruby_deindent_keywords)
|
236
|
+
call cursor(v:lnum, 1)
|
237
|
+
if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW',
|
238
|
+
\ s:end_skip_expr) > 0
|
239
|
+
let line = getline('.')
|
240
|
+
if strpart(line, 0, col('.') - 1) =~ '=\s*$' &&
|
241
|
+
\ strpart(line, col('.') - 1, 2) !~ 'do'
|
242
|
+
let ind = virtcol('.') - 1
|
243
|
+
else
|
244
|
+
let ind = indent('.')
|
245
|
+
endif
|
246
|
+
endif
|
247
|
+
return ind
|
248
|
+
endif
|
249
|
+
|
250
|
+
" If we are in a multi-line string or line-comment, don't do anything to it.
|
251
|
+
if s:IsInStringOrDocumentation(v:lnum, matchend(line, '^\s*') + 1)
|
252
|
+
return indent('.')
|
253
|
+
endif
|
254
|
+
|
255
|
+
" 3.3. Work on the previous line. {{{2
|
256
|
+
" -------------------------------
|
257
|
+
|
258
|
+
" Find a non-blank, non-multi-line string line above the current line.
|
259
|
+
let lnum = s:PrevNonBlankNonString(v:lnum - 1)
|
260
|
+
|
261
|
+
" If the line is empty and inside a string, use the previous line.
|
262
|
+
if line =~ '^\s*$' && lnum != prevnonblank(v:lnum - 1)
|
263
|
+
return indent(prevnonblank(v:lnum))
|
264
|
+
endif
|
265
|
+
|
266
|
+
" At the start of the file use zero indent.
|
267
|
+
if lnum == 0
|
268
|
+
return 0
|
269
|
+
endif
|
270
|
+
|
271
|
+
" Set up variables for current line.
|
272
|
+
let line = getline(lnum)
|
273
|
+
let ind = indent(lnum)
|
274
|
+
|
275
|
+
" If the previous line ended with a block opening, add a level of indent.
|
276
|
+
if s:Match(lnum, s:block_regex)
|
277
|
+
return indent(s:GetMSL(lnum)) + &sw
|
278
|
+
endif
|
279
|
+
|
280
|
+
" If the previous line contained an opening bracket, and we are still in it,
|
281
|
+
" add indent depending on the bracket type.
|
282
|
+
if line =~ '[[({]'
|
283
|
+
let counts = s:LineHasOpeningBrackets(lnum)
|
284
|
+
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
285
|
+
if col('.') + 1 == col('$')
|
286
|
+
return ind + &sw
|
287
|
+
else
|
288
|
+
return virtcol('.')
|
289
|
+
endif
|
290
|
+
elseif counts[1] == '1' || counts[2] == '1'
|
291
|
+
return ind + &sw
|
292
|
+
else
|
293
|
+
call cursor(v:lnum, vcol)
|
294
|
+
end
|
295
|
+
endif
|
296
|
+
|
297
|
+
" If the previous line ended with an "end", match that "end"s beginning's
|
298
|
+
" indent.
|
299
|
+
let col = s:Match(lnum, '\%(^\|[^.:@$]\)\<end\>\s*\%(#.*\)\=$')
|
300
|
+
if col > 0
|
301
|
+
call cursor(lnum, col)
|
302
|
+
if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW',
|
303
|
+
\ s:end_skip_expr) > 0
|
304
|
+
let n = line('.')
|
305
|
+
let ind = indent('.')
|
306
|
+
let msl = s:GetMSL(n)
|
307
|
+
if msl != n
|
308
|
+
let ind = indent(msl)
|
309
|
+
end
|
310
|
+
return ind
|
311
|
+
endif
|
312
|
+
end
|
313
|
+
|
314
|
+
let col = s:Match(lnum, s:ruby_indent_keywords)
|
315
|
+
if col > 0
|
316
|
+
call cursor(lnum, col)
|
317
|
+
let ind = virtcol('.') - 1 + &sw
|
318
|
+
" let ind = indent(lnum) + &sw
|
319
|
+
" TODO: make this better (we need to count them) (or, if a searchpair
|
320
|
+
" fails, we know that something is lacking an end and thus we indent a
|
321
|
+
" level
|
322
|
+
if s:Match(lnum, s:end_end_regex)
|
323
|
+
let ind = indent('.')
|
324
|
+
endif
|
325
|
+
return ind
|
326
|
+
endif
|
327
|
+
|
328
|
+
" 3.4. Work on the MSL line. {{{2
|
329
|
+
" --------------------------
|
330
|
+
|
331
|
+
" Set up variables to use and search for MSL to the previous line.
|
332
|
+
let p_lnum = lnum
|
333
|
+
let lnum = s:GetMSL(lnum)
|
334
|
+
|
335
|
+
" If the previous line wasn't a MSL and is continuation return its indent.
|
336
|
+
" TODO: the || s:IsInString() thing worries me a bit.
|
337
|
+
if p_lnum != lnum
|
338
|
+
if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line))
|
339
|
+
return ind
|
340
|
+
endif
|
341
|
+
endif
|
342
|
+
|
343
|
+
" Set up more variables, now that we know we wasn't continuation bound.
|
344
|
+
let line = getline(lnum)
|
345
|
+
let msl_ind = indent(lnum)
|
346
|
+
|
347
|
+
" If the MSL line had an indenting keyword in it, add a level of indent.
|
348
|
+
" TODO: this does not take into account contrived things such as
|
349
|
+
" module Foo; class Bar; end
|
350
|
+
if s:Match(lnum, s:ruby_indent_keywords)
|
351
|
+
let ind = msl_ind + &sw
|
352
|
+
if s:Match(lnum, s:end_end_regex)
|
353
|
+
let ind = ind - &sw
|
354
|
+
endif
|
355
|
+
return ind
|
356
|
+
endif
|
357
|
+
|
358
|
+
" If the previous line ended with [*+/.-=], indent one extra level.
|
359
|
+
if s:Match(lnum, s:continuation_regex)
|
360
|
+
if lnum == p_lnum
|
361
|
+
let ind = msl_ind + &sw
|
362
|
+
else
|
363
|
+
let ind = msl_ind
|
364
|
+
endif
|
365
|
+
endif
|
366
|
+
|
367
|
+
" }}}2
|
368
|
+
|
369
|
+
return ind
|
370
|
+
endfunction
|
371
|
+
|
372
|
+
" }}}1
|
373
|
+
|
374
|
+
let &cpo = s:cpo_save
|
375
|
+
unlet s:cpo_save
|
376
|
+
|
377
|
+
" vim:set sw=2 sts=2 ts=8 noet:
|