Skip to content

Commit

Permalink
Remove hydra-exit
Browse files Browse the repository at this point in the history
* hydra-test.el: Revert tests.

* hydra.el (hydra-exit): Delete, since `hydra-exit' doesn't run :post.
(hydra--delete-duplicates): Simplify.
(defhydra): Simplify.

Hydras with nil body will still not be bound in outside keymaps.

Re #48
Fixes #53
  • Loading branch information
abo-abo committed Feb 24, 2015
1 parent e567bd6 commit 26c3fee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
37 changes: 33 additions & 4 deletions hydra-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,20 @@ Call the head: `abbrev-mode'."
(hydra-cleanup)
(catch (quote hydra-disable)
(call-interactively (function abbrev-mode))))
(defun hydra-toggle/nil nil "Create a hydra with no body and the heads:
\"t\": `toggle-truncate-lines',
\"f\": `auto-fill-mode',
\"a\": `abbrev-mode',
\"q\": `nil'
The body can be accessed via `hydra-toggle/body'.
Call the head: `nil'."
(interactive)
(hydra-disable)
(hydra-cleanup)
(catch (quote hydra-disable)))
(defun hydra-toggle/hint nil
(if hydra-lv (lv-message (format #("toggle: [t]: truncate, [f]: fill, [a]: abbrev, [q]: cancel." 9 10 (face hydra-face-blue)
24 25 (face hydra-face-blue)
Expand All @@ -323,7 +337,7 @@ The body can be accessed via `hydra-toggle/body'."
(setq hydra-curr-map
(quote
(keymap (7 . hydra-keyboard-quit)
(113 . hydra-exit)
(113 . hydra-toggle/nil)
(97 . hydra-toggle/abbrev-mode)
(102 . hydra-toggle/auto-fill-mode)
(116 . hydra-toggle/toggle-truncate-lines)
Expand Down Expand Up @@ -396,7 +410,7 @@ Call the head: `next-line'."
(when hydra-is-helpful (unless hydra-lv (sit-for 0.8))
(hydra-vi/hint)))
(7 . hydra-keyboard-quit)
(113 . hydra-exit)
(113 . hydra-vi/nil)
(107 . hydra-vi/previous-line)
(106 . hydra-vi/next-line)
(kp-subtract . hydra--negative-argument)
Expand Down Expand Up @@ -451,7 +465,7 @@ Call the head: `previous-line'."
(when hydra-is-helpful (unless hydra-lv (sit-for 0.8))
(hydra-vi/hint)))
(7 . hydra-keyboard-quit)
(113 . hydra-exit)
(113 . hydra-vi/nil)
(107 . hydra-vi/previous-line)
(106 . hydra-vi/next-line)
(kp-subtract . hydra--negative-argument)
Expand All @@ -478,6 +492,21 @@ Call the head: `previous-line'."
(45 . hydra--negative-argument)
(21 . hydra--universal-argument))))
t (lambda nil (hydra-cleanup))))))
(defun hydra-vi/nil nil "Create a hydra with no body and the heads:
\"j\": `next-line',
\"k\": `previous-line',
\"q\": `nil'
The body can be accessed via `hydra-vi/body'.
Call the head: `nil'."
(interactive)
(set-cursor-color "#e52b50")
(hydra-disable)
(hydra-cleanup)
(catch (quote hydra-disable)
(set-cursor-color "#ffffff")))
(defun hydra-vi/hint nil
(if hydra-lv (lv-message (format #("vi: j, k, [q]: quit." 4 5 (face hydra-face-amaranth)
7 8 (face hydra-face-amaranth)
Expand Down Expand Up @@ -507,7 +536,7 @@ The body can be accessed via `hydra-vi/body'."
(when hydra-is-helpful (unless hydra-lv (sit-for 0.8))
(hydra-vi/hint)))
(7 . hydra-keyboard-quit)
(113 . hydra-exit)
(113 . hydra-vi/nil)
(107 . hydra-vi/previous-line)
(106 . hydra-vi/next-line)
(kp-subtract . hydra--negative-argument)
Expand Down
28 changes: 10 additions & 18 deletions hydra.el
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,6 @@ BODY is the second argument to `defhydra'"
(t
(setq overriding-terminal-local-map nil))))

(defun hydra-exit ()
"Exit the current Hydra and clean up."
(interactive)
(hydra-disable)
(hydra-cleanup))

(defun hydra--unalias-var (str prefix)
"Return the symbol named STR if it's bound as a variable.
Otherwise, add PREFIX to the symbol name."
Expand Down Expand Up @@ -640,17 +634,15 @@ NAME, BODY and HEADS are parameters to `defhydra'."
In duplicate HEADS, :cmd-name is modified to whatever they duplicate."
(let (res ali entry)
(dolist (h heads)
(if (null (cadr h))
(setf (cl-cdddr h) (plist-put (cl-cdddr h) :cmd-name 'hydra-exit))
(if (setq entry (assoc (cons (cadr h)
(hydra--head-color h '(nil nil)))
ali))
(setf (cl-cdddr h) (plist-put (cl-cdddr h) :cmd-name (cdr entry)))
(push (cons (cons (cadr h)
(hydra--head-color h '(nil nil)))
(plist-get (cl-cdddr h) :cmd-name))
ali)
(push h res))))
(if (setq entry (assoc (cons (cadr h)
(hydra--head-color h '(nil nil)))
ali))
(setf (cl-cdddr h) (plist-put (cl-cdddr h) :cmd-name (cdr entry)))
(push (cons (cons (cadr h)
(hydra--head-color h '(nil nil)))
(plist-get (cl-cdddr h) :cmd-name))
ali)
(push h res)))
(nreverse res)))

;;* Macros
Expand Down Expand Up @@ -764,7 +756,7 @@ result of `defhydra'."
(cl-mapcar
(lambda (head)
(let ((name (hydra--head-property head :cmd-name)))
(unless (eq name 'hydra-exit)
(when (cadr head)
(when (or body-key method)
(let ((bind (hydra--head-property head :bind 'default))
(final-key
Expand Down

0 comments on commit 26c3fee

Please sign in to comment.