同步操作将从 bearxup/vim of ma6174 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
"============================================================================="" FileName: python.vim" Desc: 修改了缩进的bug"" Author: dantezhu - http://www.vimer.cn" Email: zny2008@gmail.com"" Created: 2011年02月21日 23:55:50" Version: 0.0.9" History:" 0.0.9 | dantezhu | 2011年03月15日 10:15:05 | 注释和string不缩进" 0.0.8 | dantezhu | 2011年03月10日 18:41:15 | 之前修正的有点问题" 0.0.7 | dantezhu | 2011年03月10日 11:06:01 | 向cindent看齐,函数名" | 太短则和匹配的地方对齐" 0.0.6 | dantezhu | 2011年02月26日 23:45:18 | 只约束是字母太弱了," | 还有数字和下划线" 0.0.5 | dantezhu | 2011年02月26日 23:28:16 | 修正对调用函数时,多" | 行参数的)的缩进" 0.0.4 | dantezhu | 2011年02月24日 19:32:14 | 之前的fix有问题,重写" 0.0.3 | dantezhu | 2011年02月22日 14:53:40 | 修正了Comment或者" | String中存在:时就会缩" | 进的问题" 0.0.2 | dantezhu | 2011年02月22日 01:15:53 | 增加了对class,if,elif" | 等的兼容" 0.0.1 | dantezhu | 2011年02月21日 23:55:50 | initialization""=============================================================================" Python indent file" Language: Python" Maintainer: Eric Mc Sween <em@tomcom.de>" Original Author: David Bustos <bustos@caltech.edu>" Last Change: 2004 Jun 07" Only load this indent file when no other was loaded.if exists("b:did_indent")finishendiflet b:did_indent = 1setlocal expandtabsetlocal nolispsetlocal autoindentsetlocal indentexpr=GetPythonIndent(v:lnum)setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=exceptlet s:maxoff = 50" Find backwards the closest open parenthesis/bracket/brace.function! s:SearchParensPair()let line = line('.')let col = col('.')" Skip strings and comments and don't look too farlet skip = "line('.') < " . (line - s:maxoff) . " ? dummy :" .\ 'synIDattr(synID(line("."), col("."), 0), "name") =~? ' .\ '"string\\|comment"'" Search for parenthesescall cursor(line, col)let parlnum = searchpair('(', '', ')', 'bW', skip)let parcol = col('.')" Search for bracketscall cursor(line, col)let par2lnum = searchpair('\[', '', '\]', 'bW', skip)let par2col = col('.')" Search for bracescall cursor(line, col)let par3lnum = searchpair('{', '', '}', 'bW', skip)let par3col = col('.')" Get the closest matchif par2lnum > parlnum || (par2lnum == parlnum && par2col > parcol)let parlnum = par2lnumlet parcol = par2colendifif par3lnum > parlnum || (par3lnum == parlnum && par3col > parcol)let parlnum = par3lnumlet parcol = par3colendif" Put the cursor on the matchif parlnum > 0call cursor(parlnum, parcol)endifreturn parlnumendfunction" Find the start of a multi-line statementfunction! s:StatementStart(lnum)let lnum = a:lnumwhile 1if getline(lnum - 1) =~ '\\$'let lnum = lnum - 1elsecall cursor(lnum, 1)let maybe_lnum = s:SearchParensPair()if maybe_lnum < 1return lnumelselet lnum = maybe_lnumendifendifendwhileendfunction" Find the block starter that matches the current linefunction! s:BlockStarter(lnum, block_start_re)let lnum = a:lnumlet maxindent = 10000 " whateverwhile lnum > 1let lnum = prevnonblank(lnum - 1)if indent(lnum) < maxindentif getline(lnum) =~ a:block_start_rereturn lnumelselet maxindent = indent(lnum)" It's not worth going further if we reached the top levelif maxindent == 0return -1endifendifendifendwhilereturn -1endfunctionfunction! GetPythonIndent(lnum)" First line has indent 0if a:lnum == 1return 0endif"Add-Begin by dantezhu in 2011年03月15日 10:14:01"修正注释和字符串缩进的问题" If the start of the line is in a string don't change the indent.if has('syntax_items')\ && synIDattr(synID(a:lnum, col('.')-1, 1), 'name') =~ '\(Comment\|String\)$'return -1endif"Add-End" If we can find an open parenthesis/bracket/brace, line up with it.call cursor(a:lnum, 1)let parlnum = s:SearchParensPair()if parlnum > 0let parcol = col('.')let closing_paren = match(getline(a:lnum), '^\s*[])}]') != -1if match(getline(parlnum), '[([{]\s*$', parcol - 1) != -1if closing_paren"Mod-Begin by dantezhu in 2011年02月21日 23:38:24"FROM"return indent(parlnum)"TO"为了支持如下的格式:"def fun(" a," b" ):" print a,b"又不影响如下格式:"val = {" (" 1," 2" ):1"}"Add-Begin by dantezhu in 2011年02月26日 23:23:08"增加了对"x = user.getdata1_(" a," b," c" )"的支持if match(getline(parlnum), '\(\a\|\d\|_\)\s*(\s*$', 0) != -1"增加了对"x(" 1," 2," 3" )"user.login(" 1," 2," 3" )" 的支持if (parcol -1 - indent(parlnum)) < 4return parcol - 1elsereturn indent(parlnum) + &swendifendif"Add-Endif match(getline(a:lnum), ')\s*:') != -1 &&\ match(getline(parlnum), '\(def\|class\|if\|elif\|while\)\(\s\+\|(\)') != -1return indent(parlnum) + &swelsereturn indent(parlnum)endif"Mod-Endelsereturn indent(parlnum) + &swendifelseif closing_parenreturn parcol - 1elsereturn parcolendifendifendif" Examine this linelet thisline = getline(a:lnum)let thisindent = indent(a:lnum)" If the line starts with 'elif' or 'else', line up with 'if' or 'elif'if thisline =~ '^\s*\(elif\|else\)\>'let bslnum = s:BlockStarter(a:lnum, '^\s*\(if\|elif\)\>')if bslnum > 0return indent(bslnum)elsereturn -1endifendif" If the line starts with 'except' or 'finally', line up with 'try'" or 'except'if thisline =~ '^\s*\(except\|finally\)\>'let bslnum = s:BlockStarter(a:lnum, '^\s*\(try\|except\)\>')if bslnum > 0return indent(bslnum)elsereturn -1endifendif" Examine previous linelet plnum = a:lnum - 1let pline = getline(plnum)let sslnum = s:StatementStart(plnum)" If the previous line is blank, keep the same indentationif pline =~ '^\s*$'return -1endif" If this line is explicitly joined, try to find an indentation that looks" good.if pline =~ '\\$'let compound_statement = '^\s*\(if\|while\|for\s.*\sin\|except\)\s*'let maybe_indent = matchend(getline(sslnum), compound_statement)if maybe_indent != -1return maybe_indentelsereturn indent(sslnum) + &sw * 2endifendif" If the previous line ended with a colon, indent relative to" statement start.if pline =~ ':\s*$'"Mod-Begin by dantezhu in 2011年02月24日 19:30:52"FROM"return indent(sslnum) + &sw"TOlet t_col = match(pline,':\s*$')+1if synIDattr(synID(a:lnum-1, t_col, 1), 'name') !~ '\(Comment\|String\)$'return indent(sslnum) + &swendif"Mod-Endendif" If the previous line was a stop-execution statement or a passif getline(sslnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>'" See if the user has already dedentedif indent(a:lnum) > indent(sslnum) - &sw" If not, recommend one dedentreturn indent(sslnum) - &swendif" Otherwise, trust the userreturn -1endif" In all other cases, line up with the start of the previous statement.return indent(sslnum)endfunction
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。