all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Philip Kaludercic <philipk@posteo.net>
Cc: Dr Rainer Woitok <rainer.woitok@gmail.com>, Help-Gnu-Emacs@Gnu.Org
Subject: Re: (interactive) and &optional
Date: Sat, 25 Mar 2023 00:42:49 +0300	[thread overview]
Message-ID: <ZB4ZWaoszukq9q4X@protected.localdomain> (raw)
In-Reply-To: <87sfdt6feg.fsf@posteo.net>

* 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/



  parent reply	other threads:[~2023-03-24 21:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23 19:10 (interactive) and &optional Dr Rainer Woitok
2023-03-23 19:20 ` Philip Kaludercic
2023-03-25 12:35   ` Dr Rainer Woitok
2023-03-25 13:12     ` Philip Kaludercic
2023-03-25 14:33       ` [External] : " Drew Adams
2023-03-25 15:36         ` Dr Rainer Woitok
2023-03-25 16:58         ` Philip Kaludercic
2023-03-23 20:01 ` Emanuel Berg
2023-03-24  9:23 ` Jean Louis
2023-03-24 20:52   ` Philip Kaludercic
2023-03-24 21:07     ` Emanuel Berg
2023-03-27  1:52       ` [External] : " Drew Adams
2023-03-27  2:40         ` John Yates
2023-03-24 21:42     ` Jean Louis [this message]
2023-03-26  1:04       ` Emanuel Berg
2023-03-30 19:04         ` Jean Louis
2023-03-25 12:05   ` Dr Rainer Woitok
2023-03-25 14:32     ` Jean Louis
2023-03-25 15:41       ` Dr Rainer Woitok

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZB4ZWaoszukq9q4X@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=Help-Gnu-Emacs@Gnu.Org \
    --cc=philipk@posteo.net \
    --cc=rainer.woitok@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.