[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Suppress user-prompting when calling commands in programs
From: |
Stefan Monnier |
Subject: |
Re: Suppress user-prompting when calling commands in programs |
Date: |
Sat, 14 Jun 2014 21:58:03 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) |
> 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
- Re: Suppress user-prompting when calling commands in programs, (continued)
- Re: Suppress user-prompting when calling commands in programs, Nicolas Richard, 2014/06/13
- Re: Suppress user-prompting when calling commands in programs, Thorsten Jolitz, 2014/06/13
- RE: Suppress user-prompting when calling commands in programs, Drew Adams, 2014/06/13
- Re: Suppress user-prompting when calling commands in programs, Thorsten Jolitz, 2014/06/13
- Re: Suppress user-prompting when calling commands in programs, Eric Abrahamsen, 2014/06/13
- RE: Suppress user-prompting when calling commands in programs, Drew Adams, 2014/06/13
- Re: Suppress user-prompting when calling commands in programs, Eric Abrahamsen, 2014/06/13
Message not available
RE: Suppress user-prompting when calling commands in programs, Drew Adams, 2014/06/14
Re: Suppress user-prompting when calling commands in programs, Thorsten Jolitz, 2014/06/14