Skip to content

Commit

Permalink
few updates
Browse files Browse the repository at this point in the history
  • Loading branch information
johndgiese committed Aug 20, 2012
1 parent 611fa80 commit bb87301
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
44 changes: 37 additions & 7 deletions doc/vipy.txt
Expand Up @@ -10,9 +10,10 @@ Help on the Vipy Plugin *vipy*
2. Starting vipy |vipy-startup|
3. The vipy buffer |vipy-buffer|
4. Extra functionailty in python files |vipy-pyfiles|
5. Customization |vipy-customization|
6. Issues |vipy-issues|
7. Credits |vipy-credits|
5. Autocomplete |vipy-complete|
6. Customization |vipy-customization|
7. Issues |vipy-issues|
8. Credits |vipy-credits|

==============================================================================
1. Overview *vipy-overview*
Expand Down Expand Up @@ -79,7 +80,10 @@ window open.

Typing object? will print the IPython help, properly formatted.

Typing object?? will open the file where the object is defined in a vim buffer.
Typing object?? will open the file and place the cursor where the object is
defined in a vim buffer. If the object is a module, the cursor will be placed
at the top of the file. If the file is already opened, vipy will switch to
it.

The vipy buffer has special syntax highlighting; input is formatted as
usual, while standard output (except for python documentation) uses normal
Expand Down Expand Up @@ -146,7 +150,26 @@ program. Cell mode is useful for situations where you want to load data once,
but execute some analysis of that data multiple times

==============================================================================
5. Customization *vipy-customization*
5. Complete *vipy-complete*

VIPY provides a user-complete that querys the IPython kernel for information
about an object. By default this is accessed using <C-xC-u>, however I
strongly reccomend that you install the SuperTab plugin, so that you can use
TAB instead.

For example,
>>> a = [1,2,3,4]
>>> a.|
if you start the autocompete at | This would bring up a menu with a number of
options: a.append, a.count, etc. which you could scroll through (<C-N> and
<C-P> by default, <tab> and <s-tab> if you have supertab installed).

If you are in the command prompt, you can now press <S-CR> to print the
options actually into the buffer. This is useful if you want to search the
output, or there are too many options to see on one screen.

==============================================================================
6. Customization *vipy-customization*

The following global variables can be set in your vimrc:

Expand All @@ -166,7 +189,7 @@ remove this auto-clean behavior, use:
g:vipy_clean_connect_files=0

==============================================================================
6. Issues *vipy-issues*
7. Issues *vipy-issues*

If the server is unresponsive, close it using <S-F12>, and reopen it again by
pressing <C-F12>. This will clean out any old connection files that may be
Expand All @@ -186,6 +209,13 @@ guess it is the price of having vim's syntax highlighting work in the prompt.
If it really bothers you just clear vipy using >>> cls or >>> clear

==============================================================================
7. Credits *vipy-credits*
8. Credits *vipy-credits*

* Paul Ivanov for his vim-ipython plugin which got me started.
* Prof. Jerome Mertz at Boston University for being a great PI.
* Fernando Perez for writing IPython.
* Bram Moolenaar for writing Vim.



vim:tw=78:ts=8:ft=help:norl:
2 changes: 1 addition & 1 deletion ftplugin/python/vipy.vim
Expand Up @@ -25,7 +25,7 @@ fun! CompleteIPython(findstart, base)
python complete_type = 'normal'
while start > 0
"python vib.append('cc: %s' % vim.eval('line[start-1]'))
if line[start-1] !~ '\w\|\.'
if line[start-1] !~ '\w\|\.\|\/'
if line[start-1] == '('
python complete_type = 'argument'
endif
Expand Down
29 changes: 25 additions & 4 deletions plugin/vipy.vim
Expand Up @@ -244,7 +244,7 @@ def km_from_connection_file():
def setup_vib():
""" Setup vib (vipy buffer), that acts like a prompt. """
global vib
vim.command("rightbelow vnew vipy.py")
vim.command("drop vipy.py")
# set the global variable for everyone to reference easily
vib = get_vim_ipython_buffer()
new_prompt(append=False)
Expand All @@ -257,9 +257,9 @@ def setup_vib():
vim.command("syn match Normal /^>>>/")

# mappings to control sending stuff from vipy
vim.command("inoremap <buffer> <silent> <cr> <ESC>:py enter_at_prompt()<CR>")
vim.command("nnoremap <buffer> <silent> <cr> <ESC>:py enter_at_prompt()<CR>")
vim.command("inoremap <buffer> <silent> <s-cr> <ESC>:py shift_enter_at_prompt()<CR>")
vim.command('inoremap <expr> <buffer> <silent> <s-cr> pumvisible() ? "\<ESC>:py print_completions()\<CR>" : "\<ESC>:py shift_enter_at_prompt()\<CR>"')
vim.command('nnoremap <buffer> <silent> <cr> <ESC>:py enter_at_prompt()<CR>')
vim.command('inoremap <expr> <buffer> <silent> <cr> pumvisible() ? "<CR>" : "\<ESC>:py enter_at_prompt()\<CR>"')

# setup history mappings etc.
enter_normal(first=True)
Expand Down Expand Up @@ -478,6 +478,24 @@ def shift_enter_at_prompt():
# vim.command('call feedkeys("\<CR>")')
vim.command('normal <CR>')

def print_completions():
# grab current input
# TODO: make this work for multi-line input
if len(completions) > 2:
input_length = 1
input = vib[-input_length:]
del vib[-input_length]

# print completions
# TODO: make this print on multiple columns
if len(vib) == 1:
vib[0] = completions[1]
else:
vib[-1] = completions[1]
vib.append(completions[2:])
vib.append(input)
goto_vib()

def enter_at_prompt():
""" Remove prompts and whitespace before sending to ipython. """
if status == 'input requested':
Expand Down Expand Up @@ -537,6 +555,7 @@ def enter_at_prompt():
if content['found']:
if content['file']:
vim.command("drop " + content['file'])
vim.command("set syntax=python")

# try to position the cursor in the source file
# if content['source']:
Expand Down Expand Up @@ -575,6 +594,8 @@ def enter_at_prompt():
# this is ugly to put the cursor movement here: TODO: find a better way
if deffind and deffind.match(line):
vim.current.window.cursor = (ind + 1, 0)
else:
vim.current.window.cursor = (1, 0)


elif cmds.endswith('?'):
Expand Down

0 comments on commit bb87301

Please sign in to comment.