unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ruijie Yu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 62563@debbugs.gnu.org
Subject: bug#62563: [FR] Expose `interactive' arg handling as an Elisp function
Date: Fri, 31 Mar 2023 15:27:47 +0800	[thread overview]
Message-ID: <sdvjzyx2xe4.fsf@fw.net.yu> (raw)

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





             reply	other threads:[~2023-03-31  7:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31  7:27 Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-03-31  7:38 ` bug#62563: [FR] Expose `interactive' arg handling as an Elisp function 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

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=sdvjzyx2xe4.fsf@fw.net.yu \
    --to=bug-gnu-emacs@gnu.org \
    --cc=62563@debbugs.gnu.org \
    --cc=ruijie@netyu.xyz \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).