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

Add support for NeoComplete #105

Open
wants to merge 125 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
6d30bfd
Add support for NeoComplete by setting omnifunc instead of completefunc
wilywampa Sep 15, 2014
af8444e
Fix neocomplete function names; check has('python'); only use
wilywampa Sep 15, 2014
c2c0989
Use CompleteIPython in neocomplete even if it's not the current omnifunc
wilywampa Sep 20, 2014
b819b3f
Suppress errors using silent! instead of try so neocomplete doesn't give
wilywampa Sep 20, 2014
254ec1a
Ignore .pyc files
wilywampa Dec 5, 2014
9fb23da
Move autocmds into vim-ipython augroup
wilywampa Dec 5, 2014
7f20e03
Move mappings into function and run automatically
wilywampa Dec 5, 2014
32da777
Tweak mappings and add get_doc_buffer
wilywampa Dec 5, 2014
a0b8227
Dictionary and greedy completion with metadata
wilywampa Dec 5, 2014
5fca252
Improve km_from_string function
wilywampa Dec 5, 2014
56fa1d3
Change default options
wilywampa Dec 5, 2014
105fc88
Improve preview window behavior
wilywampa Dec 5, 2014
e6b4279
Add default timeout to get_child_msg
wilywampa Dec 5, 2014
a58a059
Don't put os in ipython namespace
wilywampa Dec 5, 2014
0c557a1
Add run_ipy_input function
wilywampa Dec 5, 2014
df68712
Whitespace
wilywampa Dec 5, 2014
e6cd52d
Handle findstart for non-index square bracket
wilywampa Dec 8, 2014
2ca1b0b
Allow completion for nested dicts (adjacent ][)
wilywampa Dec 10, 2014
82902b3
Do mappings on BufNewFile event
wilywampa Dec 14, 2014
0c570c4
Fix error when completion contains \"
wilywampa Dec 17, 2014
275add7
Change visual map to dedent lines
wilywampa Dec 25, 2014
6065ef0
Replace ugly vim command with pyevals
wilywampa Dec 26, 2014
0a75c91
Fix findstart for e.g. word['key'].word
wilywampa Jan 6, 2015
762800b
Merge remote-tracking branch 'upstream/master' into dev
wilywampa Jan 13, 2015
6bce398
Completion for imports
wilywampa Jan 23, 2015
ab0231a
Completion for imports
wilywampa Jan 23, 2015
1808548
Improve completion of 'from module import a, ...'
wilywampa Jan 23, 2015
668658b
Don't map <S-F5>
wilywampa Jan 24, 2015
4194ef1
Better skipped message handling
wilywampa Feb 18, 2015
f3f8f21
Fix findstart for some corner cases
wilywampa Mar 7, 2015
7f6d461
Change run_flags to a vim variable
wilywampa Mar 7, 2015
801d281
Add function to evaluate g:ipy_input into @@/@+/@-
wilywampa Mar 8, 2015
242c4c1
Fix import completion
wilywampa Mar 8, 2015
88f6df8
Do mappings on FileType python autocmd
wilywampa Mar 17, 2015
80b3b5c
Fix 'from .* import .*' when indent is non-zero
wilywampa Mar 20, 2015
37df7f2
Fix findstart for decorators
wilywampa Mar 29, 2015
8160fd3
Change <C-k> imap to <Leader>K
wilywampa Mar 30, 2015
c77185c
Fix split_pattern
wilywampa Apr 1, 2015
f959294
Change eval_to_register to eval_ipy_input
wilywampa Apr 26, 2015
ded5363
Allow completion of dict keys after *dictname[
wilywampa May 19, 2015
44e7e87
Finish merge
wilywampa Jun 1, 2015
56afe52
Finish merge
wilywampa Jun 29, 2015
7af79b8
Improve ANSI code pattern
wilywampa Jul 6, 2015
69bef00
Remove string prefix and quotes in eval_ipy_input
wilywampa Jul 23, 2015
342c6fd
Send _vim_client message after connecting
wilywampa Jul 23, 2015
cd48865
Set syntax correctly
wilywampa Jul 29, 2015
f1be971
Fix exception handling and use float division
wilywampa Aug 2, 2015
6e9d007
Fix keys in wrong order and result undefined
wilywampa Aug 5, 2015
300f507
Make get_doc_buffer work for g:ipy_input
wilywampa Aug 16, 2015
7ec7723
Disable visual map
wilywampa Aug 17, 2015
f1a73ec
Improve eval_ipy_input
wilywampa Aug 17, 2015
b53d87e
Add IPythonHistory function
wilywampa Aug 21, 2015
1723515
Fix calling get_doc_buffer with word argument
wilywampa Aug 22, 2015
376111e
Fix to include current session history
wilywampa Aug 23, 2015
d9b1faa
Fall back to jedi#completions on timeout
wilywampa Aug 23, 2015
897dbc3
Add ipython_history_timeout option
wilywampa Aug 27, 2015
2052ce4
Fix check for empty pattern
wilywampa Aug 27, 2015
57725d1
Add maps to change filetype in doc buffer
wilywampa Aug 31, 2015
2e46528
Disable insert mode map
wilywampa Sep 7, 2015
611167b
Add option to not store history in run_ipy_input
wilywampa Sep 7, 2015
6fe7198
Use run_cython for Cython files
wilywampa Sep 19, 2015
5a8ab4e
Remove neocomplete source
wilywampa Sep 26, 2015
37f8a9c
Add completion timeout and history by session
wilywampa Oct 7, 2015
d4c78ab
IPython 3+ compatibility
wilywampa Oct 11, 2015
2343f9a
Py3 compat and don't show 0 for session number
wilywampa Oct 12, 2015
a0dc32a
Fix encoding issues
wilywampa Oct 12, 2015
f33d69f
Improve handling of argument to km_from_string
wilywampa Oct 28, 2015
d5fe517
Only set unique if pattern is non-empty
wilywampa Oct 29, 2015
85f6a3d
Fix completion of 'from a.b import ...'
wilywampa Oct 30, 2015
b505eb4
Allow anchoring start/end of pattern
wilywampa Oct 31, 2015
881a0ca
Handle unicode characters in completion
wilywampa Nov 1, 2015
20a34ba
Support Python 3 and IPython 3/4
wilywampa Nov 1, 2015
7bcea4d
Fix completion of imports and magics
wilywampa Nov 2, 2015
90e59d5
Fix 'from x.x …' imports and fix imports s:start
wilywampa Nov 7, 2015
40dc8da
Return empty list after aborting completion
wilywampa Nov 7, 2015
a2ade82
Use g:ipython_store_history everywhere
wilywampa Nov 9, 2015
f9d238b
Fix unicode errors in run_ipy_input in Python 2
wilywampa Nov 12, 2015
4fffbbb
Add silent keyword argument to run_ipy_input
wilywampa Nov 30, 2015
935237e
MAke get_child_msg timeout configurable
wilywampa Dec 24, 2015
2e61840
Add command line completion function
wilywampa Dec 24, 2015
e27236b
Fix return value for failed completion
wilywampa Dec 25, 2015
515c45e
Add whitespace delimited completion function
wilywampa Dec 31, 2015
bb47570
Handle no response from kernel correctly
wilywampa Jan 4, 2016
82234cc
Fix handling of string escapes in eval_ipy_input
wilywampa Jan 4, 2016
d8babda
Ignore consecutive duplicates in IPythonHistory
wilywampa Jan 7, 2016
b28f511
Make uniqueness optional in IPythonHistory
wilywampa Jan 17, 2016
848b0e7
Show most recent repeated history item
wilywampa Jan 28, 2016
eef6e30
Allow keyword arguments to run_ipy_input
wilywampa Feb 14, 2016
5af8ab8
Set defaults for history options
wilywampa Feb 20, 2016
26f4ca6
Escape opening square brackets in IPythonHistory
wilywampa Feb 25, 2016
5cfb2db
Add map to %run with -n flag
wilywampa Mar 10, 2016
206a238
Handle no metadata
wilywampa Apr 2, 2016
c592d70
Better handling of brackets in complete findstart
wilywampa Apr 4, 2016
7e418c5
Improve completion edge cases
wilywampa Apr 21, 2016
c624274
Make help requests for magics work right
wilywampa Apr 21, 2016
8bea179
Escape funcsigs with backticks to not confuse rst
wilywampa Apr 21, 2016
0c32d06
Fix escaping of 'Init signature:'
wilywampa Apr 24, 2016
15773a0
Clean up open file descriptors
wilywampa Apr 30, 2016
67e5046
Better check for signature line
wilywampa May 1, 2016
0589ec2
Fix error when null bytes exist in metadata
wilywampa May 29, 2016
4f39105
Delete argspec from doc to fix SyntaxError
wilywampa May 30, 2016
a38a5e4
Fix function existence check
wilywampa Jun 12, 2016
dc67fda
Fix potential KeyError
wilywampa Jul 13, 2016
021e9c3
Use dicts for completion metadata instead of strs
wilywampa Jul 13, 2016
655a7dc
Initial commit of monitor.py script
wilywampa Jul 14, 2016
953abc2
Rename metadata fields to match Vim naming
wilywampa Jul 14, 2016
e5e9d59
Disallow stdin until input_requests are handled
wilywampa Jul 14, 2016
ed4c2dc
Add documentation for metadata and monitor
wilywampa Jul 14, 2016
0437e45
Add history Unite source
wilywampa Jul 15, 2016
4dc32dd
Fix run_these_lines() maps
wilywampa Jul 15, 2016
773b067
Add RunCell implementation (run paragraph)
wilywampa Jul 19, 2016
9dd97ec
Replace Result class with dict in process_matches
wilywampa Nov 6, 2016
1f9d1da
Don't cause an exception if metadata doesn't exist
wilywampa Nov 8, 2016
a66b4a1
Don't require 'word' in the metadata dict
wilywampa Nov 8, 2016
d07dd0a
Move comment to the right place
wilywampa Nov 8, 2016
ba8d8fe
Don't use dictionary comprehension
wilywampa Jan 28, 2017
eb566c8
Make doc buffer `nomodifiable`.
DerWeh Mar 15, 2017
2fb70d2
Merge pull request #3 from DerWeh/modifiable
wilywampa Mar 17, 2017
90350eb
Disable mapping
wilywampa Aug 6, 2017
6e02769
add code to allow answers to stdin requests by editing the last line …
Aug 21, 2017
4e931ec
Added IPythonInput and IPythonInputSecret commands
Aug 27, 2017
a195417
Removed option to reply to stdin requests by editing vim-ipython buff…
Aug 27, 2017
69f9a52
Merge pull request #4 from jmriego/stdin_requests
wilywampa Aug 28, 2017
89b84e1
Handle relative filenames for the connection file
wilywampa Dec 30, 2017
a8c25b8
Fix exception on non-existent relative path
wilywampa Jan 21, 2018
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
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ vim-ipython from defining any of the default mappings.
By default, vim-ipython activates the custom completefunc globally.
Sometimes, having a completefunc breaks other plugins' completions. Putting
the line ``let g:ipy_completefunc = 'local'`` in one's vimrc will activate the
IPython-based completion only for current buffer. Setting `g:ipy_completefunc`
to anything other than `'local'` or `'global'` disables it altogether.
IPython-based completion only for current buffer. Putting ``let
g:ipy_completefunc = 'omni'`` will set the omnifunc option for the current
buffer. Setting `g:ipy_completefunc` to anything other than `'local'` or
`'global'` disables it altogether.

**NEW since IPython 0.13**

Expand Down
197 changes: 197 additions & 0 deletions autoload/unite/sources/history_ipython.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
if exists('g:loaded_history_ipython')
finish
endif
let g:loaded_history_ipython = 1

let s:save_cpo = &cpo
set cpo&vim

function! unite#sources#history_ipython#define()
return s:source
endfunction

let s:source = {
\ 'name' : 'history/ipython',
\ 'description' : 'candidates from IPython history',
\ 'action_table' : {},
\ 'hooks' : {},
\ 'default_action' : 'send',
\ 'default_kind' : 'word',
\ 'syntax' : 'uniteSource__Python',
\ 'max_candidates' : 100,
\}

function! s:source.hooks.on_syntax(args, context)
let save_current_syntax = get(b:, 'current_syntax', '')
unlet! b:current_syntax

try
silent! syntax include @Python syntax/python.vim
syntax region uniteSource__IPythonPython
\ start=' ' end='$' contains=@Python containedin=uniteSource__IPython
let &l:iskeyword = substitute(&l:iskeyword, ',!$\|!,', '', '')
finally
let b:current_syntax = save_current_syntax
endtry
endfunction

function! s:source.hooks.on_init(args, context)
if !exists('*IPythonHistory')
call unite#print_source_error(
\ 'IPythonHistory() does not exist', s:source.name)
return
endif

let args = unite#helper#parse_source_args(a:args)
let a:context.source__session = get(a:context, 'source__session', -1)
if a:context.source__session == -1
let a:context.source__session = get(args, 0, -1)
endif
let a:context.source__input = a:context.input
if a:context.source__input == '' || a:context.unite__is_restart
let a:context.source__input = unite#util#input('Pattern: ',
\ a:context.source__input,
\ 'customlist,IPythonCmdComplete')
endif

call unite#print_source_message('Pattern: '
\ . a:context.source__input, s:source.name)
endfunction

function! s:source.gather_candidates(args, context)
if !exists('*IPythonHistory')
return []
endif

return map(IPythonHistory(a:context.source__input,
\ a:context.source__session), '{
\ "word" : v:val.code,
\ "abbr" : printf("'''''' %d/%d '''''' %s", v:val.session, v:val.line,
\ v:val.code =~ "\n" ?
\ "\n" . join(split(v:val.code, "\n")[:50], "\n") : v:val.code),
\ "is_multiline" : 1,
\ "source__session" : v:val.session,
\ "source__line" : v:val.line,
\ "source__context" : a:context,
\ "action__regtype" : "V",
\ }')
endfunction

let s:source.action_table.send = {
\ 'description' : 'run in IPython',
\ 'is_selectable' : 1,
\ }
function! s:source.action_table.send.func(candidates)
for candidate in a:candidates
let g:ipy_input = candidate.word
Python2or3 run_ipy_input()
silent! unlet g:ipy_input
endfor
endfunction

let s:source.action_table.session = {
\ 'description' : "get history for candidate's session",
\ 'is_quit' : 0,
\ 'is_invalidate_cache' : 1,
\ }
function! s:source.action_table.session.func(candidate)
let context = a:candidate.source__context
let context.source__input = unite#util#input('Pattern: ',
\ context.source__input,
\ 'customlist,IPythonCmdComplete')
let context.source__session = a:candidate.source__session
endfunction

let s:source.action_table.session_info = {
\ 'description' : "print information about a session",
\ 'is_quit' : 0,
\ }
function! s:source.action_table.session_info.func(candidate)
let store_history = get(g:, 'ipython_store_history', 1)
try
let g:ipython_store_history = 0
let session_info = [
\ "from IPython import get_ipython",
\ "def _session_info(session=0):",
\ " def date(d):",
\ " return d.strftime('%a %d%b%Y %T')",
\ " session_id, start, end, cmds, remark = " .
\ " get_ipython().history_manager.get_session_info(session)",
\ " val = 'start: {0}'.format(date(start))",
\ " if end:",
\ " val += '; end: {0}; {1} commands'.format(date(end), cmds)",
\ " return val",
\ ]
let g:ipy_input = join(session_info, "\n")
silent Python2or3 run_ipy_input(silent=True)
let g:ipy_input = printf('_session_info(%d)', a:candidate.source__session)
silent! unlet g:ipy_result
Python2or3 eval_ipy_input('g:ipy_result')
echomsg printf('session %d: %s',
\ a:candidate.source__session, g:ipy_result)
finally
let g:ipython_store_history = store_history
endtry
endfunction

let s:source.action_table.macro = {
\ 'description' : 'create IPython macro',
\ 'is_selectable' : 1,
\ }
function! s:source.action_table.macro.func(candidates)
let g:ipy_input = printf('%%macro %s %s',
\ unite#util#input('Macro name: '),
\ join(map(a:candidates,
\ 'printf("%s/%s", v:val.source__session, v:val.source__line)'))
\ )
Python2or3 run_ipy_input()
silent! unlet g:ipy_input
endfunction

let s:source.action_table.yank = {
\ 'description' : 'yank candidates',
\ 'is_selectable' : 1,
\ 'is_quit' : 1,
\ }
function! s:source.action_table.yank.func(candidates)
if len(a:candidates) == 1 && a:candidates[0].word !~ "\n"
let text = a:candidates[0].word
let mode = 'v'
else
let text = join(map(copy(a:candidates), 'v:val.word'), "\n\n")
let mode = 'V'
endif
call setreg('"', text, mode)
if has('clipboard')
if &clipboard =~# '\<unnamed\>'
call setreg('*', text, mode)
endif
if &clipboard =~# '\<unnamedplus\>'
call setreg('+', text, mode)
endif
endif

echohl Question | echo 'Yanked:' | echohl Normal
echo text
endfunction

let s:source.action_table.append = {
\ 'description' : 'append candidates',
\ 'is_selectable' : 1,
\ }
function! s:source.action_table.append.func(candidates)
put = join(map(copy(a:candidates), 'v:val.word'), \"\n\n\")
endfunction

let s:source.action_table.insert = {
\ 'description' : 'insert candidates',
\ 'is_selectable' : 1,
\ }
function! s:source.action_table.insert.func(candidates)
put! = join(map(copy(a:candidates), 'v:val.word'), \"\n\n\")
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo

" vim:set et ts=2 sts=2 sw=2:
159 changes: 159 additions & 0 deletions doc/ipython.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
*ipython.txt*

==============================================================================
Contents *vim-ipython-contents*

1. Completion Metadata |vim-ipython-metadata|
2. IPython Monitor |vim-ipython-monitor|
3. IPython History Unite Source |vim-ipython-history|
4. Variables |vim-ipython-variables|
4.1. g:ipy_autostart |g:ipy_autostart|
4.2. g:ipy_completefunc |g:ipy_completefunc|
4.3. g:ipy_input |g:ipy_input|
4.4. g:ipy_perform_mappings |g:ipy_perform_mappings|
4.5. g:ipython_completion_timeout |g:ipython_completion_timeout|
4.6. g:ipython_dictionary_completion |g:ipython_dictionary_completion|
4.7. g:ipython_greedy_matching |g:ipython_greedy_matching|
4.8. g:ipython_history_len |g:ipython_history_len|
4.9. g:ipython_history_raw |g:ipython_history_raw|
4.10. g:ipython_history_timeout |g:ipython_history_timeout|
4.11. g:ipython_history_unique |g:ipython_history_unique|
4.12. g:ipython_run_flags |g:ipython_run_flags|
4.13. g:ipython_store_history |g:ipython_store_history|
4.14. g:ipython_timeout |g:ipython_timeout|

==============================================================================
1. Completion Metadata *vim-ipython-metadata*

vim-ipython supports user-supplied metadata associated with completions from
the IPython shell. The plugin fetches the metadata from the IPython kernel
using the user-defined function `completion_metadata` which takes one
parameter - the result of `get_ipython()`. If the function does not exist in
IPython's namespace, completion will still work but without any menu/info
entries in the completion menu. Each completion match should have a
corresponding metadata dictionary with "word", "menu", and "info" fields. A
basic (and slow) implementation of such a function follows: >

def completion_metadata(ip):
import inspect
import six
metadata = [dict(word=m) for m in ip.Completer.matches]
for m in metadata:
try:
obj = eval(m['word'], ip.user_ns)
except Exception:
continue
m['menu'] = six.moves.reprlib.repr(obj)
info = inspect.getdoc(obj)
if info:
m['info'] = info
return metadata

==============================================================================
2. IPython Monitor *vim-ipython-monitor*

The included `monitor.py` script listens in on message from Vim to the IPython
kernel to echo inputs and outputs to the kernel in real-time. The script must
be started before connecting Vim to the IPython kernel so that it can
differentiate between Vim and the Jupyter shell clients. The `:IPython`
command can be executed multiple times without ill effect in case the monitor
is started later on.

Basic usage: >

$ python monitor.py &; jupyter console
:IPython

Note: Currently the script looks for a connection file automatically and will
connect to the first connection file it finds matching the glob pattern
"kernel-[0-9]*.json'. This means the script will not connect to IPython
notebook kernels by design.

==============================================================================
3. IPython History Unite Source *vim-ipython-history*

Note: Requires unite.vim: https://github.com/Shougo/unite.vim

The plugin includes a Unite source named "history/ipython" providing an
interface to the history messaging in IPython. The source will prompt for a
glob pattern to search for. If no pattern is provided, the search results in
up to |g:ipython_history_len| of the most recent IPython commands. If the
pattern begins or ends with a '*', the other end of the pattern is anchored at
the start or end of the match. For example, >

Pattern: def *

will return results that start with a function definition and >

Pattern: *)

will return results ending with ')'. Otherwise a '*' is both prepended
and appended to the pattern, so >

Pattern: sys

will return results containing "sys" anywhere.

The input prompt allows completion from the IPython namespace.

After selecting a history entry, the available actions are (in addition to
Unite's common actions):

- `append` (insert the entry after the cursor line)
- `insert` (insert the entry before the cursor line)
- `macro` (prompt for a macro name and create an IPython macro to repeat
the commands)
- `send` (repeat the command in IPython)
- `session` (restart the history/ipython source showing entries only from
the same session as the selected entry)
- `session_info` (print session date and start time)
- `yank` (yank entries to unnamed and clipboard if 'clipboard' is set)

Multiple history entries may be selected for all of the actions.

==============================================================================
4. Variables *vim-ipython-variables*

------------------------------------------------------------------------------
4.1. `g:ipy_autostart` *g:ipy_autostart*

------------------------------------------------------------------------------
4.2. `g:ipy_completefunc` *g:ipy_completefunc*

------------------------------------------------------------------------------
4.3. `g:ipy_input` *g:ipy_input*

------------------------------------------------------------------------------
4.4. `g:ipy_perform_mappings` *g:ipy_perform_mappings*

------------------------------------------------------------------------------
4.5. `g:ipython_completion_timeout` *g:ipython_completion_timeout*

------------------------------------------------------------------------------
4.6. `g:ipython_dictionary_completion` *g:ipython_dictionary_completion*

------------------------------------------------------------------------------
4.7. `g:ipython_greedy_matching` *g:ipython_greedy_matching*

------------------------------------------------------------------------------
4.8. `g:ipython_history_len` *g:ipython_history_len*

------------------------------------------------------------------------------
4.9. `g:ipython_history_raw` *g:ipython_history_raw*

------------------------------------------------------------------------------
4.10. `g:ipython_history_timeout` *g:ipython_history_timeout*

------------------------------------------------------------------------------
4.11. `g:ipython_history_unique` *g:ipython_history_unique*

------------------------------------------------------------------------------
4.12. `g:ipython_run_flags` *g:ipython_run_flags*

------------------------------------------------------------------------------
4.13. `g:ipython_store_history` *g:ipython_store_history*

------------------------------------------------------------------------------
4.14. `g:ipython_timeout` *g:ipython_timeout*

vim: textwidth=78 et filetype=help:norightleft:
Loading