“谷歌” python 样式脚本不工作
我正在尝试使用 Google python 缩进脚本,但事实并非如此为我工作。我希望它缩进如下:
very_long_function_name(
first_param,
我将其文本粘贴到 这个 vim 脚本的末尾: 并将其放入 ~/.vim/indent/python.vim
中。不知道为什么它不起作用。
编辑:已修复。
我修改了缩进文件如下:
function GetGooglePythonIndent(lnum)
" Indent inside parens.
" Align with the open paren unless it is at the end of the line.
" E.g.
" open_paren_not_at_EOL(100,
" (200,
" 300),
" 400)
" open_paren_at_EOL(
" 100, 200, 300, 400)
call cursor(a:lnum, 1)
let [par_line, par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
\ . " =~ '\\(Comment\\|String\\)$'")
echo par_line par_col
if par_line > 0
call cursor(par_line, 1)
if par_col != col("$") - 1
return par_col
else
return indent(par_line) + &sw " FIXED HERE. FIXED BY ADDING THIS LINE
endif
endif
" Delegate the rest to the original function.
return GetPythonIndent(a:lnum)
endfunction
I'm trying to use the Google python indentation script, but it's not working for me. I want it to indent as follows:
very_long_function_name(
first_param,
I pasted its text onto the end of this vim script: and put it into ~/.vim/indent/python.vim
. Not sure why it's not working.
Edit: FIXED.
I modified the indent file as follows:
function GetGooglePythonIndent(lnum)
" Indent inside parens.
" Align with the open paren unless it is at the end of the line.
" E.g.
" open_paren_not_at_EOL(100,
" (200,
" 300),
" 400)
" open_paren_at_EOL(
" 100, 200, 300, 400)
call cursor(a:lnum, 1)
let [par_line, par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :"
\ . " synIDattr(synID(line('.'), col('.'), 1), 'name')"
\ . " =~ '\\(Comment\\|String\\)
")
echo par_line par_col
if par_line > 0
call cursor(par_line, 1)
if par_col != col("$") - 1
return par_col
else
return indent(par_line) + &sw " FIXED HERE. FIXED BY ADDING THIS LINE
endif
endif
" Delegate the rest to the original function.
return GetPythonIndent(a:lnum)
endfunction
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的 .vimrc 中可能缺少
filetype indent on
。You are probably missing
filetype indent on
from your .vimrc.就我而言,我必须将脚本复制到
~/.vim/after/indent/python.vim
,因为内置的 python 缩进脚本会覆盖我添加到~/ 的脚本。 vim/indent/python.vim
。我能够通过
:scriptnames
命令查看加载的顺序。In my case, I had to copy the script to
~/.vim/after/indent/python.vim
as the built-in python indent script overridden the one I added to~/.vim/indent/python.vim
.I was able to see the loaded order by
:scriptnames
command.通过修改脚本并添加缺失的行来修复。
Fixed by modifying the script and adding a missing line.