diff options
Diffstat (limited to 'runtime/indent')
-rw-r--r-- | runtime/indent/ada.vim | 8 | ||||
-rw-r--r-- | runtime/indent/bst.vim | 2 | ||||
-rw-r--r-- | runtime/indent/cmake.vim | 10 | ||||
-rw-r--r-- | runtime/indent/cobol.vim | 2 | ||||
-rw-r--r-- | runtime/indent/cpp.vim | 4 | ||||
-rw-r--r-- | runtime/indent/cuda.vim | 15 | ||||
-rw-r--r-- | runtime/indent/eiffel.vim | 4 | ||||
-rw-r--r-- | runtime/indent/eruby.vim | 2 | ||||
-rw-r--r-- | runtime/indent/gitconfig.vim | 4 | ||||
-rw-r--r-- | runtime/indent/mail.vim | 13 | ||||
-rw-r--r-- | runtime/indent/php.vim | 85 | ||||
-rw-r--r-- | runtime/indent/ruby.vim | 2 | ||||
-rw-r--r-- | runtime/indent/sh.vim | 138 | ||||
-rw-r--r-- | runtime/indent/xml.vim | 14 |
14 files changed, 206 insertions, 97 deletions
diff --git a/runtime/indent/ada.vim b/runtime/indent/ada.vim index e56aaffecf..a9b461ccc5 100644 --- a/runtime/indent/ada.vim +++ b/runtime/indent/ada.vim @@ -1,15 +1,15 @@ "------------------------------------------------------------------------------ " Description: Vim Ada indent file " Language: Ada (2005) -" $Id$ +" $Id: ada.vim 887 2008-07-08 14:29:01Z krischik $ " Copyright: Copyright (C) 2006 Martin Krischik " Maintainer: Martin Krischik <krischik@users.sourceforge.net> " Neil Bird <neil@fnxweb.com> " Ned Okie <nokie@radford.edu> -" $Author$ -" $Date$ +" $Author: krischik $ +" $Date: 2008-07-08 16:29:01 +0200 (Di, 08 Jul 2008) $ " Version: 4.6 -" $Revision$ +" $Revision: 887 $ " $HeadURL: https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/tools/vim/indent/ada.vim $ " History: 24.05.2006 MK Unified Headers " 16.07.2006 MK Ada-Mode as vim-ball diff --git a/runtime/indent/bst.vim b/runtime/indent/bst.vim index 5933d80673..be1f63e8e9 100644 --- a/runtime/indent/bst.vim +++ b/runtime/indent/bst.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: bst " Author: Tim Pope <vimNOSPAM@tpope.info> -" $Id$ +" $Id: bst.vim,v 1.1 2007/05/05 18:11:12 vimboss Exp $ if exists("b:did_indent") finish diff --git a/runtime/indent/cmake.vim b/runtime/indent/cmake.vim index b54a8d87a2..4315ad23af 100644 --- a/runtime/indent/cmake.vim +++ b/runtime/indent/cmake.vim @@ -1,10 +1,10 @@ " ============================================================================= " " Program: CMake - Cross-Platform Makefile Generator -" Module: $RCSfile$ +" Module: $RCSfile: cmake-indent.vim,v $ " Language: VIM -" Date: $Date$ -" Version: $Revision$ +" Date: $Date: 2006/09/23 21:09:08 $ +" Version: $Revision: 1.7 $ " " ============================================================================= @@ -12,8 +12,8 @@ " Language: CMake (ft=cmake) " Author: Andy Cedilnik <andy.cedilnik@kitware.com> " Maintainer: Andy Cedilnik <andy.cedilnik@kitware.com> -" Last Change: $Date$ -" Version: $Revision$ +" Last Change: $Date: 2006/09/23 21:09:08 $ +" Version: $Revision: 1.7 $ " " Licence: The CMake license applies to this file. See " http://www.cmake.org/HTML/Copyright.html diff --git a/runtime/indent/cobol.vim b/runtime/indent/cobol.vim index 9ed8a470ed..8dce3cd014 100644 --- a/runtime/indent/cobol.vim +++ b/runtime/indent/cobol.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: cobol " Author: Tim Pope <vimNOSPAM@tpope.info> -" $Id$ +" $Id: cobol.vim,v 1.1 2007/05/05 18:08:19 vimboss Exp $ if exists("b:did_indent") finish diff --git a/runtime/indent/cpp.vim b/runtime/indent/cpp.vim index 9ae126ac4d..ffa37d7208 100644 --- a/runtime/indent/cpp.vim +++ b/runtime/indent/cpp.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: C++ " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2001 Jun 12 +" Last Change: 2008 Nov 29 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -11,3 +11,5 @@ let b:did_indent = 1 " C++ indenting is built-in, thus this is very simple setlocal cindent + +let b:undo_indent = "setl cin<" diff --git a/runtime/indent/cuda.vim b/runtime/indent/cuda.vim new file mode 100644 index 0000000000..68ee9cec0c --- /dev/null +++ b/runtime/indent/cuda.vim @@ -0,0 +1,15 @@ +" Vim indent file +" Language: CUDA +" Maintainer: Bram Moolenaar <Bram@vim.org> +" Last Change: 2008 Nov 29 + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" It's just like C indenting +setlocal cindent + +let b:undo_indent = "setl cin<" diff --git a/runtime/indent/eiffel.vim b/runtime/indent/eiffel.vim index 895945939e..db66bf8fea 100644 --- a/runtime/indent/eiffel.vim +++ b/runtime/indent/eiffel.vim @@ -2,8 +2,8 @@ " Language: Eiffel " Maintainer: Jocelyn Fiat <eiffel@djoce.net> " Previous-Maintainer: David Clarke <gadicath@dishevelled.net> -" $Date$ -" $Revision$ +" $Date: 2004/12/09 21:33:52 $ +" $Revision: 1.3 $ " URL: http://www.djoce.net/page/vim/ " Last Change: 2004 Sept 14 : removed specific value for tab (sw) diff --git a/runtime/indent/eruby.vim b/runtime/indent/eruby.vim index 31cbb8b011..931eaac385 100644 --- a/runtime/indent/eruby.vim +++ b/runtime/indent/eruby.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: eRuby " Maintainer: Tim Pope <vimNOSPAM@tpope.info> -" Info: $Id$ +" Info: $Id: eruby.vim,v 1.16 2008/06/29 04:18:43 tpope Exp $ " URL: http://vim-ruby.rubyforge.org " Anon CVS: See above site " Release Coordinator: Doug Kearns <dougkearns@gmail.com> diff --git a/runtime/indent/gitconfig.vim b/runtime/indent/gitconfig.vim index 7ce0c715bd..28d95b7cd2 100644 --- a/runtime/indent/gitconfig.vim +++ b/runtime/indent/gitconfig.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: git config file -" Maintainer: Tim Pope <vimNOSPAM@tpope.info> -" Last Change: 2008 Jun 04 +" Maintainer: Tim Pope <vimNOSPAM@tpope.org> +" Last Change: 2009 Dec 24 if exists("b:did_indent") finish diff --git a/runtime/indent/mail.vim b/runtime/indent/mail.vim new file mode 100644 index 0000000000..6246b407e9 --- /dev/null +++ b/runtime/indent/mail.vim @@ -0,0 +1,13 @@ +" Vim indent file +" Language: Mail +" Maintainer: Bram Moolenaar +" Last Change: 2009 Jun 03 + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" What works best is auto-indenting, disable other indenting. +" For formatting see the ftplugin. +setlocal autoindent nosmartindent nocindent indentexpr= diff --git a/runtime/indent/php.vim b/runtime/indent/php.vim index 6124eb2f66..9f1a1ed9d3 100644 --- a/runtime/indent/php.vim +++ b/runtime/indent/php.vim @@ -2,17 +2,10 @@ " Language: PHP " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> " URL: http://www.2072productions.com/vim/indent/php.vim -" Last Change: 2008 June 7th +" Last Change: 2008 November 22nd " Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php -" Version: 1.28 +" Version: 1.30 " -" 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. -" -" ---> 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. " " 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. @@ -24,7 +17,7 @@ " NOTE: This script must be used with PHP syntax ON and with the php syntax " script by Lutz Eymers (http://www.isp.de/data/php.vim ) or with the " script by Peter Hodge (http://www.vim.org/scripts/script.php?script_id=1571 ) -" the later is bunbdled by default with vim 7. +" the later is bunbdled by default with Vim 7. " " " In the case you have syntax errors in your script such as HereDoc end @@ -33,50 +26,19 @@ " they are followed by a ';'). " " -" 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 -" '\s*$' correctly. -" So you have to remove those useless characters first with a command like: -" -" :%s /\r$//g -" -" 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. +" NOTE: If you are editing files 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 +" '\s*$' correctly. +" So you have to remove those useless characters first with a command like: " -" Options: PHP_default_indenting = # of sw (default is 0), # of sw will be -" added to the indent of each line of PHP code. +" :%s /\r$//g " -" 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! -" -" 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) -" { -" foo(); -" } -" -" NOTE: The script will be a bit slower if you use this option because -" some optimizations won't be available. -" -" Options: PHP_vintage_case_default_indent = 1 (defaults to 0) to add a meaningless indent -" befaore 'case:' and 'default":' statement in switch block +" 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: See :help php-indent for available options. + if exists("b:did_indent") finish @@ -145,6 +107,7 @@ if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUn endif if exists("*GetPhpIndent") + call ResetPhpOptions() finish " XXX endif @@ -317,14 +280,13 @@ endfunction " }}} let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|else\)' let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\)' -let s:autorestoptions = 0 -if ! s:autorestoptions - au BufWinEnter,Syntax *.php,*.php3,*.php4,*.php5 call ResetOptions() - let s:autorestoptions = 1 +let s:autoresetoptions = 0 +if ! s:autoresetoptions + let s:autoresetoptions = 1 endif -function! ResetOptions() - if ! b:optionsset +function! ResetPhpOptions() + if ! b:optionsset && &filetype == "php" if b:PHP_autoformatcomment setlocal comments=s1:/*,mb:*,ex:*/,://,:# @@ -341,6 +303,8 @@ function! ResetOptions() endif endfunc +call ResetPhpOptions() + function! GetPhpIndent() let b:GetLastRealCodeLNum_ADD = 0 @@ -360,7 +324,7 @@ function! GetPhpIndent() if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast if b:PHP_indentbeforelast let b:PHP_indentinghuge = 1 - echom 'Large indenting detected, speed optimizations engaged (v1.28)' + echom 'Large indenting detected, speed optimizations engaged (v1.30)' endif let b:PHP_indentbeforelast = b:PHP_lastindented endif @@ -693,6 +657,7 @@ function! GetPhpIndent() if !LastLineClosed + if last_line =~# '[{(]'.endline || last_line =~? '\h\w*\s*(.*,$' && pline !~ '[,(]'.endline if !b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{' @@ -715,11 +680,11 @@ function! GetPhpIndent() elseif last_line =~ '^\s*'.s:blockstart let ind = ind + &sw - elseif last_line =~# defaultORcase + elseif last_line =~# defaultORcase && cline !~# defaultORcase let ind = ind + &sw - elseif pline =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . defaultORcase + elseif pline =~ '\%(;\%(\s*?>\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . defaultORcase && cline !~# defaultORcase let ind = ind + &sw endif diff --git a/runtime/indent/ruby.vim b/runtime/indent/ruby.vim index 8a56e54c07..4a3012f94f 100644 --- a/runtime/indent/ruby.vim +++ b/runtime/indent/ruby.vim @@ -1,7 +1,7 @@ " Vim indent file " Language: Ruby " Maintainer: Nikolai Weibull <now at bitwi.se> -" Info: $Id$ +" Info: $Id: ruby.vim,v 1.47 2008/06/29 04:18:43 tpope Exp $ " URL: http://vim-ruby.rubyforge.org " Anon CVS: See above site " Release Coordinator: Doug Kearns <dougkearns@gmail.com> diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim index 483e5430ec..49146c7e37 100644 --- a/runtime/indent/sh.vim +++ b/runtime/indent/sh.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: Shell Script +" Language: Shell Script " Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-04-19 +" Latest Revision: 2010-01-06 if exists("b:did_indent") finish @@ -9,8 +9,10 @@ endif let b:did_indent = 1 setlocal indentexpr=GetShIndent() -setlocal indentkeys+==then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done +setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,),0=;;,0=;& +setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix setlocal indentkeys-=:,0# +setlocal nosmartindent if exists("*GetShIndent") finish @@ -19,34 +21,138 @@ endif let s:cpo_save = &cpo set cpo&vim -function GetShIndent() +function s:buffer_shiftwidth() + return &shiftwidth +endfunction + +let s:sh_indent_defaults = { + \ 'default': function('s:buffer_shiftwidth'), + \ 'continuation-line': function('s:buffer_shiftwidth'), + \ 'case-labels': function('s:buffer_shiftwidth'), + \ 'case-statements': function('s:buffer_shiftwidth'), + \ 'case-breaks': 0 } + +function! s:indent_value(option) + let Value = exists('b:sh_indent_options') + \ && has_key(b:sh_indent_options, a:option) ? + \ b:sh_indent_options[a:option] : + \ s:sh_indent_defaults[a:option] + if type(Value) == type(function('type')) + return Value() + endif + return Value +endfunction + +function! GetShIndent() let lnum = prevnonblank(v:lnum - 1) if lnum == 0 return 0 endif - " Add a 'shiftwidth' after if, while, else, case, until, for, function() - " Skip if the line also contains the closure for the above + let pnum = prevnonblank(lnum - 1) + let ind = indent(lnum) let line = getline(lnum) - if line =~ '^\s*\(if\|then\|do\|else\|elif\|case\|while\|until\|for\)\>' - \ || line =~ '^\s*\<\k\+\>\s*()\s*{' - \ || line =~ '^\s*{' - if line !~ '\(esac\|fi\|done\)\>\s*$' && line !~ '}\s*$' - let ind = ind + &sw + if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\)\>' + if line !~ '\<\%(fi\|esac\|done\)\>\s*\%(#.*\)\=$' + let ind += s:indent_value('default') + endif + elseif s:is_case_label(line, pnum) + if !s:is_case_ended(line) + let ind += s:indent_value('case-statements') endif + elseif line =~ '^\s*\<\k\+\>\s*()\s*{' || line =~ '^\s*{' + if line !~ '}\s*\%(#.*\)\=$' + let ind += s:indent_value('default') + endif + elseif s:is_continuation_line(line) + if pnum == 0 || !s:is_continuation_line(getline(pnum)) + let ind += s:indent_value('continuation-line') + endif + elseif pnum != 0 && s:is_continuation_line(getline(pnum)) + let ind = indent(s:find_continued_lnum(pnum)) endif - " Subtract a 'shiftwidth' on a then, do, else, esac, fi, done - " Retain the indentation level if line matches fin (for find) + let pine = line let line = getline(v:lnum) - if (line =~ '^\s*\(then\|do\|else\|elif\|esac\|fi\|done\)\>' || line =~ '^\s*}') - \ && line !~ '^\s*fi[ln]\>' - let ind = ind - &sw + if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\)\>' || line =~ '^\s*}' + let ind -= s:indent_value('default') + elseif line =~ '^\s*esac\>' + let ind -= (s:is_case_label(pine, lnum) && s:is_case_ended(pine) ? + \ 0 : s:indent_value('case-statements')) + + \ s:indent_value('case-labels') + if s:is_case_break(pine) + let ind += s:indent_value('case-breaks') + endif + elseif s:is_case_label(line, lnum) + if s:is_case(pine) + let ind = indent(lnum) + s:indent_value('case-labels') + else + let ind -= s:indent_value('case-statements') - s:indent_value('case-breaks') + endif + elseif s:is_case_break(line) + let ind -= s:indent_value('case-breaks') endif return ind endfunction +function! s:is_continuation_line(line) + return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\)$' +endfunction + +function! s:find_continued_lnum(lnum) + let i = a:lnum + while i > 1 && s:is_continuation_line(getline(i - 1)) + let i -= 1 + endwhile + return i +endfunction + +function! s:is_case_label(line, pnum) + if a:line !~ '^\s*(\=.*)' + return 0 + endif + + if a:pnum > 0 + let pine = getline(a:pnum) + if !(s:is_case(pine) || s:is_case_ended(pine)) + return 0 + endif + endif + + let suffix = substitute(a:line, '^\s*(\=', "", "") + let nesting = 0 + let i = 0 + let n = strlen(suffix) + while i < n + let c = suffix[i] + let i += 1 + if c == '\\' + let i += 1 + elseif c == '(' + let nesting += 1 + elseif c == ')' + if nesting == 0 + return 1 + endif + let nesting -= 1 + endif + endwhile + return 0 +endfunction + +function! s:is_case(line) + return a:line =~ '^\s*case\>' +endfunction + +function! s:is_case_break(line) + return a:line =~ '^\s*;[;&]' +endfunction + +function! s:is_case_ended(line) + return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$' +endfunction + let &cpo = s:cpo_save unlet s:cpo_save diff --git a/runtime/indent/xml.vim b/runtime/indent/xml.vim index 340981b3dd..4ac35b6af1 100644 --- a/runtime/indent/xml.vim +++ b/runtime/indent/xml.vim @@ -1,10 +1,11 @@ " Language: xml " Maintainer: Johannes Zellner <johannes@zellner.org> -" Last Change: Tue, 27 Apr 2004 14:54:59 CEST +" Last Change: 2009-05-26 00:17:25 " Notes: 1) does not indent pure non-xml code (e.g. embedded scripts) " 2) will be confused by unbalanced tags in comments " or CDATA sections. -" TODO: implement pre-like tags, see xml_indent_open / xml_indent_close +" 2009-05-26 patch by Nikolai Weibull +" TODO: implement pre-like tags, see xml_indent_open / xml_indent_close " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -46,6 +47,9 @@ fun! <SID>XmlIndentSynCheck(lnum) if '' != syn1 && syn1 !~ 'xml' && '' != syn2 && syn2 !~ 'xml' " don't indent pure non-xml code return 0 + elseif syn1 =~ '^xmlComment' && syn2 =~ '^xmlComment' + " indent comments specially + return -1 endif endif return 1 @@ -74,8 +78,12 @@ fun! XmlIndentGet(lnum, use_syntax_check) endif if a:use_syntax_check - if 0 == <SID>XmlIndentSynCheck(lnum) || 0 == <SID>XmlIndentSynCheck(a:lnum) + let check_lnum = <SID>XmlIndentSynCheck(lnum) + let check_alnum = <SID>XmlIndentSynCheck(a:lnum) + if 0 == check_lnum || 0 == check_alnum return indent(a:lnum) + elseif -1 == check_lnum || -1 == check_alnum + return -1 endif endif |