Right-click menu

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Right-click menu

Halim, Salman
Hello, all,

In Gvim, is there any way to customize the menu that pops up when the
user right-clicks in the text?  Is it possible to capture this motion
and create a menu dynamically?

I'm trying to have the right-click show alternative spelling suggestions
for the current word, basically...

Thank you,

Salman.
Reply | Threaded
Open this post in threaded view
|

Re: Right-click menu

A.J.Mechelynck
----- Original Message -----
From: "Halim, Salman" <[hidden email]>
To: "vim mailing list" <[hidden email]>
Sent: Thursday, July 21, 2005 6:32 PM
Subject: Right-click menu


> Hello, all,
>
> In Gvim, is there any way to customize the menu that pops up when the
> user right-clicks in the text?  Is it possible to capture this motion
> and create a menu dynamically?
>
> I'm trying to have the right-click show alternative spelling suggestions
> for the current word, basically...
>
> Thank you,
>
> Salman.

Method I (easiest for simple cases, but only in some GUI versions):
The menu that pops up if 'mousemodel' includes "popup" is the PopUp menu,
see ":help popup-menu". You can define it and change it just like any other
menu.

Method II (also for console Vim with mouse):
You could map <RightMouse> to whatever suited you, possibly using the
":popup" command to pop up any menu, or calling a function which first
creates a menu and then pops it up.


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: Right-click menu

Bram Moolenaar
In reply to this post by Halim, Salman

Salman Halim wrote:

> In Gvim, is there any way to customize the menu that pops up when the
> user right-clicks in the text?  Is it possible to capture this motion
> and create a menu dynamically?
>
> I'm trying to have the right-click show alternative spelling
> suggestions for the current word, basically...

This currently is not possible.

I think what we would want is an autocommand event that is triggered
just before the popup menu is displayed:  "MenuPopup".  I'll see if that
can be implemented...  Yes, that's quite easy.  I'll also make a first
version of the popup menu entry.  Try it out in the next snapshot.

--
The war between Emacs and Vi is over.  Vi has won with 3 to 1.
                        http://www.ssc.com/lg/issue30/raymond.html

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: Right-click menu

Tim Chase-2
In reply to this post by A.J.Mechelynck
> Method I (easiest for simple cases, but only in some GUI versions):
> The menu that pops up if 'mousemodel' includes "popup" is the PopUp
> menu, see ":help popup-menu". You can define it and change it just like
> any other menu.

A little tweaking to this experimental function may do what Tony
describes.

function! SpellCheck()
     let l:curWord = expand("<cword>")
     if l:curWord == 'this' " do something that returns a boolean
     " based on whether the current word is incorrect or not

         " set a variable with all the alternatives
         let l:alternatives='the#this#foo'

         unmenu PopUp
         while l:alternatives=~'#'
             let l:alternative = substitute(l:alternatives,
"#.*", "", "")
             let l:alternatives = substitute(l:alternatives,
"^[^#]*#", "", "")
             exec "menu PopUp.".l:alternative.'
"_ciw'.l:alternative."\x1b"
         endwhile
         let l:alternative = substitute(l:alternatives, "#.*",
"", "")
         exec "menu PopUp.".l:alternative.'
"_ciw'.l:alternative."\x1b"
     else
         unmenu PopUp
     endif
endfunction


HTH,

-tim




Reply | Threaded
Open this post in threaded view
|

Re: Right-click menu

Tim Chase-2
In reply to this post by Halim, Salman
>> exec "menu PopUp.".l:alternative.' "_ciw'.l:alternative."\x1b"
>
> Thank you very much; I admit I don't understand the _ before
> the ciw and the \xlb bit afterwards.

Note that the "-character is inside single-quotes. This, in
normal mode, issues

        "_ciw

which uses the black-hole (":help quote_") register so that your
regular register doesn't get tromped on by the change. It then
changes the inner word (the "ciw" bit) to the replacement text,
and then "types" escape ("\x1b") to leave the insert mode.

You can do it without the "_ involved, you'll just get your
default register populated with the misspelled word you replaced.

Hope this helps shed some light on what's goin' on.

-tim