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: Fri, 24 Mar 2023 12:23:29 +0300
User-agent: Mutt/2.2.9+54 (af2080d) (2022-11-21)

* Dr Rainer Woitok <rainer.woitok@gmail.com> [2023-03-23 22:12]:
> Am I really expected in a function that is both,  callable from Lisp and
> via "M-x", to code something along the lines of
> 
>    (cond ((or (null arg) (string-empty-p arg)) 'default-val)
>          (arg))
> 
> to check whether or not an optional argument has been passed?  Are there
> any more elegant ways to achieve this?

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

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