1

Contents of wrapper.vim

func! Auto_complete(findstart, base)
    let l:start = a:findstart
    let l:base  = a:base
    let l:res   = []
python3 << EOF
import ac
ac.__main__()
EOF
    if a:findstart       #YUCK
        return l:start
endfunction

Contents of actual implementation def main(): import vim

    base = vim.eval('a:base')
    findstart = vim.eval('a:findstart')

    # First invocation: 
    # findstart set to 1 and base is empty return int
    # between 0 and cursor_column, to indicate part of text between
    # return_position and cursor_column which is to be replaced
    if findstart == 1:
        set_position()
    else: # findstart == 0 and base = replacement_text
        feed_replacement_text()

I'm trying to write an omnicomplete function in python (C-X C-O). The first time the function is called:

On the first invocation the arguments are:
   a:findstart  1
   a:base   empty


On the second invocation the arguments are:
   a:findstart  0
   a:base   the text with which matches should match; the text that was
        located in the first call (can be empty)

The function must return a List with the matching words.  These matches
usually include the "a:base" text.  When there are no matches return an empty
List.

I want to avoid first passing to a:findstart, then saving to l:findstart (all this within the wrapper), then reading l:findstart and messing with it within the python module - finally doing a return l:start or a empty list. Trying to manage a 'global' variable and toggling it from different places is a pain.

Is there some way I can return values directly from the python module without ever doing a vimscript: return l:start. How do I deal directly from python w.r.t omnifunc and completefunc

  • 2
    Related questions [How to export a value from a python script back to vim?](http://stackoverflow.com/q/17656320), [How do I get the value returned from a function in Python & Vimscript?](http://stackoverflow.com/q/16756613). – glts Nov 08 '14 at 15:13
  • Hi, unfortunately that's not what I'm looking for :( but thanks for the links. –  Nov 09 '14 at 02:47
  • 1
    http://stackoverflow.com/questions/16756613/how-do-i-get-the-value-returned-from-a-function-in-python-vimscript This link deals with scope - the fact that you can do python3 << EOF def Login(): pass EOF OUTSIDE a vimscript function! ... endfunction. Obviously in this case you can just do a python: return client and expect the other python function to call and use Login, they share the same interpreter and scope. –  Nov 09 '14 at 02:50
  • http://stackoverflow.com/questions/17656320/using-python-in-vimscript-how-to-export-a-value-from-a-python-script-back-to-vi Sounds similar but deals with accessing a python/vim variable sInVim - this is a standard scoping question. –  Nov 09 '14 at 02:53
  • Both links are useful but don't address my question, which is about the internal Vimscript stack! A Vim-function is being called with certain arguments being passed via the stack. When i 'return' a value. it's again, passed via the stack - this is different from accessing sInVim which seems to be scoped locally - i'm not sure.. What i want to know is if there's a way to bypass the stack passing. –  Nov 09 '14 at 02:57

0 Answers0