mirror of
https://github.com/gryf/python.vim.git
synced 2025-12-17 19:40:28 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc9722e464 | - | |
|
|
414dc1c5c0 | - | |
|
|
5f50c785a7 | - |
@@ -1,12 +1,12 @@
|
|||||||
" -*- vim -*-
|
" -*- vim -*-
|
||||||
" FILE: python.vim
|
" FILE: python.vim
|
||||||
" LAST MODIFICATION: 2001/07/07
|
" LAST MODIFICATION: 2003/06/12 08:19
|
||||||
" (C) Copyright 2001 Mikael Berthe <mikael.berthe@efrei.fr>
|
" (C) Copyright 2001-2003 Mikael Berthe <mikael.b@netcourrier.com>
|
||||||
" Version: 1.1
|
" Version: 1.6
|
||||||
|
|
||||||
" USAGE:
|
" USAGE:
|
||||||
"
|
"
|
||||||
" Juste source this script when editing Python files.
|
" Just source this script when editing Python files.
|
||||||
" Example: au FileType python source ~me/.vim/scripts/python.vim
|
" Example: au FileType python source ~me/.vim/scripts/python.vim
|
||||||
" 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
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
" shift commands...
|
" shift commands...
|
||||||
"
|
"
|
||||||
" REQUIREMENTS:
|
" REQUIREMENTS:
|
||||||
" vim (>= 600)
|
" vim (>= 6)
|
||||||
"
|
"
|
||||||
" Shortcuts:
|
" Shortcuts:
|
||||||
" [[ -- Jump to beginning of block
|
" [[ -- Jump to beginning of block
|
||||||
@@ -55,11 +55,14 @@ map ]<down> :call PythonNextLine(1)<CR>
|
|||||||
|
|
||||||
|
|
||||||
" Menu entries
|
" Menu entries
|
||||||
|
nmenu <silent> &Python.Update\ IM-Python\ Menu
|
||||||
|
\:call UpdateMenu()<CR>
|
||||||
|
nmenu &Python.-Sep1- :
|
||||||
nmenu <silent> &Python.Beginning\ of\ Block<Tab>[[
|
nmenu <silent> &Python.Beginning\ of\ Block<Tab>[[
|
||||||
\[[
|
\[[
|
||||||
nmenu <silent> &Python.End\ of\ Block<Tab>]]
|
nmenu <silent> &Python.End\ of\ Block<Tab>]]
|
||||||
\]]
|
\]]
|
||||||
nmenu &Python.-Sep1- :
|
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>]<
|
||||||
@@ -68,7 +71,7 @@ nmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
|
|||||||
\]>
|
\]>
|
||||||
vmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
|
vmenu <silent> &Python.Shift\ Block\ Right<Tab>]>
|
||||||
\]>
|
\]>
|
||||||
nmenu &Python.-Sep2- :
|
nmenu &Python.-Sep3- :
|
||||||
vmenu <silent> &Python.Comment\ Selection
|
vmenu <silent> &Python.Comment\ Selection
|
||||||
\:call PythonCommentSelection()<CR>
|
\:call PythonCommentSelection()<CR>
|
||||||
nmenu <silent> &Python.Comment\ Selection
|
nmenu <silent> &Python.Comment\ Selection
|
||||||
@@ -77,7 +80,7 @@ vmenu <silent> &Python.Uncomment\ Selection
|
|||||||
\:call PythonUncommentSelection()<CR>
|
\:call PythonUncommentSelection()<CR>
|
||||||
nmenu <silent> &Python.Uncomment\ Selection
|
nmenu <silent> &Python.Uncomment\ Selection
|
||||||
\:call PythonUncommentSelection()<CR>
|
\:call PythonUncommentSelection()<CR>
|
||||||
nmenu &Python.-Sep3- :
|
nmenu &Python.-Sep4- :
|
||||||
nmenu <silent> &Python.Previous\ Class
|
nmenu <silent> &Python.Previous\ Class
|
||||||
\:call PythonDec("class", -1)<CR>
|
\:call PythonDec("class", -1)<CR>
|
||||||
nmenu <silent> &Python.Next\ Class
|
nmenu <silent> &Python.Next\ Class
|
||||||
@@ -86,14 +89,14 @@ nmenu <silent> &Python.Previous\ Function
|
|||||||
\:call PythonDec("function", -1)<CR>
|
\:call PythonDec("function", -1)<CR>
|
||||||
nmenu <silent> &Python.Next\ Function
|
nmenu <silent> &Python.Next\ Function
|
||||||
\:call PythonDec("function", 1)<CR>
|
\:call PythonDec("function", 1)<CR>
|
||||||
nmenu &Python.-Sep4- :
|
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>]f
|
nmenu <silent> &Python.Select\ Function<Tab>]f
|
||||||
\]f
|
\]f
|
||||||
nmenu <silent> &Python.Select\ Class<Tab>]c
|
nmenu <silent> &Python.Select\ Class<Tab>]c
|
||||||
\]c
|
\]c
|
||||||
nmenu &Python.-Sep5- :
|
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>
|
||||||
@@ -102,7 +105,7 @@ nmenu <silent> &Python.Next\ Line\ wrt\ indent<Tab>]<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"
|
||||||
|
:com! UpdateMenu call UpdateMenu()
|
||||||
|
|
||||||
|
|
||||||
" Go to a block boundary (-1: previous, 1: next)
|
" Go to a block boundary (-1: previous, 1: next)
|
||||||
@@ -276,22 +279,27 @@ function! PythonNextLine(direction)
|
|||||||
execute "normal ".ln."G"
|
execute "normal ".ln."G"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" update the IM-Python menu, that holds Classes and Functions
|
|
||||||
|
" Update the IM-Python menu, that holds Classes and Functions
|
||||||
function! UpdateMenu()
|
function! UpdateMenu()
|
||||||
|
let restore_fe = &foldenable
|
||||||
|
set nofoldenable
|
||||||
|
let cline=line('.')
|
||||||
call MakeClassStructure ()
|
call MakeClassStructure ()
|
||||||
call MakeFuncStructure ()
|
call MakeFuncStructure ()
|
||||||
|
execute "normal ".cline."Gzz"
|
||||||
|
let &foldenable = restore_fe
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command UpdateMenu call UpdateMenu ()
|
" Make a menu that holds all of the classes
|
||||||
|
|
||||||
" make a menu that holds all of the classes
|
|
||||||
function! MakeClassStructure ()
|
function! MakeClassStructure ()
|
||||||
norm mpgg0
|
norm mpgg0
|
||||||
while line(".") <= line("$")
|
while line(".") <= line("$")
|
||||||
if match ( getline("."), '^\s*class\s\+' ) != -1
|
if match ( getline("."), '^\s*class\s\+' ) != -1
|
||||||
norm ^w"nyw
|
norm ^w"nyw
|
||||||
let name=@n
|
let name=@n
|
||||||
exe 'menu IM-Python.classes.'.name.' '.line(".").'gg'
|
"exe 'menu IM-Python.classes.'.name.' '.line(".").'gg15zo'
|
||||||
|
exe 'menu IM-Python.classes.'.name.' :call <SID>JumpToAndUnfold('.line(".").')<CR>'
|
||||||
endif
|
endif
|
||||||
if line(".") == line("$")
|
if line(".") == line("$")
|
||||||
return
|
return
|
||||||
@@ -301,14 +309,15 @@ function! MakeClassStructure ()
|
|||||||
norm 'p
|
norm 'p
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
"make a menu that holds all of the function deffinitions
|
" Make a menu that holds all of the function definitions
|
||||||
function! MakeFuncStructure ()
|
function! MakeFuncStructure ()
|
||||||
norm mpgg0
|
norm mpgg0
|
||||||
while line(".") <= line("$")
|
while line(".") <= line("$")
|
||||||
if match ( getline("."), '^\s*def\s\+' ) != -1
|
if match ( getline("."), '^\s*def\s\+' ) != -1
|
||||||
norm ^w"nyw
|
norm ^w"nyw
|
||||||
let name=@n
|
let name=@n
|
||||||
exe 'menu IM-Python.functions.'.name.' '.line(".").'gg'
|
"exe 'menu IM-Python.functions.'.name.' '.line(".").'gg15zo'
|
||||||
|
exe 'menu IM-Python.functions.'.name.' :call <SID>JumpToAndUnfold('.line(".").')<CR>'
|
||||||
endif
|
endif
|
||||||
if line(".") == line("$")
|
if line(".") == line("$")
|
||||||
return
|
return
|
||||||
@@ -318,6 +327,26 @@ function! MakeFuncStructure ()
|
|||||||
norm 'p
|
norm 'p
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:JumpToAndUnfold(line)
|
||||||
|
" Go to the right line
|
||||||
|
execute 'normal '.a:line.'gg'
|
||||||
|
" Check to see if we are in a fold
|
||||||
|
let lvl = foldlevel(a:line)
|
||||||
|
if lvl != 0
|
||||||
|
" and if so, then expand the fold out, other wise, ignore this part.
|
||||||
|
execute 'normal 15zo'
|
||||||
|
endif
|
||||||
|
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