From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Placement of list within an interactive clause Date: Fri, 15 Jul 2022 13:14:25 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38027"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-06-11) Cc: carlmarcos@tutanota.com, Help Gnu Emacs To: Christopher Dimech Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 15 12:16:54 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oCINS-0009di-7U for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 15 Jul 2022 12:16:54 +0200 Original-Received: from localhost ([::1]:36208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oCINQ-0002Yg-Ok for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 15 Jul 2022 06:16:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCILr-0002YG-Cq for help-gnu-emacs@gnu.org; Fri, 15 Jul 2022 06:15:15 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:36637) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oCILp-0008UA-E3 for help-gnu-emacs@gnu.org; Fri, 15 Jul 2022 06:15:15 -0400 Original-Received: from localhost ([::ffff:154.225.39.176]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000A3C53.0000000062D13E2E.000070B1; Fri, 15 Jul 2022 03:15:09 -0700 Mail-Followup-To: Christopher Dimech , carlmarcos@tutanota.com, Help Gnu Emacs Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138487 Archived-At: * Christopher Dimech [2022-07-15 11:19]: > > Thus instead of following: > > > > (defun my-fun-1 (&optional name) > > (interactive "MName: ") > > (message "Hello %s" name)) > > > > I am using following: > > > > (defun my-fun-2 (&optional name) > > (interactive) > > (let ((name (or name (read-from-minibuffer "Name: ")))) > > (message "Hello %s" name))) > > > > as that gives me little more freedom: > > > > - if I call (my-fun-1) ⇒ "Hello nil" that result is not what I > > really want. It makes it difficult to get the wanted result. To > > get the wanted result I need to use: > > > > (call-interactively 'my-fun-1) ⇒ "Hello Bob" > > > > - but if I call (my-fun-2) and NAME is not supplied, I will be > > asked for name: (my-fun-2) ⇒ "Hello Bob" and will not get "NIL" > > as result. In this case I need not complicate the call and use > > `call-interactively`. > > > > Additionall, complex `interactive` clauses I find often too > > difficult to comprehend than reading the body of the function. > > Yes, but you are forced for interactive commands. It is not equivalent > to a function that is non-interactive. You are not forced to supply arguments within (interactive), not at all. Function may not need any arguments. But if it has prefix you should declare (interactive "P"). But if it needs some text input you may say (interactive "MInput: ") However, I have explained in the above example of mine that such input may be provided in the function itself. And it looks to me that it is better handled that way than through `interactive' declaration. So this is the way to go: (defun my-fun-2 (&optional name) (interactive) (let ((name (or name (read-from-minibuffer "Name: ")))) (message "Hello %s" name))) Function `interactive' DOES NOT make function "interactive" in the other contexts in English language, there is special meaning in the Emacs Lisp context. Programming meaning is simply not same to English context. To call function interactively, it means not to call it exclusively from Lisp, but from the user interface by using M-x or key. That means, when there is declaration (interactive), that function becomes accessible through M-x invokation, and it may be bound to a key. It means then you can run the function by pressing a key (that is what is meant with "interactively") or by invoking the function with M-x or through menus. IT DOES NOT EXCLUDE that other functions without the declaration "(interactive)" are and can be "interactive" in the meaning of English language. You may thus have a function that is command and that may be invoked interactively because of declaration "(interactive)": (defun my-fun-2 (&optional name) (interactive) (let ((name (or name (read-from-minibuffer "Name: ")))) (message "Hello %s" name))) And you may have interactive function, that interacts with user without declaration "(interactive)": (defun my-fun-3 (&optional name) (let ((name (or name (read-from-minibuffer "Name: ")))) (message "Hello %s" name))) And that function in the meaning of English language is interactive, but is not a command in the meaning of Emacs Lisp because it does not have declaration "(interactive)". ,---- | Specify a way of parsing arguments for interactive use of a function. | For example, write | (defun foo (arg buf) "Doc string" (interactive "P\nbbuffer: ") .... ) | to make ARG be the raw prefix argument, and set BUF to an existing buffer, | when ‘foo’ is called as a command. | | The "call" to ‘interactive’ is actually a declaration rather than a | function; it tells ‘call-interactively’ how to read arguments to pass | to the function. When actually called, ‘interactive’ just returns | nil. | | Usually the argument of ‘interactive’ is a string containing a code | letter followed optionally by a prompt. (Some code letters do not | use I/O to get the argument and do not use prompts.) To pass several | arguments to the command, concatenate the individual strings, | separating them by newline characters. | | Prompts are passed to ‘format’, and may use %s escapes to print the | arguments that have already been read. | | If the argument is not a string, it is evaluated to get a list of | arguments to pass to the command. | | Just ‘(interactive)’ means pass no arguments to the command when | calling interactively. `---- -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/