[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 00:42:49 +0300 |
User-agent: |
Mutt/2.2.9+54 (af2080d) (2022-11-21) |
* Philip Kaludercic <philipk@posteo.net> [2023-03-24 23:54]:
> > 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.
I understand the meaning in general, though I do not understand what
is the mentioned issue. Could you explain it?
It is interesting as I use those functions from other functions.
This should be the classic Emacs Lisp approach:
(defun search-something (query)
"Search something by using QUERY."
(interactive "MQuery: ")
(message query))
(progn (search-something "Hello")) ➜ "Hello"
(progn (search-something)) ➜ "Ok here"
This should be my approach:
(defun search-something (&optional query)
"Search something by using QUERY."
(interactive)
(let ((query (or query (read-from-minibuffer "Query: "))))
(message query)))
(progn (search-something "Hello")) ➜ "Hello"
(progn (search-something)) ➜ "Ok here"
- while `interactive' declaration may shorten some code, it may as
well complicated readability of function
Here is short version where buffer must be existing buffer:
(defun my-message-buffer (buffer)
"Message name of my BUFFER."
(interactive "b")
(message buffer))
That short function I do not know how to make easy without (interactive "b").
For majority of uses in my code I do not use arguments to
`interactive' and there are no issues so far.
I find `interactive' complex and would like to know why it was
invented.
(info "(elisp) Using Interactive")
(info "(elisp) Interactive Codes")
Tell me examples on what issues you encounter and pointers to
implications.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
Re: (interactive) and &optional, Emanuel Berg, 2023/03/23
Re: (interactive) and &optional, Jean Louis, 2023/03/24
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