From: Drew Adams <drew.adams@oracle.com>
To: Thorsten Jolitz <tjolitz@gmail.com>, help-gnu-emacs@gnu.org
Subject: RE: Suppress user-prompting when calling commands in programs
Date: Fri, 13 Jun 2014 09:04:53 -0700 (PDT) [thread overview]
Message-ID: <5b284aa3-068d-461d-a95b-52cd97ba292a@default> (raw)
In-Reply-To: <878up0kfcv.fsf@gmail.com>
> > OTOH, is it really not possible to change the function upstream ? "bar"
> > could be made an optional argument upstream (possibly with proper
> > interactive spec), or the body of the let form could be factored out as
> > a function for you to use.
>
> I tried convincing upstream before and never made it!
Try again.
> And I actually understand the authors of code like that and even copied
> that technique sometimes, because it might be harder to write the
> interactive spec for both interactive and programmatical use than to
> write the function itself, and then there is no need for a wrapper
> command or interactive (lambda ...) expression when it comes to define
> a key for that command.
Huh? Instead of:
(defun foo (&optional arg)
(interactive "P")
(let ((bar (org-icompleting-read ...)))
...))
What's wrong with them pushing the read into the interactive spec?
(defun foo (&optional arg bar)
(interactive (list current-prefix-arg
(org-icompleting-read ...))))
...)
That's the recommended approach, in general.
Or if the (org-icompleting-read ...) code itself uses the prefix
arg as the variable ARG, then rename such occurrences of ARG to,
say, PREF), and bind PREF before invoking `org-icompleting-read':
(defun foo (&optional arg bar)
(interactive
(let ((pref current-prefix-arg))
(list pref (org-icompleting-read ...))))
...)
Or if they really want to leave the beginning of the code the
same for some reason, they could at least factor out the body
(the second "..."), so you can invoke that code directly:
(defun foo (&optional arg)
(interactive "P")
(let ((bar (org-icompleting-read ...)))
(foo-guts arg bar))) ; <== Just a wrapper for the body.
; No other code changes needed.
Then your code would just call `foo-guts'.
> But OTOH its a shame that many commands are hard/impossible to reuse in
> programs because of this 'trick'.
A shame and unnecessary.
next prev parent reply other threads:[~2014-06-13 16:04 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-13 13:51 Suppress user-prompting when calling commands in programs Thorsten Jolitz
2014-06-13 14:03 ` Eli Zaretskii
2014-06-13 14:25 ` Stefan Monnier
2014-06-13 15:09 ` Thorsten Jolitz
2014-06-13 15:29 ` Drew Adams
2014-06-13 15:49 ` Thorsten Jolitz
2014-06-13 14:20 ` Nicolas Richard
2014-06-13 15:18 ` Thorsten Jolitz
2014-06-13 16:04 ` Drew Adams [this message]
2014-06-13 18:14 ` Thorsten Jolitz
2014-06-14 3:33 ` Eric Abrahamsen
2014-06-14 3:36 ` Drew Adams
2014-06-14 3:47 ` Eric Abrahamsen
[not found] ` <mailman.3579.1402672740.1147.help-gnu-emacs@gnu.org>
2014-06-13 18:55 ` Stefan Monnier
2014-06-14 8:07 ` Thorsten Jolitz
2014-06-14 8:22 ` Thorsten Jolitz
2014-06-15 1:58 ` Stefan Monnier
2014-06-14 15:52 ` Drew Adams
2014-06-14 16:27 ` Thorsten Jolitz
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=5b284aa3-068d-461d-a95b-52cd97ba292a@default \
--to=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=tjolitz@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.
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).