From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Suppress user-prompting when calling commands in programs Date: Sat, 14 Jun 2014 21:58:03 -0400 Message-ID: References: <87r42skjd8.fsf@gmail.com> <877g4k7ux4.fsf@geodiff-mac3.ulb.ac.be> <87mwdfvrqd.fsf@gmail.com> <87ioo3vr1v.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1402797534 31529 80.91.229.3 (15 Jun 2014 01:58:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 15 Jun 2014 01:58:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 15 03:58:46 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WvziX-0006GT-Qz for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Jun 2014 03:58:45 +0200 Original-Received: from localhost ([::1]:37285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvziX-0000kR-Gr for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Jun 2014 21:58:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvziF-0000kF-SI for help-gnu-emacs@gnu.org; Sat, 14 Jun 2014 21:58:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wvzi8-0002Lp-CY for help-gnu-emacs@gnu.org; Sat, 14 Jun 2014 21:58:27 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:35566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wvzi8-0002Ll-5J for help-gnu-emacs@gnu.org; Sat, 14 Jun 2014 21:58:20 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1Wvzi7-0005rU-Bv for help-gnu-emacs@gnu.org; Sun, 15 Jun 2014 03:58:19 +0200 Original-Received: from 75-119-224-253.dsl.teksavvy.com ([75.119.224.253]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 15 Jun 2014 03:58:19 +0200 Original-Received: from monnier by 75-119-224-253.dsl.teksavvy.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 15 Jun 2014 03:58:19 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 81 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 75-119-224-253.dsl.teksavvy.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) Cancel-Lock: sha1:+M8CKX6WcPFoR7jQ3l764lgHBsc= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:98272 Archived-At: > 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