unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Running an extended command with default input?
@ 2016-03-07 15:09 egarrulo
  2016-03-07 18:38 ` John Mastro
  0 siblings, 1 reply; 2+ messages in thread
From: egarrulo @ 2016-03-07 15:09 UTC (permalink / raw)
  To: help-gnu-emacs

How can you run an extended command with a default input?  For example: 
`eval-expression` with `(+ 1 1)` as default input (in other words: what 
you would accomplish by typing `M-: (+ 1 1)` without RET).  This code 
works, but it seems to add an implicit RET:

(execute-kbd-macro (vconcat (kbd (substitute-command-keys 
"\\[eval-expression] "))
                             "(+ 1 1)"))

Thanks.


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

* Re: Running an extended command with default input?
  2016-03-07 15:09 Running an extended command with default input? egarrulo
@ 2016-03-07 18:38 ` John Mastro
  0 siblings, 0 replies; 2+ messages in thread
From: John Mastro @ 2016-03-07 18:38 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org; +Cc: egarrulo

egarrulo <egarrulo@gmail.com> wrote:
> How can you run an extended command with a default input? For example:
> `eval-expression` with `(+ 1 1)` as default input (in other words:
> what you would accomplish by typing `M-: (+ 1 1)` without RET). This
> code works, but it seems to add an implicit RET:
>
> (execute-kbd-macro (vconcat (kbd (substitute-command-keys "\\[eval-expression] "))
>                             "(+ 1 1)"))

One option is to define your own command, which reads the input itself
(providing the default) and then invokes the underlying command. For
instance, for ‘eval-expression’ you could do something like:

    (defun my-eval-expression (exp &optional insert-value)
      (interactive (list (read--expression "Eval: " "(+ 1 1)")
                         current-prefix-arg))
      (eval-expression exp insert-value))

-- 
john



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

end of thread, other threads:[~2016-03-07 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-07 15:09 Running an extended command with default input? egarrulo
2016-03-07 18:38 ` John Mastro

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