Skip to content

Commit

Permalink
Add hydra-repeat': hydra-specific repeat'
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
abo-abo committed Feb 27, 2015
1 parent 9fc928b commit 7de26d0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hydra.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7de26d0

Please sign in to comment.