unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Christopher Dimech <dimech@gmx.com>
To: Jean Louis <bugs@gnu.support>
Cc: carlmarcos@tutanota.com, Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Placement of list within an interactive clause
Date: Fri, 15 Jul 2022 12:32:58 +0200	[thread overview]
Message-ID: <trinity-11a9f333-32ae-422e-bf25-78b5961694c7-1657881178191@3c-app-mailcom-bs16> (raw)
In-Reply-To: <YtE+AfYzGNxwRX/G@protected.localdomain>



> Sent: Friday, July 15, 2022 at 10:14 PM
> From: "Jean Louis" <bugs@gnu.support>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: carlmarcos@tutanota.com, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Re: Placement of list within an interactive clause
>
> * Christopher Dimech <dimech@gmx.com> [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.

You can call it within lisp code for sure.  With interactive to set function 
arguments, you are also correct.  In the broader context of considering
any input from minibuffer as user interactive, it could make some problems.  


 
> 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/
> 
>



  reply	other threads:[~2022-07-15 10:32 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14 18:14 Placement of list within an interactive clause carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-14 18:34 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-14 19:24   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-14 20:15     ` Philip Kaludercic
2022-07-14 20:30     ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-14 20:52       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-14 21:12         ` Stefan Monnier
2022-07-14 21:15           ` carlmarcos--- via Users list for the GNU Emacs text editor
     [not found]         ` <jwv7d4f761t.fsf-monnier+emacs@gnu.org-N6yYlrA----2>
2022-07-16 23:01           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-17  2:38             ` Stefan Monnier
     [not found]             ` <jwvcze4pj2d.fsf-monnier+emacs@gnu.org-N790PCt----2>
2022-07-17  3:02               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-17 13:34                 ` Stefan Monnier
2022-07-14 21:23       ` [External] : " Drew Adams
2022-07-14 22:31       ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-14 22:52         ` [External] : " Drew Adams
     [not found]         ` <SJ0PR10MB54881126A1B0DB238AE8B82BF3889@SJ0PR10MB5488.namprd10.prod.outlook.com-N6yu_1j----2>
2022-07-15 20:05           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-15  7:26 ` Jean Louis
2022-07-15  8:19   ` Christopher Dimech
2022-07-15 10:14     ` Jean Louis
2022-07-15 10:32       ` Christopher Dimech [this message]
2022-07-15 21:03         ` Jean Louis
2022-07-15 21:22           ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-15 21:31             ` Jean Louis
2022-07-15 22:53               ` Christopher Dimech
     [not found]             ` <YtHcni0c1ZTL+V8R@protected.localdomain-N72lwEe----2>
2022-07-16 22:08               ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-16 23:40                 ` Jean Louis
2022-07-17  1:22                   ` [External] : " Drew Adams
2022-07-17  2:04                     ` RE: [External] : " Christopher Dimech
2022-07-17  1:53                   ` Christopher Dimech
2022-07-17  2:16                     ` Jean Louis
2022-07-17  2:46                       ` Christopher Dimech
2022-08-01 11:52       ` Emanuel Berg
2022-07-15 19:55   ` carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-15 21:08     ` Jean Louis
2022-07-15 21:54   ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-07-16 10:15     ` Jean Louis

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-11a9f333-32ae-422e-bf25-78b5961694c7-1657881178191@3c-app-mailcom-bs16 \
    --to=dimech@gmx.com \
    --cc=bugs@gnu.support \
    --cc=carlmarcos@tutanota.com \
    --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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).