How can user can select from list?

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

How can user can select from list?

David Nebauer
In a ftplugin of mine I occasionally need users to select an option from
a list.  Sometimes a list may have up to twenty options.  I have not
found an ideal method.  Here are the approaches I've tried:

1. confirm()
This is clearly intended to be used for only two or three options.  On
my platform (Debian) the GUI confirm widget extends off the screen if
there are too many options.

2. vimSpell|bufExplorer-like solution
In this method a menu is built in another buffer with suitable mappings
that call a function when one of the options is selected.  The problem
here is that control is passed from the calling function to the function
triggered when an option is selected.  This requires all sorts of
contortions in the scripting and prevents encapsulating this mechanism
as a single general-purpose 'SelectFromMenu' function.

3. popup
I have not explored this possibility in depth as the help text notes
that, "This command is for backwards compatibility, using it is
discouraged, because it behaves in a strange way."


I'm currently using Xdialog and a shell-script to handle menu selection
but would prefer a Vim-only solution.  I've scoured vim scripts, vim
tips and googled extensively -- crazy as it seems, I can find no
evidence this problem has ever been raised.  Either I'm the first person
to need to do this (very unlikely) or I have missed something blindingly
obvious (if so it's not for lack of looking!).

Any help gratefully appreciated.

Regards,
David.
Reply | Threaded
Open this post in threaded view
|

Re: How can user can select from list?

Steve Hall-4
On Mon, 2005-10-03 at 12:20 +0930, David Nebauer wrote:
> In a ftplugin of mine I occasionally need users to select an option
> from a list.  Sometimes a list may have up to twenty options.  I
> have not found an ideal method.

I have been begging for dialog checkboxes and radio buttons in
vimscript for years. :) Failing that...

By stacking the dialog buttons vertically (guioptions+=v), one can
have at least 8 items without running into the screen edge. (I am
comfortable stacking 11 + a Cancel button, on Windows and GTK.)

If these are static options, why not just put them into a menu?
Through clever submenus, Cream (cream.sf.net) places hundreds of
options into menus, some dynamically based on local conditions. We
like to show state (on/off) for options in the right column of a menu
item (after <Tab>).

Or you could parse the results of inputdialog(), offering suggestions
when the user enters something that is unparsable.


--
Steve Hall  [ digitect mindspring com ]


Reply | Threaded
Open this post in threaded view
|

Re: How can user can select from list?

Mikołaj Machowski
In reply to this post by David Nebauer
Dnia poniedzia?ek, 3 pa?dziernika 2005 04:50, David Nebauer napisa?:
> I'm currently using Xdialog and a shell-script to handle menu selection
> but would prefer a Vim-only solution.  I've scoured vim scripts, vim
> tips and googled extensively -- crazy as it seems, I can find no
> evidence this problem has ever been raised.  Either I'm the first person
> to need to do this (very unlikely) or I have missed something blindingly
> obvious (if so it's not for lack of looking!).
>
> Any help gratefully appreciated.
>

Create quasi menu with input() and check returned value.

In Vim7 there is inputlist() function.

m.
--
You have the right to remain silent. Anything you say will be misquoted,
then used against you.

Reply | Threaded
Open this post in threaded view
|

Re: How can user can select from list?

David Nebauer
In reply to this post by Steve Hall-4
Steve Hall wrote:

>>In a ftplugin of mine I occasionally need users to select an option
>>from a list.
>>
>
>I have been begging for dialog checkboxes and radio buttons in
>vimscript for years. :) Failing that...
>

I'll second that plea.  Perhaps in Vim7?

>By stacking the dialog buttons vertically (guioptions+=v), one can
>have at least 8 items without running into the screen edge.
>

There are often more options than this.

>If these are static options, why not just put them into a menu?
>

Unfortunately, they are not static options.  In any event you cannot, as
I understand it, force a user to make a menu selection at a specific
point in script execution unless you use popup/tearoff menus.  This is
advised against in the help system.

>Or you could parse the results of inputdialog(), offering suggestions
>when the user enters something that is unparsable.
>

This is a good idea, but it does not work for the cases I have in mind.  
The user does not know what the valid options are.  Even if they did, it
is faster and _error-proof_ to give them pre-set options to choose from.

Thanks for your suggestions.

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

Re: How can user can select from list?

David Nebauer
In reply to this post by Mikołaj Machowski
Mikolaj Machowski wrote:

>>I'm currently using Xdialog and a shell-script to handle menu selection
>>but would prefer a Vim-only solution.
>>
>
>Create quasi menu with input() and check returned value.
>

Since input() consists of a prompt and a default string, I presume by
"create quasi menu" you mean either:
A. Putting the possible options in the prompt string for the user to
read.  This would cause a massive prompt string which would look very
unwieldy.  It is also error-prone as the user must copy the desired option.
B. Putting the possible options in the default text and getting the user
to delete all but the desired option.  This would cause a massive
default input string which would be very unwieldy.  It also is error-prone.

Both approaches also suffer from the grievous sin of inelegance :) .

>In Vim7 there is inputlist() function.
>

Excellent.  This will solve the problem definitively.

Regards,
David.
Reply | Threaded
Open this post in threaded view
|

Re: How can user can select from list?

Mikołaj Machowski
Dnia poniedzia?ek, 3 pa?dziernika 2005 13:42, David Nebauer napisa?:

> Mikolaj Machowski wrote:
> >>I'm currently using Xdialog and a shell-script to handle menu
> >> selection but would prefer a Vim-only solution.
> >
> >Create quasi menu with input() and check returned value.
>
> Since input() consists of a prompt and a default string, I presume by
> "create quasi menu" you mean either:
> A. Putting the possible options in the prompt string for the user to
> read.  This would cause a massive prompt string which would look very
> unwieldy.  It is also error-prone as the user must copy the desired
> option.

1. It can be nicely formatted
2. It can took numbers as input

Check latex-Suite for that.

m.

Reply | Threaded
Open this post in threaded view
|

Re: How can user can select from list?

Hari Krishna Dara
In reply to this post by David Nebauer

On Mon, 3 Oct 2005 at 4:10pm, Mikolaj Machowski wrote:

> Dnia poniedzia?ek, 3 pa?dziernika 2005 13:42, David Nebauer napisa?:
> > Mikolaj Machowski wrote:
> > >>I'm currently using Xdialog and a shell-script to handle menu
> > >> selection but would prefer a Vim-only solution.
> > >
> > >Create quasi menu with input() and check returned value.
> >
> > Since input() consists of a prompt and a default string, I presume by
> > "create quasi menu" you mean either:
> > A. Putting the possible options in the prompt string for the user to
> > read.  This would cause a massive prompt string which would look very
> > unwieldy.  It is also error-prone as the user must copy the desired
> > option.
>
> 1. It can be nicely formatted
> 2. It can took numbers as input
>
> Check latex-Suite for that.
>
> m.
>

There are functions in multvals.vim for formatting a list of options and
prompting the user to select one. I use them in a couple of my plugins
to allow user to change options. Take a look at the MvPromptForElement
and MvPromptForElement2 functions, and the example usages at the end of
the file.

--
HTH,
Hari


               
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com