From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Suppress user-prompting when calling commands in programs
Date: Sat, 14 Jun 2014 21:58:03 -0400 [thread overview]
Message-ID: <jwvfvj754i7.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 87ioo3vr1v.fsf@gmail.com
> But what about a case like this, a command with several optional args,
> that are not always necessary. How to give the user the option to decide
> for which args he wants to give input (and use the defaults for the
> others)?
That's a UI issue more than a programming issue. The general design we
try to follow in Emacs in this respect is to only have 2 options:
either minimal prompting (the default) or full prompting (which the user
can request with C-u).
But that's completely up to the package's author.
> Where to put the (prefix) 'arg argument in this case? How does Emacs
> know which of the optional arguments should be the prefix-argument?
These questions can't be answered directly because they only indicate
a misunderstanding of what is the prefix argument.
> Do I need a "P" or "p" then somewhere in the spec when
> I add 'arg' to the arguments list?
"P" only means that the argument at that position will receive the value
of `current-prefix-arg'. And "p" does the same for
(prefix-numeric-value current-prefix-arg). You can call that argument
`arg', or `best-friends-for-ever', or any other name you like.
> (defun iorg-scrape-repl (&optional port host how local)
> "Run inferior Picolisp and setup process for GUI-scripting."
> (interactive
> (cond
> ((equal current-prefix-arg nil) nil)
> ((equal current-prefix-arg '(4))
> (list
> (read-number "Port: ")))
> ((equal current-prefix-arg '(16))
> (list
> (read-number "Port: ")
> (read-string "Host: ")))
> ((equal current-prefix-arg '(32))
> (list
> (read-number "Port: ")
> (read-string "Host: ")
> (read-string "How: ")))
> (t
> (list
> (read-number "Port: ")
> (read-string "Host: ")
> (read-string "How: ")
> (read-string "Local: ")))))
That would work.
As mentioned above, we usually prefer not to distinguish (4) from (16)
or any other value, other than nil, so it would be just:
(defun iorg-scrape-repl (&optional port host how local)
"Run inferior Picolisp and setup process for GUI-scripting."
(interactive
(when current-prefix-arg
(list
(read-number "Port: ")
(read-string "Host: ")
(read-string "How: ")
(read-string "Local: "))))
And then we'd try to reduce the worst-case prompting either by avoiding
some of the prompts depending on previous prompt's return value, or by
merging prompts. E.g.:
(defun iorg-scrape-repl (&optional port host how local)
"Run inferior Picolisp and setup process for GUI-scripting."
(interactive
(when current-prefix-arg
(let ((host+port (split-string (read-string "Host (and port): ")
":")))
`(,(nth 1 host+port)
,(nth 0 host+port)
,@(unless (equal (nth 0 host+port) "localhost")
(list (read-string "How: ")
(read-string "Local: "))))))))
-- Stefan
next prev parent reply other threads:[~2014-06-15 1:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-13 13:51 Suppress user-prompting when calling commands in programs Thorsten Jolitz
2014-06-13 14:03 ` Eli Zaretskii
2014-06-13 14:25 ` Stefan Monnier
2014-06-13 15:09 ` Thorsten Jolitz
2014-06-13 15:29 ` Drew Adams
2014-06-13 15:49 ` Thorsten Jolitz
2014-06-13 14:20 ` Nicolas Richard
2014-06-13 15:18 ` Thorsten Jolitz
2014-06-13 16:04 ` Drew Adams
2014-06-13 18:14 ` Thorsten Jolitz
2014-06-14 3:33 ` Eric Abrahamsen
2014-06-14 3:36 ` Drew Adams
2014-06-14 3:47 ` Eric Abrahamsen
[not found] ` <mailman.3579.1402672740.1147.help-gnu-emacs@gnu.org>
2014-06-13 18:55 ` Stefan Monnier
2014-06-14 8:07 ` Thorsten Jolitz
2014-06-14 8:22 ` Thorsten Jolitz
2014-06-15 1:58 ` Stefan Monnier [this message]
2014-06-14 15:52 ` Drew Adams
2014-06-14 16:27 ` Thorsten Jolitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvfvj754i7.fsf-monnier+gmane.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.