Skip to content

Instantly share code, notes, and snippets.

@bowbow99
Created January 30, 2011 07:28
Show Gist options
  • Select an option

  • Save bowbow99/802650 to your computer and use it in GitHub Desktop.

Select an option

Save bowbow99/802650 to your computer and use it in GitHub Desktop.
`e' だけ(`C-x' なし)で kbd-macro を繰り返す #xyzzy
;;; repeat kbd-macro with just #\e (without #\C-x)
(let ((repeating nil))
(labels ((check-repeating-kbd-macro ()
(unless (member *this-command*
'(execute-last-kbd-macro
repeat-kbd-macro-or-self-insert
universal-argument
digit-argument
negative-argument))
(setf repeating nil)
(delete-hook '*pre-command-hook* #'check-repeating-kbd-macro))))
(defun repeat-kbd-macro-or-self-insert (&optional (arg 1))
(interactive "*p")
(if repeating
(call-interactively 'execute-last-kbd-macro)
(call-interactively 'self-insert-command)))
(defun execute-last-kbd-macro (&optional (arg 1))
(interactive "*p")
(call-interactively 'call-last-kbd-macro)
(setf repeating t)
(unless (and (boundp '*pre-command-hook*)
(member #'check-repeating-kbd-macro *pre-command-hook*))
(add-hook '*pre-command-hook* #'check-repeating-kbd-macro)))
)) ; let, labels
(define-key *global-keymap* #\e 'repeat-kbd-macro-or-self-insert)
(define-key ctl-x-map #\e 'execute-last-kbd-macro)
@bowbow99
Copy link
Author

call-last-kbd-macro を実行すると *last-command* が kbd-macro で実行されたコマンドになってしまうので *pre-command-hook* など使うハメに。

@bowbow99
Copy link
Author

*pre-command-hook* が(xyzzy 起動後最初に add-hook されるまで?)unbound なことがあるみたいなのでチェックするようにした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment