Pregunta

I know that M-x (execute-extended-command) allows one to call a command in Emacs by typing its name. That however doesn't allow me to call command with arguments, e.g "backward-word 5"

I am aware that C-5 M-b produces the desired result but I am looking for a general method.

Does anyone know how to do this?

Thanks, Danny

¿Fue útil?

Solución 2

@abo-abo provided the general answer: use M-:.

  1. However, if you are interested not only in obtaining the side effects of the evaluation, and not only in a cursory overview of the return value, but in the full return value (regardless of its size and complexity), then vanilla Emacs M-: is not what you want.

    For that, I substitute pp-eval-expression for eval-expression wrt its key bindings (including M-:), and I recommend this practice for others too:

    (substitute-key-definition 'eval-expression 'pp-eval-expression global-map)

    That pretty-prints the return value, and you can make it print the complete value (no ellipses: ...).

  2. In addition, I offer a modified version of pp-eval-expression in library pp+.el. It has these advantages:

    • Reads with completion, using pp-read-expression-map.
    • Emacs-Lisp mode indentation and completion key bindings are available during input.
    • With a prefix arg, inserts the resulting value into the current buffer at point.
    • With a negative prefix arg, if the return value is a string, inserts it into the buffer without double-quotes (").
    • Font-locks the return value (syntax highlighting) for Emacs-Lisp mode. (And during display emacs-lisp-mode-hook and change-major-mode-hook are inhibited.)
    • Respects new user options pp-eval-expression-print-length, pp-eval-expression-print-level, and standard option eval-expression-debug-on-error. The former are separate from the similar, standard options eval-expression-print-length and eval-expression-print-level because the use cases are typically different.
  3. If you use library Icicles then you get the same advantages as library pp+.el -- no need to load pp+.el also.

Otros consejos

Eval it: M-: (backward-word 5) RET.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top