how to write omnifunction?

8 views
Skip to first unread message

aleCodd

unread,
Aug 17, 2010, 2:28:03 AM8/17/10
to v...@vim.org

I would like the items in the popupmenu to be more than simple strings, i
mean that after i select an item i want the cursor to automatically jump to
specific locations.

let me give a simple example, from JavaScript:
when i type:
document.getEle
and then
<c-x><c-o>
i want it to complete to
document.getElementById()
but that is NOT enough, i want the cursor to MOVE <left>, so it will already
be between the parentheses after i select the completion.

Now, in the help files there is a vague paragraph that implies that
theoretically this is possible, i mean in insert.txt (line 613)
it says the following:
"Note: While completion is active Insert mode can't be used
recursively.
Mappings that somehow invoke ":normal i.." will generate an E523
error."

I mean, it warns against invoking the insert mode recursively, but could it
be possible in the first place?
Because in order to invoke the :normal command you must first ESCAPE the
insert mode, now what is the trick to do that from INSIDE an item of the
popupmenu?
if i look in the example (insert.txt line 1059), the res variable is always
set to a list of "simple" strings that do no more than to complete a string
but not so much as to complete the magic by jumping the cursor from place to
place, and in order to do that, you must first ESCAPE the insert mode or to
let the function interpret the <left><up> etc. inside the strings (as in
mapping and abbreviations), but can we do that?


Thanks in advance for ANY help, please keep in mind that im new to vim so
that ANY help would be much appreciated.

Alex
--
View this message in context: http://vim.1045645.n5.nabble.com/how-to-write-omnifunction-tp2637764p2637764.html
Sent from the Vim - General mailing list archive at Nabble.com.

Tony Mechelynck

unread,
Aug 17, 2010, 4:07:40 AM8/17/10
to vim...@googlegroups.com, aleCodd, v...@vim.org

Did you try ending your completion text with "\<Left>" e.g. :return
"document.getElementById()\<Left>" (with double quotes and a backslash
before the less-than sign)? (I haven't, so I don't know if it works.)

See
:help expr-quote
:help complete-functions

Best regards,
Tony.
--
"God gives burdens; also shoulders"

Jimmy Carter cited this Jewish saying in his concession speech at the
end of the 1980 election. At least he said it was a Jewish saying; I
can't find it anywhere. I'm sure he's telling the truth though; why
would he lie about a thing like that?
-- Arthur Naiman, "Every Goy's Guide to Yiddish"

ale

unread,
Aug 17, 2010, 6:37:27 AM8/17/10
to vim_use
<cite>
Did you try ending your completion text with "\<Left>" e.g. :return
"document.getElementById()\<Left>" (with double quotes and a backslash
before the less-than sign)? (I haven't, so I don't know if it works.)
</cite>

unfortunately it doesnt work..

alex

ale

unread,
Aug 17, 2010, 6:37:48 AM8/17/10
to vim_use
<cite>
Did you try ending your completion text with "\<Left>" e.g. :return
"document.getElementById()\<Left>" (with double quotes and a backslash
before the less-than sign)? (I haven't, so I don't know if it works.)

aleCodd

unread,
Aug 17, 2010, 5:21:06 AM8/17/10
to v...@vim.org
ok..next time
but why didn't you forwayd my reply
and why do i have still to wait for every reply, with all due respect...its like torture..
why should i have to wait hours just to get my answer through...

maybe somebody wants to help but now i will have to wait for tomorrow before he sees the message again

thanks
alex

On Tue, Aug 17, 2010 at 6:08 PM, Tony Mechelynck [via VIM] <[hidden email]> wrote:
On 17/08/10 08:28, aleCodd wrote:

>
> I would like the items in the popupmenu to be more than simple strings, i
> mean that after i select an item i want the cursor to automatically jump to
> specific locations.
>u
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php



View message @ http://vim.1045645.n5.nabble.com/how-to-write-omnifunction-tp2637764p2637823.html
To unsubscribe from how to write omnifunction?, click here.




View this message in context: Re: how to write omnifunction?

aleCodd

unread,
Aug 17, 2010, 5:25:37 AM8/17/10
to v...@vim.org
just noticed that you helped me in the forum :-)
thanks...
hope youve seen the answer and the script i linked


cheers
alex

On Tue, Aug 17, 2010 at 6:08 PM, Tony Mechelynck [via VIM] <[hidden email]> wrote:
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php



View message @ http://vim.1045645.n5.nabble.com/how-to-write-omnifunction-tp2637764p2637823.html
To unsubscribe from how to write omnifunction?, click here.




View this message in context: Re: how to write omnifunction?

aleCodd

unread,
Aug 17, 2010, 5:00:09 AM8/17/10
to v...@vim.org

just a minor correction to the script...
i.e. the line "return start" was moved after "endwhile" as it should be...
here is the script: http://vim.1045645.n5.nabble.com/file/n2637872/test
test
--
View this message in context: http://vim.1045645.n5.nabble.com/how-to-write-omnifunction-tp2637764p2637872.html

aleCodd

unread,
Aug 17, 2010, 4:48:40 AM8/17/10
to v...@vim.org

seems like the right answer, but what i get is the following:
getElementById()<80>kl

can you please check the linked script
http://vim.1045645.n5.nabble.com/file/n2637863/test test ?
thanks
--
View this message in context: http://vim.1045645.n5.nabble.com/how-to-write-omnifunction-tp2637764p2637863.html

Christian Brabandt

unread,
Aug 18, 2010, 3:13:09 PM8/18/10
to v...@vim.org
Hi aleCodd!

On Di, 17 Aug 2010, aleCodd wrote:

>
> just a minor correction to the script...
> i.e. the line "return start" was moved after "endwhile" as it should be...
> here is the script: http://vim.1045645.n5.nabble.com/file/n2637872/test
> test

I am not sure that is possible, what you want.
You can however do map e.g. C-Y to move the cursor after selecting the
entry from the popup menu.

e.g. something like this:
inoremap <expr> <C-Y> pumvisible() ? "\<lt>C-Y>\<lt>Left>" : "\<lt>C-Y>"

However, I don't think you can move the cursor depending on which item
was selected. There seems no function available that tells you which
match is currently selected.

regards,
Christian

Reply all
Reply to author
Forward
0 new messages