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

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

Re: Running an extended command with default input?


From: John Mastro
Subject: Re: Running an extended command with default input?
Date: Mon, 7 Mar 2016 10:38:39 -0800

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



reply via email to

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