[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Placement of list within an interactive clause

From: carlmarcos
Subject: Re: Placement of list within an interactive clause
Date: Fri, 15 Jul 2022 21:55:17 +0200 (CEST)

Jul 15, 2022, 07:26 by

> Most of time I do not use `interactive' for supply arguments to
> function.
> 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.
> Fo this reason I recommend using this second approach with (or
> ARGUMENT (GET-ARGUMENT)) rather then using `interactive` with
> purpose to supply arguments.
> -- 
> Jean

If with GET-ARGUMENT you use a command that calls the minibuffer, then calling
the function in lisp code will ask the user for input.  Something that a pure 
call in elisp code does not normally do.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]