Skip to content

Commit

Permalink
Don't wrap `hydra-repeat'
Browse files Browse the repository at this point in the history
* hydra.el (hydra--delete-duplicates): Update.
(hydra--vconcat): Trim trailing spaces.

* hydra-test.el (hydra-red-error): Update test.
(hydra--table): Update test.
  • Loading branch information
abo-abo committed Feb 27, 2015
1 parent 8e90037 commit 41f98bd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
56 changes: 35 additions & 21 deletions hydra-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
"error"
("h" first-error "first")
("j" next-error "next")
("k" previous-error "prev")))
("k" previous-error "prev")
("SPC" hydra-repeat "rep" :bind nil)))
'(progn
(defun hydra-error/first-error nil "Create a hydra with a \"M-g\" body and the heads:
\"h\": `first-error',
\"j\": `next-error',
\"k\": `previous-error'
\"k\": `previous-error',
\"SPC\": `hydra-repeat'
The body can be accessed via `hydra-error/body'.
Expand All @@ -49,14 +51,16 @@ Call the head: `first-error'."
(hydra-disable)
(catch (quote hydra-disable)
(condition-case err (prog1 t (call-interactively (function first-error)))
((quit error) (message "%S" err)
((quit error)
(message "%S" err)
(unless hydra-lv (sit-for 0.8))
nil))
(when hydra-is-helpful (hydra-error/hint))
(setq hydra-last
(hydra-set-transient-map
(setq hydra-curr-map
(quote (keymap (7 . hydra-keyboard-quit)
(32 . hydra-repeat)
(107 . hydra-error/previous-error)
(106 . hydra-error/next-error)
(104 . hydra-error/first-error)
Expand Down Expand Up @@ -88,7 +92,8 @@ Call the head: `first-error'."
\"h\": `first-error',
\"j\": `next-error',
\"k\": `previous-error'
\"k\": `previous-error',
\"SPC\": `hydra-repeat'
The body can be accessed via `hydra-error/body'.
Expand All @@ -97,14 +102,16 @@ Call the head: `next-error'."
(hydra-disable)
(catch (quote hydra-disable)
(condition-case err (prog1 t (call-interactively (function next-error)))
((quit error) (message "%S" err)
((quit error)
(message "%S" err)
(unless hydra-lv (sit-for 0.8))
nil))
(when hydra-is-helpful (hydra-error/hint))
(setq hydra-last
(hydra-set-transient-map
(setq hydra-curr-map
(quote (keymap (7 . hydra-keyboard-quit)
(32 . hydra-repeat)
(107 . hydra-error/previous-error)
(106 . hydra-error/next-error)
(104 . hydra-error/first-error)
Expand Down Expand Up @@ -136,7 +143,8 @@ Call the head: `next-error'."
\"h\": `first-error',
\"j\": `next-error',
\"k\": `previous-error'
\"k\": `previous-error',
\"SPC\": `hydra-repeat'
The body can be accessed via `hydra-error/body'.
Expand All @@ -145,14 +153,16 @@ Call the head: `previous-error'."
(hydra-disable)
(catch (quote hydra-disable)
(condition-case err (prog1 t (call-interactively (function previous-error)))
((quit error) (message "%S" err)
((quit error)
(message "%S" err)
(unless hydra-lv (sit-for 0.8))
nil))
(when hydra-is-helpful (hydra-error/hint))
(setq hydra-last
(hydra-set-transient-map
(setq hydra-curr-map
(quote (keymap (7 . hydra-keyboard-quit)
(32 . hydra-repeat)
(107 . hydra-error/previous-error)
(106 . hydra-error/next-error)
(104 . hydra-error/first-error)
Expand Down Expand Up @@ -184,23 +194,26 @@ Call the head: `previous-error'."
(define-key global-map (kbd "M-g")
nil))
(define-key global-map [134217831 104]
(function hydra-error/first-error))
(function hydra-error/first-error))
(define-key global-map [134217831 106]
(function hydra-error/next-error))
(function hydra-error/next-error))
(define-key global-map [134217831 107]
(function hydra-error/previous-error))
(function hydra-error/previous-error))
(defun hydra-error/hint nil
(if hydra-lv (lv-message (format #("error: [h]: first, [j]: next, [k]: prev." 8 9 (face hydra-face-red)
(if hydra-lv (lv-message (format #("error: [h]: first, [j]: next, [k]: prev, [SPC]: rep." 8 9 (face hydra-face-red)
20 21 (face hydra-face-red)
31 32 (face hydra-face-red))))
(message (format #("error: [h]: first, [j]: next, [k]: prev." 8 9 (face hydra-face-red)
31 32 (face hydra-face-red)
42 45 (face hydra-face-red))))
(message (format #("error: [h]: first, [j]: next, [k]: prev, [SPC]: rep." 8 9 (face hydra-face-red)
20 21 (face hydra-face-red)
31 32 (face hydra-face-red))))))
31 32 (face hydra-face-red)
42 45 (face hydra-face-red))))))
(defun hydra-error/body nil "Create a hydra with a \"M-g\" body and the heads:
\"h\": `first-error',
\"j\": `next-error',
\"k\": `previous-error'
\"k\": `previous-error',
\"SPC\": `hydra-repeat'
The body can be accessed via `hydra-error/body'."
(interactive)
Expand All @@ -212,6 +225,7 @@ The body can be accessed via `hydra-error/body'."
(setq hydra-curr-map
(quote
(keymap (7 . hydra-keyboard-quit)
(32 . hydra-repeat)
(107 . hydra-error/previous-error)
(106 . hydra-error/next-error)
(104 . hydra-error/first-error)
Expand Down Expand Up @@ -1067,14 +1081,14 @@ When non-nil, hydra will issue some non essential style warnings. %`hy
_p_ Captain Jean Luc Picard: % -8`hydra-tng/picard^^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
_r_ Commander William Riker: % -8`hydra-tng/riker^^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
_d_ Lieutenant Commander Data: % -8`hydra-tng/data^^^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^
_w_ Worf: % -8`hydra-tng/worf^^^^
_f_ Geordi La Forge: % -8`hydra-tng/la-forge " 1)))
_w_ Worf: % -8`hydra-tng/worf^^^^
_f_ Geordi La Forge: % -8`hydra-tng/la-forge" 1)))
(should (equal (hydra--table hydra-tng/names 4 3)
(substring "
_p_ Captain Jean Luc Picard: % -8`hydra-tng/picard _f_ Geordi La Forge: % -8`hydra-tng/la-forge^^
_r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
_d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
_w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^ " 1)))))
_p_ Captain Jean Luc Picard: % -8`hydra-tng/picard _f_ Geordi La Forge: % -8`hydra-tng/la-forge^^
_r_ Commander William Riker: % -8`hydra-tng/riker^ _t_ Deanna Troi: % -8`hydra-tng/troi^^^^^^
_d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly Crusher: % -8`hydra-tng/dr-crusher
_w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to % -8`hydra-tng/phaser^^^^" 1)))))

(provide 'hydra-test)

Expand Down
8 changes: 6 additions & 2 deletions hydra.el
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ NAME, BODY and HEADS are parameters to `defhydra'."
(defun hydra--delete-duplicates (heads)
"Return HEADS without entries that have the same CMD part.
In duplicate HEADS, :cmd-name is modified to whatever they duplicate."
(let (res ali entry)
(let ((ali '(((hydra-repeat . red) . hydra-repeat)))
res entry)
(dolist (h heads)
(if (setq entry (assoc (cons (cadr h)
(hydra--head-color h '(nil nil)))
Expand Down Expand Up @@ -702,7 +703,10 @@ NAMES is a list of variables."
JOINER is a function similar to `concat'."
(setq joiner (or joiner #'concat))
(mapconcat
#'identity
(lambda (s)
(if (string-match " +$" s)
(replace-match "" nil nil s)
s))
(apply #'cl-mapcar joiner
(mapcar
(lambda (s) (split-string s "\n"))
Expand Down

0 comments on commit 41f98bd

Please sign in to comment.