help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: (interactive) and &optional


From: Jean Louis
Subject: Re: (interactive) and &optional
Date: Sat, 25 Mar 2023 17:32:06 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Dr Rainer Woitok <rainer.woitok@gmail.com> [2023-03-25 15:05]:
> > I do not like involving `interactive' at all, so I do the handling by
> > providing optional argument and telling function to check for it, or
> > ask for it.
> > 
> > (defun search-something (&optional query)
> >   "Search something by using QUERY."
> >   (interactive)
> >   (let* ((query (or query (read-from-minibuffer "Query: "))))
> >     (do-the-search query)))
> 
> Correct me if I'm wrong,  but doesn't this  unconditionally call  "read-
> from-minibuffer"  when non-interactively called  without argument?  Non-
> interactively I would like the function to simply use my default value.

Yet, it calls unconditionally if that is the choice of programmer.

If you want default value, then you can do so:

(let* ((query (or query my-default-value (read-from-minibuffer "Query: "))))
  (do-the-search query)))

or like this:

(let* ((query (or query my-default-value)))
  (do-the-search query))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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