diff options
Diffstat (limited to 'runtime/indent')
-rw-r--r-- | runtime/indent/d.vim | 22 | ||||
-rw-r--r-- | runtime/indent/eruby.vim | 8 | ||||
-rw-r--r-- | runtime/indent/php.vim | 101 | ||||
-rw-r--r-- | runtime/indent/ruby.vim | 53 |
4 files changed, 110 insertions, 74 deletions
diff --git a/runtime/indent/d.vim b/runtime/indent/d.vim new file mode 100644 index 000000000..b5dd5e8fa --- /dev/null +++ b/runtime/indent/d.vim @@ -0,0 +1,22 @@ +" Vim indent file for the D programming language (version 0.137). +" +" Language: D +" Maintainer: Jason Mills<jmills@cs.mun.ca> +" Last Change: 2005 Nov 22 +" Version: 0.1 +" +" Please email me with bugs, comments, and suggestion. Put vim in the subject +" to ensure the email will not be marked has spam. +" + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif + +let b:did_indent = 1 + +" D indenting is a lot like the built-in C indenting. +setlocal cindent + +" vim: ts=8 noet diff --git a/runtime/indent/eruby.vim b/runtime/indent/eruby.vim index 81f7c1aeb..b62a0245f 100644 --- a/runtime/indent/eruby.vim +++ b/runtime/indent/eruby.vim @@ -2,14 +2,8 @@ " Language: Ruby " Maintainer: Doug Kearns <djkea2 at gus.gscit.monash.edu.au> " Info: $Id$ -" URL: http://vim-ruby.rubyforge.org/ +" 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. " ---------------------------------------------------------------------------- " Only load this indent file when no other was loaded. diff --git a/runtime/indent/php.vim b/runtime/indent/php.vim index 22210cee7..8d05b03b0 100644 --- a/runtime/indent/php.vim +++ b/runtime/indent/php.vim @@ -2,17 +2,19 @@ " Language: PHP " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> " URL: http://www.2072productions.com/vim/indent/php.vim -" Last Change: 2005 September 22th -" Version: 1.181 +" Last Change: 2005 Nobember 21st +" Version: 1.20 " -" The change log and all the comments have been removed from this file. +" The change log and all the comments have been removed from this file. " -" For a complete change log and fully commented code, download the script on -" 2072productions.com at the URI provided above. +" For a complete change log and fully commented code, download the script on +" 2072productions.com at the URI provided above. +" +" If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr +" with an example of code that break the algorithm. " " -" If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr -" with an example of code that breaks the algorithm. +" Thanks a lot for using this script. " " " NOTE: This script must be used with PHP syntax ON and with the php syntax @@ -23,6 +25,7 @@ " tags not at col 1 you'll have to indent your file 2 times (This script " will automatically put HereDoc end tags at col 1). " +" " NOTE: If you are editing file in Unix file format and that (by accident) " there are '\r' before new lines, this script won't be able to proceed " correctly and will make many mistakes because it won't be able to match @@ -34,31 +37,36 @@ " or simply 'let' the option PHP_removeCRwhenUnix to 1 and the script will " silently remove them when VIM load this script (at each bufread). + +" Options: PHP_autoformatcomment = 0 to not enable autoformating of comment by +" default, if set to 0, this script will let the 'formatoptions' setting intact. +" " Options: PHP_default_indenting = # of sw (default is 0), # of sw will be -" added to the indent of each line of PHP code. +" added to the indent of each line of PHP code. " " Options: PHP_removeCRwhenUnix = 1 to make the script automatically remove CR -" at end of lines (by default this option is unset), NOTE that you -" MUST remove CR when the fileformat is UNIX else the indentation -" won't be correct... +" at end of lines (by default this option is unset), NOTE that you +" MUST remove CR when the fileformat is UNIX else the indentation +" won't be correct... " " Options: PHP_BracesAtCodeLevel = 1 to indent the '{' and '}' at the same -" level than the code they contain. -" Exemple: -" Instead of: -" if ($foo) -" { -" foo(); -" } -" -" You will write: -" if ($foo) +" level than the code they contain. +" Exemple: +" Instead of: +" if ($foo) " { -" foo(); +" foo(); " } " -" NOTE: The script will be a bit slower if you use this option because -" some optimizations won't be available. +" You will write: +" if ($foo) +" { +" foo(); +" } +" +" NOTE: The script will be a bit slower if you use this option because +" some optimizations won't be available. + if exists("b:did_indent") @@ -82,6 +90,11 @@ else let b:PHP_BracesAtCodeLevel = 0 endif +if exists("PHP_autoformatcomment") + let b:PHP_autoformatcomment = PHP_autoformatcomment +else + let b:PHP_autoformatcomment = 1 +endif let b:PHP_lastindented = 0 let b:PHP_indentbeforelast = 0 @@ -114,12 +127,12 @@ if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUn endif if exists("*GetPhpIndent") - finish " XXX + finish " XXX endif let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!' -"setlocal debug=msg " XXX +" setlocal debug=msg " XXX function! GetLastRealCodeLNum(startline) " {{{ @@ -141,7 +154,7 @@ function! GetLastRealCodeLNum(startline) " {{{ if lastline !~ '^\*/' call search('\*/', 'W') endif - let lnum = searchpair('/\*', '', '\*/', s:searchpairflags) + let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') let lastline = getline(lnum) if lastline =~ '^\s*/\*' @@ -184,6 +197,17 @@ function! GetLastRealCodeLNum(startline) " {{{ return lnum endfunction " }}} +function! Skippmatch2() + + let line = getline(".") + + if line =~ '\%(".*\)\@<=/\*\%(.*"\)\@=' || line =~ '\%(//.*\)\@<=/\*' + return 1 + else + return 0 + endif +endfun + function! Skippmatch() " {{{ let synname = synIDattr(synID(line("."), col("."), 0), "name") if synname == "Delimiter" || synname == "phpParent" || synname == "javaScriptBraces" || synname == "phpComment" && b:UserIsTypingComment @@ -245,7 +269,7 @@ function! IslinePHP (lnum, tofind) " {{{ let cline = getline(a:lnum) if a:tofind=="" - let tofind = "^\\s*[\"']*\s*\\zs\\S" + let tofind = "^\\s*[\"']*\\s*\\zs\\S" else let tofind = a:tofind endif @@ -264,17 +288,28 @@ function! IslinePHP (lnum, tofind) " {{{ endfunction " }}} let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\);' -let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|class\>\|[|&]\)' +let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|[|&]\)' let s:autorestoptions = 0 if ! s:autorestoptions - au BufWinEnter,Syntax *.php,*.php3,*.php4,*.php5 call ResetOptions() + au BufWinEnter,Syntax *.php,*.php3,*.php4,*.php5 call ResetOptions() let s:autorestoptions = 1 endif function! ResetOptions() if ! b:optionsset - setlocal formatoptions=qroc + if b:PHP_autoformatcomment + + setlocal comments=s1:/*,mb:*,ex:*/,://,:# + + setlocal formatoptions-=t + setlocal formatoptions+=q + setlocal formatoptions+=r + setlocal formatoptions+=o + setlocal formatoptions+=w + setlocal formatoptions+=c + setlocal formatoptions+=b + endif let b:optionsset = 1 endif endfunc @@ -376,7 +411,7 @@ function! GetPhpIndent() if cline !~ '^\*/' call search('\*/', 'W') endif - let lnum = searchpair('/\*', '', '\*/', s:searchpairflags) + let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') let b:PHP_CurrentIndentLevel = b:PHP_default_indenting @@ -493,7 +528,7 @@ function! GetPhpIndent() if cline !~ '^\*/' call search('\*/', 'W') endif - let lnum = searchpair('/\*', '', '\*/', s:searchpairflags) + let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') let b:PHP_CurrentIndentLevel = b:PHP_default_indenting diff --git a/runtime/indent/ruby.vim b/runtime/indent/ruby.vim index e5946ebc8..5d48a798c 100644 --- a/runtime/indent/ruby.vim +++ b/runtime/indent/ruby.vim @@ -1,16 +1,10 @@ " Vim indent file -" 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. +" 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 " ---------------------------------------------------------------------------- " 0. Initialization {{{1 @@ -42,17 +36,13 @@ set cpo&vim 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\)\>' + \ '\<ruby\%(String\|StringDelimiter\|Interpolation\|NoInterpolation\|Escape\)\>' " Regex of syntax group names that are strings or documentation. let s:syng_stringdoc = - \'\<ruby\%(String\|Interpolation\|NoInterpolation\|Escape\|Documentation\)\>' + \'\<ruby\%(String\|StringDelimiter\|Interpolation\|NoInterpolation\|Escape\|Documentation\)\>' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = @@ -109,11 +99,6 @@ 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 @@ -134,14 +119,14 @@ function s:PrevNonBlankNonString(lnum) let line = getline(lnum) if line =~ '^=begin$' if in_block - let in_block = 0 + let in_block = 0 else - break + 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))) + \ && s:IsInStringOrComment(lnum, strlen(line))) break endif let lnum = prevnonblank(lnum - 1) @@ -160,7 +145,7 @@ function s:GetMSL(lnum) let line = getline(lnum) let col = match(line, s:continuation_regex2) + 1 if (col > 0 && !s:IsInStringOrComment(lnum, col)) - \ || s:IsInString(lnum, strlen(line)) + \ || s:IsInString(lnum, strlen(line)) let msl = lnum else break @@ -181,9 +166,9 @@ function s:LineHasOpeningBrackets(lnum) if !s:IsInStringOrComment(a:lnum, pos + 1) let idx = stridx('(){}[]', line[pos]) if idx % 2 == 0 - let open_{idx} = open_{idx} + 1 + let open_{idx} = open_{idx} + 1 else - let open_{idx - 1} = open_{idx - 1} - 1 + let open_{idx - 1} = open_{idx - 1} - 1 endif endif let pos = match(line, '[][(){}]', pos + 1) @@ -246,13 +231,13 @@ function GetRubyIndent() if s:Match(v:lnum, s:ruby_deindent_keywords) 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 + \ s:end_skip_expr) > 0 let line = getline('.') if strpart(line, 0, col('.') - 1) =~ '=\s*$' && \ strpart(line, col('.') - 1, 2) !~ 'do' - let ind = virtcol('.') - 1 + let ind = virtcol('.') - 1 else - let ind = indent('.') + let ind = indent('.') endif endif return ind @@ -302,12 +287,12 @@ function GetRubyIndent() if col > 0 call cursor(lnum, col) if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW', - \ s:end_skip_expr) > 0 + \ s:end_skip_expr) > 0 let n = line('.') let ind = indent('.') let msl = s:GetMSL(n) if msl != n - let ind = indent(msl) + let ind = indent(msl) end return ind endif |