mirror of
https://github.com/gryf/python.vim.git
synced 2025-12-17 11:30:22 +01:00
Clean up indentation and commented code
This commit is contained in:
@@ -7,11 +7,7 @@
|
|||||||
|
|
||||||
" USAGE:
|
" USAGE:
|
||||||
"
|
"
|
||||||
" Save this file to $VIMFILES/ftplugin/python.vim. You can have multiple
|
" See README for installation.
|
||||||
" python ftplugins by creating $VIMFILES/ftplugin/python and saving your
|
|
||||||
" ftplugins in that directory. If saving this to the global ftplugin
|
|
||||||
" directory, this is the recommended method, since vim ships with an
|
|
||||||
" ftplugin/python.vim file already.
|
|
||||||
" You can set the global variable "g:py_select_leading_comments" to 0
|
" You can set the global variable "g:py_select_leading_comments" to 0
|
||||||
" if you don't want to select comments preceding a declaration (these
|
" if you don't want to select comments preceding a declaration (these
|
||||||
" are usually the description of the function/class).
|
" are usually the description of the function/class).
|
||||||
@@ -84,55 +80,53 @@ vmap ]F :call PythonDec("function", -1)<CR>
|
|||||||
map ]f :call PythonDec("function", 1)<CR>
|
map ]f :call PythonDec("function", 1)<CR>
|
||||||
vmap ]f :call PythonDec("function", 1)<CR>
|
vmap ]f :call PythonDec("function", 1)<CR>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
" Menu entries
|
" Menu entries
|
||||||
nmenu <silent> &Python.Update\ IM-Python\ Menu
|
nmenu <silent> &Python.Update\ IM-Python\ Menu
|
||||||
\:call UpdateMenu()<CR>
|
\:call UpdateMenu()<CR>
|
||||||
nmenu &Python.-Sep1- :
|
nmenu &Python.-Sep1- :
|
||||||
nmenu <silent> &Python.Beginning\ of\ Block<Tab>[t
|
nmenu <silent> &Python.Beginning\ of\ Block<Tab>[t
|
||||||
\]t
|
\]t
|
||||||
nmenu <silent> &Python.End\ of\ Block<Tab>]e
|
nmenu <silent> &Python.End\ of\ Block<Tab>]e
|
||||||
\]e
|
\]e
|
||||||
nmenu &Python.-Sep2- :
|
nmenu &Python.-Sep2- :
|
||||||
nmenu <silent> &Python.Shift\ Block\ Left<Tab>]<
|
nmenu <silent> &Python.Shift\ Block\ Left<Tab>]<
|
||||||
\]<
|
\]<
|
||||||
vmenu <silent> &Python.Shift\ Block\ Left<Tab>]<
|
vmenu <silent> &Python.Shift\ Block\ Left<Tab>]<
|
||||||
\]<
|
\]<
|
||||||
nmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
|
nmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
|
||||||
\]>
|
\]>
|
||||||
vmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
|
vmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
|
||||||
\]>
|
\]>
|
||||||
nmenu &Python.-Sep3- :
|
nmenu &Python.-Sep3- :
|
||||||
vmenu <silent> &Python.Comment\ Selection<Tab>]#
|
vmenu <silent> &Python.Comment\ Selection<Tab>]#
|
||||||
\]#
|
\]#
|
||||||
nmenu <silent> &Python.Comment\ Selection<Tab>]#
|
nmenu <silent> &Python.Comment\ Selection<Tab>]#
|
||||||
\]#
|
\]#
|
||||||
vmenu <silent> &Python.Uncomment\ Selection<Tab>]u
|
vmenu <silent> &Python.Uncomment\ Selection<Tab>]u
|
||||||
\]u
|
\]u
|
||||||
nmenu <silent> &Python.Uncomment\ Selection<Tab>]u
|
nmenu <silent> &Python.Uncomment\ Selection<Tab>]u
|
||||||
\]u
|
\]u
|
||||||
nmenu &Python.-Sep4- :
|
nmenu &Python.-Sep4- :
|
||||||
nmenu <silent> &Python.Previous\ Class<Tab>]J
|
nmenu <silent> &Python.Previous\ Class<Tab>]J
|
||||||
\]J
|
\]J
|
||||||
nmenu <silent> &Python.Next\ Class<Tab>]j
|
nmenu <silent> &Python.Next\ Class<Tab>]j
|
||||||
\]j
|
\]j
|
||||||
nmenu <silent> &Python.Previous\ Function<Tab>]F
|
nmenu <silent> &Python.Previous\ Function<Tab>]F
|
||||||
\]F
|
\]F
|
||||||
nmenu <silent> &Python.Next\ Function<Tab>]f
|
nmenu <silent> &Python.Next\ Function<Tab>]f
|
||||||
\]f
|
\]f
|
||||||
nmenu &Python.-Sep5- :
|
nmenu &Python.-Sep5- :
|
||||||
nmenu <silent> &Python.Select\ Block<Tab>]v
|
nmenu <silent> &Python.Select\ Block<Tab>]v
|
||||||
\]v
|
\]v
|
||||||
nmenu <silent> &Python.Select\ Function<Tab>]d
|
nmenu <silent> &Python.Select\ Function<Tab>]d
|
||||||
\]d
|
\]d
|
||||||
nmenu <silent> &Python.Select\ Class<Tab>]c
|
nmenu <silent> &Python.Select\ Class<Tab>]c
|
||||||
\]c
|
\]c
|
||||||
nmenu &Python.-Sep6- :
|
nmenu &Python.-Sep6- :
|
||||||
nmenu <silent> &Python.Previous\ Line\ wrt\ indent<Tab>]<up>
|
nmenu <silent> &Python.Previous\ Line\ wrt\ indent<Tab>]<up>
|
||||||
\]<up>
|
\]<up>
|
||||||
nmenu <silent> &Python.Next\ Line\ wrt\ indent<Tab>]<down>
|
nmenu <silent> &Python.Next\ Line\ wrt\ indent<Tab>]<down>
|
||||||
\]<down>
|
\]<down>
|
||||||
|
|
||||||
:com! PBoB execute "normal ".PythonBoB(line('.'), -1, 1)."G"
|
:com! PBoB execute "normal ".PythonBoB(line('.'), -1, 1)."G"
|
||||||
:com! PEoB execute "normal ".PythonBoB(line('.'), 1, 1)."G"
|
:com! PEoB execute "normal ".PythonBoB(line('.'), 1, 1)."G"
|
||||||
@@ -148,15 +142,15 @@ function! PythonBoB(line, direction, force_sel_comments)
|
|||||||
let indent_valid = strlen(getline(ln))
|
let indent_valid = strlen(getline(ln))
|
||||||
let ln = ln + a:direction
|
let ln = ln + a:direction
|
||||||
if (a:direction == 1) && (!a:force_sel_comments) &&
|
if (a:direction == 1) && (!a:force_sel_comments) &&
|
||||||
\ exists("g:py_select_trailing_comments") &&
|
\ exists("g:py_select_trailing_comments") &&
|
||||||
\ (!g:py_select_trailing_comments)
|
\ (!g:py_select_trailing_comments)
|
||||||
let sel_comments = 0
|
let sel_comments = 0
|
||||||
else
|
else
|
||||||
let sel_comments = 1
|
let sel_comments = 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
while((ln >= 1) && (ln <= line('$')))
|
while((ln >= 1) && (ln <= line('$')))
|
||||||
if (sel_comments) || (match(getline(ln), "^\\s*#") == -1)
|
if (sel_comments) || (match(getline(ln), "^\\s*#") == -1)
|
||||||
if (!indent_valid)
|
if (!indent_valid)
|
||||||
let indent_valid = strlen(getline(ln))
|
let indent_valid = strlen(getline(ln))
|
||||||
let ind = indent(ln)
|
let ind = indent(ln)
|
||||||
@@ -181,7 +175,7 @@ endfunction
|
|||||||
function! PythonDec(obj, direction)
|
function! PythonDec(obj, direction)
|
||||||
if (a:obj == "class")
|
if (a:obj == "class")
|
||||||
let objregexp = "^\\s*class\\s\\+[a-zA-Z0-9_]\\+"
|
let objregexp = "^\\s*class\\s\\+[a-zA-Z0-9_]\\+"
|
||||||
\ . "\\s*\\((\\([a-zA-Z0-9_,. \\t\\n]\\)*)\\)\\=\\s*:"
|
\ . "\\s*\\((\\([a-zA-Z0-9_,. \\t\\n]\\)*)\\)\\=\\s*:"
|
||||||
else
|
else
|
||||||
let objregexp = "^\\s*\\(async def\\|def\\)\\s\\+[a-zA-Z0-9_]\\+\\s*(\\_[^:#]*)\\s*:"
|
let objregexp = "^\\s*\\(async def\\|def\\)\\s\\+[a-zA-Z0-9_]\\+\\s*(\\_[^:#]*)\\s*:"
|
||||||
endif
|
endif
|
||||||
@@ -235,7 +229,7 @@ function! PythonUncommentSelection() range
|
|||||||
let cl = a:firstline
|
let cl = a:firstline
|
||||||
while (cl <= a:lastline)
|
while (cl <= a:lastline)
|
||||||
let ul = substitute(getline(cl),
|
let ul = substitute(getline(cl),
|
||||||
\"\\(\\s*\\)".commentString."\\(.*\\)$", "\\1\\2", "")
|
\"\\(\\s*\\)".commentString."\\(.*\\)$", "\\1\\2", "")
|
||||||
call setline(cl, ul)
|
call setline(cl, ul)
|
||||||
let cl = cl + 1
|
let cl = cl + 1
|
||||||
endwhile
|
endwhile
|
||||||
@@ -264,9 +258,9 @@ function! PythonSelectObject(obj)
|
|||||||
|
|
||||||
if (a:obj == "class")
|
if (a:obj == "class")
|
||||||
let eod = "\\(^\\s*class\\s\\+[a-zA-Z0-9_]\\+\\s*"
|
let eod = "\\(^\\s*class\\s\\+[a-zA-Z0-9_]\\+\\s*"
|
||||||
\ . "\\((\\([a-zA-Z0-9_,. \\t\\n]\\)*)\\)\\=\\s*\\)\\@<=:"
|
\ . "\\((\\([a-zA-Z0-9_,. \\t\\n]\\)*)\\)\\=\\s*\\)\\@<=:"
|
||||||
else
|
else
|
||||||
let eod = "\\(^\\s*\\(async def\\|def\\)\\s\\+[a-zA-Z0-9_]\\+\\s*(\\_[^:#]*)\\s*\\)\\@<=:"
|
let eod = "\\(^\\s*\\(async def\\|def\\)\\s\\+[a-zA-Z0-9_]\\+\\s*(\\_[^:#]*)\\s*\\)\\@<=:"
|
||||||
endif
|
endif
|
||||||
" Look for the end of the declaration (not always the same line!)
|
" Look for the end of the declaration (not always the same line!)
|
||||||
call search(eod, "")
|
call search(eod, "")
|
||||||
@@ -296,7 +290,7 @@ function! PythonNextLine(direction)
|
|||||||
|
|
||||||
while((ln >= 1) && (ln <= line('$')))
|
while((ln >= 1) && (ln <= line('$')))
|
||||||
if (!indent_valid) && strlen(getline(ln))
|
if (!indent_valid) && strlen(getline(ln))
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
if (strlen(getline(ln)))
|
if (strlen(getline(ln)))
|
||||||
if (indent(ln) <= ind)
|
if (indent(ln) <= ind)
|
||||||
@@ -432,15 +426,4 @@ function! s:JumpToAndUnfold(line)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"" This one will work only on vim 6.2 because of the try/catch expressions.
|
|
||||||
" function! s:JumpToAndUnfoldWithExceptions(line)
|
|
||||||
" try
|
|
||||||
" execute 'normal '.a:line.'gg15zo'
|
|
||||||
" catch /^Vim\((\a\+)\)\=:E490:/
|
|
||||||
" " Do nothing, just consume the error
|
|
||||||
" endtry
|
|
||||||
"endfunction
|
|
||||||
|
|
||||||
|
|
||||||
" vim:set et sts=2 sw=2:
|
" vim:set et sts=2 sw=2:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user