[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master eb1e0fc 58/72: Don't bind nil heads in outside keymaps
From: |
Oleh Krehel |
Subject: |
[elpa] master eb1e0fc 58/72: Don't bind nil heads in outside keymaps |
Date: |
Fri, 06 Mar 2015 13:04:21 +0000 |
branch: master
commit eb1e0fc25c239ad8a3893c9e85479cae0a880035
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Don't bind nil heads in outside keymaps
* hydra.el (hydra-exit): New command to be used for nil heads.
(hydra--delete-duplicates): Update for `hydra-exit'.
(defhydra): Don't bind `hydra-exit' in outside keymaps.
* hydra-test.el (hydra-blue-toggle): Update test.
(hydra-amaranth-vi): Update test.
Fixes #48.
---
hydra-test.el | 37 +++------------------------
hydra.el | 77 +++++++++++++++++++++++++++++++-------------------------
2 files changed, 47 insertions(+), 67 deletions(-)
diff --git a/hydra-test.el b/hydra-test.el
index b904f2d..b4a1994 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -297,20 +297,6 @@ 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)
@@ -337,7 +323,7 @@ The body can be accessed via `hydra-toggle/body'."
(setq hydra-curr-map
(quote
(keymap (7 . hydra-keyboard-quit)
- (113 . hydra-toggle/nil)
+ (113 . hydra-exit)
(97 . hydra-toggle/abbrev-mode)
(102 . hydra-toggle/auto-fill-mode)
(116 . hydra-toggle/toggle-truncate-lines)
@@ -410,7 +396,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-vi/nil)
+ (113 . hydra-exit)
(107 . hydra-vi/previous-line)
(106 . hydra-vi/next-line)
(kp-subtract . hydra--negative-argument)
@@ -465,7 +451,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-vi/nil)
+ (113 . hydra-exit)
(107 . hydra-vi/previous-line)
(106 . hydra-vi/next-line)
(kp-subtract . hydra--negative-argument)
@@ -492,21 +478,6 @@ 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)
@@ -536,7 +507,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-vi/nil)
+ (113 . hydra-exit)
(107 . hydra-vi/previous-line)
(106 . hydra-vi/next-line)
(kp-subtract . hydra--negative-argument)
diff --git a/hydra.el b/hydra.el
index ecbc409..cc3e5fe 100644
--- a/hydra.el
+++ b/hydra.el
@@ -378,6 +378,12 @@ 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."
@@ -634,15 +640,17 @@ 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 (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 (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))))
(nreverse res)))
;;* Macros
@@ -755,31 +763,32 @@ result of `defhydra'."
,@(delq nil
(cl-mapcar
(lambda (head)
- (let ((name (hydra--head-name head name)))
- (when (or body-key method)
- (let ((bind (hydra--head-property head :bind 'default))
- (final-key
- (if body-key
- (vconcat (kbd body-key) (kbd (car head)))
- (kbd (car head)))))
- (cond ((null bind) nil)
-
- ((eq bind 'default)
- (list
- (if (hydra--callablep method)
- 'funcall
- 'define-key)
- method
- final-key
- (list 'function name)))
-
- ((hydra--callablep bind)
- `(funcall (function ,bind)
- ,final-key
- (function ,name)))
-
- (t
- (error "Invalid :bind property %S" head)))))))
+ (let ((name (hydra--head-property head :cmd-name)))
+ (unless (eq name 'hydra-exit)
+ (when (or body-key method)
+ (let ((bind (hydra--head-property head :bind 'default))
+ (final-key
+ (if body-key
+ (vconcat (kbd body-key) (kbd (car head)))
+ (kbd (car head)))))
+ (cond ((null bind) nil)
+
+ ((eq bind 'default)
+ (list
+ (if (hydra--callablep method)
+ 'funcall
+ 'define-key)
+ method
+ final-key
+ (list 'function name)))
+
+ ((hydra--callablep bind)
+ `(funcall (function ,bind)
+ ,final-key
+ (function ,name)))
+
+ (t
+ (error "Invalid :bind property %S"
head))))))))
heads))
(defun ,(intern (format "%S/hint" name)) ()
,(hydra--message name body docstring heads))
- [elpa] master efcffc0 45/72: hydra-examples.el: Add example 9, (continued)
- [elpa] master efcffc0 45/72: hydra-examples.el: Add example 9, Oleh Krehel, 2015/03/06
- [elpa] master ef1f61d 40/72: hydra.el (hydra--handle-nonhead): Fix bug, Oleh Krehel, 2015/03/06
- [elpa] master 2eddb83 43/72: hydra-test.el (hydra-format): New test, Oleh Krehel, 2015/03/06
- [elpa] master 5242aad 48/72: Fix :exit t / :exit nil inheritance issue, Oleh Krehel, 2015/03/06
- [elpa] master 0f733d8 37/72: Add an option to fontify heads in a custom way, Oleh Krehel, 2015/03/06
- [elpa] master c413b5f 54/72: Allow for a custom key format spec in docstrings, Oleh Krehel, 2015/03/06
- [elpa] master 54004d2 52/72: hydra.el (hydra-verbose): New defcustom, Oleh Krehel, 2015/03/06
- [elpa] master 0d9c95e 47/72: Update README.md, Oleh Krehel, 2015/03/06
- [elpa] master 3c06695 56/72: Amend the key regex in docstring to include <>, Oleh Krehel, 2015/03/06
- [elpa] master e567bd6 59/72: lv.el (lv-window): set-window-parameter 'no-other-window, Oleh Krehel, 2015/03/06
- [elpa] master eb1e0fc 58/72: Don't bind nil heads in outside keymaps,
Oleh Krehel <=
- [elpa] master 41ec124 50/72: Avoid generating multiple defuns with same name, Oleh Krehel, 2015/03/06
- [elpa] master db0415e 49/72: hydra.el (hydra-keyboard-quit): Add, Oleh Krehel, 2015/03/06
- [elpa] master 55682e7 57/72: Improve handling of heads with duplicate cmd, Oleh Krehel, 2015/03/06
- [elpa] master 7de26d0 64/72: Add `hydra-repeat': hydra-specific `repeat', Oleh Krehel, 2015/03/06
- [elpa] master f231dc0 55/72: Simplify the hint part of each head, Oleh Krehel, 2015/03/06
- [elpa] master 764f4b6 67/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master 8e90037 65/72: Add some features for generating tables, Oleh Krehel, 2015/03/06
- [elpa] master 3040f45 61/72: hydra.el (hydra--format): Amend key regex, Oleh Krehel, 2015/03/06
- [elpa] master e1e2e3e 69/72: lv.el (lv-window): Bind `golden-ratio-mode' to nil, Oleh Krehel, 2015/03/06
- [elpa] master 8dec3cd 70/72: Allow for a %s(test) spec in docstring, Oleh Krehel, 2015/03/06