all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#62563: [FR] Expose `interactive' arg handling as an Elisp function
@ 2023-03-31  7:27 Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-03-31  7:38 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-03-31  7:27 UTC (permalink / raw)
  To: 62563

Hello,

I find myself sometimes needing to manually write code that do the same
job as the string-form `interactive' would do, like "read for an
existing file name" (the "f" form), etc.  This happens because I want to
do the following conversion.  

--8<---------------cut here---------------start------------->8---
(defun foo (fname)
  (interactive "f")
  (ignore fname))

(defun foo (fname bar)
  (interactive
   (list (simulate-interactive-f)
         (get-bar)))
  (ignore fname bar))
--8<---------------cut here---------------end--------------->8---

In short, this is useful when I need to add an interactive argument that
is not already covered by interactive codes, so I have to use the more
verbose interactive list form.

Currently, the code that handles interactive codes is written as part of
`call-interactively'.  This is in src/callint.c,
DEFUN("call-interactively").

In fact, there is already _a way_ to do it (I consider it more like a
workaround).  However, I think my proposal might be more concise than
the workaround for readers.  And also more performant, since the
workaround unnecessarily creates a lambda and then extracts its
interactive form, only to make use of the result of its interactive
code.

--8<---------------cut here---------------start------------->8---
(call-interactively (lambda (f) (interactive "f") f))
--8<---------------cut here---------------end--------------->8---

If people are in favor of exposing the interactive codes, I imagine it
can be defined as `interactive-handle-code (code &optional prompt)', and
I would be able to do this:

--8<---------------cut here---------------start------------->8---
(interactive-handle-code ?f)
(interactive-handle-code ?M "Insert some random text: ")
;; etc
--8<---------------cut here---------------end--------------->8---

Alternatively, if we believe that my c-i + λ workaround is sufficiently
small, we could advise people in the same boat to follow suit?  That
implies modifying the `interactive' docstring and (info "(elisp)
Interactive Codes").

-- 
Best,


RY





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-09-19 10:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-31  7:27 bug#62563: [FR] Expose `interactive' arg handling as an Elisp function Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-31  7:38 ` Eli Zaretskii
2023-09-11 23:54   ` Stefan Kangas
2023-09-17  0:50     ` Michael Heerdegen
2023-09-17 11:31       ` Stefan Kangas
2023-09-18  4:28         ` Michael Heerdegen
2023-09-19 10:21         ` Richard Stallman

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.