help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: How to write (interactive) with user-selection from predefined enume


From: Drew Adams
Subject: RE: How to write (interactive) with user-selection from predefined enumeration? (was Re: (interactive "rP") valid?)
Date: Tue, 28 May 2013 10:27:44 -0700 (PDT)

> OK, I did read the 'interactive' section of the manual again, but I did
> not find the answer to this question (although it is most likely there,
> somehere):

Hm.  "Most likely there somewhere".  Does that mean that you did not spend
time looking for it or you did spend time and couldn't find it?

If the latter, use `M-x report-emacs-bug', to let Emacs Dev know what's
missing - say just how you looked and what you think would have made your
search easier.  Emacs Dev is usually open to improvement suggestions, such
as adding index entries or clarifying the text.

If the former, I have only a little sympathy.  Sure, it might seem easier
to write a question here (and again, there is nothing wrong with that).
But learning to take advantage of the Emacs doc and help system
(`C-h f interactive') yourself is a win for everyone, especially you.

> How to write an interactive function and let the user choose from a list
> (an enumeration) of possible solutions as input (like: Item1 | Item2 |
> Item3)?

Wrt the original question, (elisp) `Using Interactive' (the first target reached
from `i interactive') gives two examples using \n, and it says:

 "It may be a string; its contents are a sequence of elements separated
  by newlines, one for each argument(1)."

And that node cross-references node `Interactive Codes', which explains more.

As to your new question, what is each ItemN?  Just any old name, or the name
of a particular kind of Emacs object?

Node `Interactive Codes' explains about code chars that allow for completion
(of choices).  It says that you get this for choosing the name of a function,
buffer, command, directory, file, user option, or coding system.

Beyond that, node `Using Interactive' explains that the `interactive' spec can
be a Lisp sexp that returns a list of args to be passed to the command.  You
really cannot get more general than that: you can do pretty much anything here.

`Using Interactive' explains how to code such a list.  As one example, you can
use `completing-read' to read a user choice among any kind of completion
candidates (not just names of functions, buffers, commands, directories, files,
options, and coding systems).

What more do you need?  The manual is your friend.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]