[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (interactive) and &optional
From: |
Philip Kaludercic |
Subject: |
Re: (interactive) and &optional |
Date: |
Fri, 24 Mar 2023 20:52:23 +0000 |
Jean Louis <bugs@gnu.support> writes:
> * 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)))
The issue here is that the function is difficult to re-use from other
scripts. If the interactive stuff is encapsulated within an
(interactive) form then you avoid the issue.
--
Philip Kaludercic
Re: (interactive) and &optional, Emanuel Berg, 2023/03/23
Re: (interactive) and &optional, Jean Louis, 2023/03/24
- Re: (interactive) and &optional,
Philip Kaludercic <=
Re: (interactive) and &optional, Emanuel Berg, 2023/03/26
RE: [External] : Re: (interactive) and &optional, Drew Adams, 2023/03/26
Re: [External] : Re: (interactive) and &optional, John Yates, 2023/03/26
Re: (interactive) and &optional, Dr Rainer Woitok, 2023/03/25