Add `hydra-repeat': hydra-specific `repeat'

* hydra.el (hydra-repeat): New defun.
(hydra-repeat--command): New defvar.
(hydra-repeat--prefix-arg): New defvar.

Example:

(defhydra hydra-vi ()
  "vi"
  ("h" backward-char)
  ("j" next-line)
  ("k" previous-line)
  ("l" forward-char)
  ("." hydra-repeat))
(global-set-key (kbd "C-v") 'hydra-vi/body)

"C-v 4l.." will result in movement forward by 4 chars 3 times: first
time from "4l", the other two from "..".

Fixes #59.
master
Oleh Krehel 11 years ago
parent 9fc928b8ab
commit 7de26d04a6
  1. 15
      hydra.el

@ -215,6 +215,21 @@ Vanquishable only through a blue head.")
(interactive "P")
(let ((universal-argument-map hydra-curr-map))
(negative-argument arg)))
;;* Repeat
(defvar hydra-repeat--prefix-arg nil
"Prefix arg to use with `hydra-repeat'.")
(defvar hydra-repeat--command nil
"Command to use with `hydra-repeat'.")
(defun hydra-repeat ()
"Repeat last command with last prefix arg."
(interactive)
(unless (string-match "hydra-repeat$" (symbol-name last-command))
(setq hydra-repeat--command last-command)
(setq hydra-repeat--prefix-arg (or last-prefix-arg 1)))
(setq current-prefix-arg hydra-repeat--prefix-arg)
(funcall hydra-repeat--command))
;;* Misc internals
(defvar hydra-last nil

Loading…
Cancel
Save