help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Suppress user-prompting when calling commands in programs


From: Drew Adams
Subject: RE: Suppress user-prompting when calling commands in programs
Date: Fri, 13 Jun 2014 09:04:53 -0700 (PDT)

> > 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]