Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

execute visual/motion; syntax of doc window #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions ftplugin/python/ipy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ def get_doc_buffer(level=0):
#vim.command('pcl')
#vim.command('pedit doc')
#vim.command('normal ') # go to previous window
# "rest" is the syntax of python documentation. Stock vim doesn't have
# a syntax file for rest, but if the user has installed one then this will
# cause the docs to be colorized.
vim.command('setlocal syntax=rest')

def update_subchannel_msgs(debug=False):
msgs = km.sub_channel.get_msgs()
Expand Down Expand Up @@ -419,10 +423,10 @@ if !exists('g:ipy_perform_mappings')
let g:ipy_perform_mappings = 1
endif
if g:ipy_perform_mappings != 0
map <silent> <F5> :python run_this_file()<CR>
map <silent> <S-F5> :python run_this_line()<CR>
map <silent> <F5> <Plug>IPyRunFile
map <silent> <S-F5> <Plug>IPyRunLine
map <silent> <F9> :python run_these_lines()<CR>
map <silent> <leader>d :py get_doc_buffer()<CR>
map <silent> <leader>d <Plug>IPyDocWord
map <silent> <leader>s :py update_subchannel_msgs(); echo("vim-ipython shell updated",'Operator')<CR>
map <silent> <S-F9> :python toggle_reselect()<CR>
"map <silent> <C-F6> :python send('%pdb')<CR>
Expand All @@ -439,10 +443,17 @@ if g:ipy_perform_mappings != 0
"" Example of how to quickly close all figures with a keystroke
"map <silent> <F11> :python run_command("plt.close('all')")<cr>

" <leader>p runs command from a visual selection or a motion.
" For example, <leader>piw to execute a word.
vmap <silent> <leader>p <Plug>IPyRunSel
nmap <silent> <leader>p <Plug>IPyRunSel
" <leader>pp runs one line (analogous to e.g. "dd")
nmap <silent> <leader>pp <Plug>IPyRunLine

"pi custom
map <silent> <C-Return> :python run_this_file()<CR>
map <silent> <C-s> :python run_this_line()<CR>
imap <silent> <C-s> <C-O>:python run_this_line()<CR>
map <silent> <C-Return> <Plug>IpyRunFile
map <silent> <C-s> <Plug>IPyRunLine
imap <silent> <C-s> <Plug>IPyRunLine
map <silent> <M-s> :python dedent_run_this_line()<CR>
vmap <silent> <C-S> :python run_these_lines()<CR>
vmap <silent> <M-s> :python dedent_run_these_lines()<CR>
Expand All @@ -452,6 +463,15 @@ if g:ipy_perform_mappings != 0
vmap <silent> <M-C> :s/^\([ \t]*\)#/\1/<CR>
endif

nnoremap <Plug>IPyRunFile :py run_this_file()<CR>
noremap <Plug>IPyRunLine :python run_this_line()<CR>
inoremap <Plug>IPyRunLine <C-\><C-O>:python run_this_line()<CR>
" See: http://learnvimscriptthehardway.stevelosh.com/chapters/34.html
" And: :help map
vnoremap <Plug>IPyRunSel :<C-U>call <SID>IPythonRunOp(visualmode(), 1)<cr>
nnoremap <Plug>IPyRunSel :set operatorfunc=<SID>IPythonRunOp<cr>g@
nnoremap <Plug>IPyDocWord :py get_doc_buffer()<CR>

command! -nargs=* IPython :py km_from_string("<args>")
command! -nargs=0 IPythonClipboard :py km_from_string(vim.eval('@+'))
command! -nargs=0 IPythonXSelection :py km_from_string(vim.eval('@*'))
Expand Down Expand Up @@ -519,3 +539,30 @@ endpython
endif
endfun
set completefunc=CompleteIPython

" Only create function if it doesn't already exist. It isn't sufficient to
" just use "function!" since the function may already be referenced by
" operatorfunc, and vim doesn't allow redefining the function in that case.
if !exists('*s:IPythonRunOp')
function s:IPythonRunOp(type, ...)
let saved_unnamed_register = @@

if a:0 " Invoked from Visual mode, use '< and '> marks.
exe "silent normal! `<" . a:type . "`>y"
elseif a:type ==# 'char'
silent normal! `[v`]y
elseif a:type == 'line'
silent normal! '[V']y
elseif a:type == 'block'
silent normal! `[\<C-V>`]y
else
echo "error: type=".a:type." a:0=".a:0
return
endif

"echo "0: ".a:0." t: ".a:type." @: ".@@
python run_command(vim.eval('@@'))

let @@ = saved_unnamed_register
endfunction
endif