Emacs tiene repeaty repeat-complex-command, que dibujan diferentes comandos del historial de comandos y están vinculados a diferentes teclas. ¿Cómo repite cualquier último comando, ya sea complejo o no, con una sola tecla? En otras palabras, tal comando repetitivo se comportaría como repeat-complex-commandsi el último comando requiriera entrada, de lo contrario se comportaría como repeat.
EDITAR : en otras palabras, estoy buscando una forma de leer el último comando, complejo o no, y luego llamarlo repeat-complex-commando repeathacerlo, según sea apropiado. Por ejemplo, supongamos que un nuevo comando está obligado a hacerlo <f8>. Entonces:
(imitando
C-x M-: (repeat-complex-command)conM-z (zap-to-char)):C-u M-z a <f8> <f8>será equivalente aC-u M-z a C-x M-: RET C-x M-: RET(imitando
C-x z (repeat)conC-f (forward-char)):C-u C-f <f8> <f8>será equivalente aC-u C-f C-x z z
Ahora, repeat-complex-commandrequiere que confirme el formulario Lisp que se ejecutará. Para permitir la repetición de un comando complejo sin confirmación, he escrito una versión alternativa de repeat-complex-command, llamada repeat-complex-command-no-confirm(ver más abajo para la implementación). El problema es que no puedo entender cómo determinar si debo llamar repeato repeat-complex-command-no-confirmal presionar <f8>.
-
(defun repeat-complex-command-no-confirm (arg)
"Like `repeat-complex-command' but does not require confirmation."
;; Adapted from `repeat-complex-command' of Emacs 24.5.1.
(interactive "p")
(let ((elt (nth (1- arg) command-history))
newcmd)
(if elt
(progn
(setq newcmd elt)
;; If command to be redone does not match front of history,
;; add it to the history.
(or (equal newcmd (car command-history))
(setq command-history (cons newcmd command-history)))
(unwind-protect
(progn
;; Trick called-interactively-p into thinking that `newcmd' is
;; an interactive call (bug#14136).
(add-hook 'called-interactively-p-functions
#'repeat-complex-command--called-interactively-skip)
(eval newcmd))
(remove-hook 'called-interactively-p-functions
#'repeat-complex-command--called-interactively-skip)))
(if command-history
(error "Argument %d is beyond length of command history" arg)
(error "There are no previous complex commands to repeat")))))