[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 97d6987 21/28: Add hydra-rectangle example
From: |
Oleh Krehel |
Subject: |
[elpa] master 97d6987 21/28: Add hydra-rectangle example |
Date: |
Sun, 22 Mar 2015 16:34:46 +0000 |
branch: master
commit 97d6987bb585c5e9967ef6719659a98186cabf57
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add hydra-rectangle example
* hydra-examples.el (hydra-toggle-simple): Rename from `hydra-toggle'.
(hydra-rectangle): New hydra.
---
hydra-examples.el | 71 +++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 58 insertions(+), 13 deletions(-)
diff --git a/hydra-examples.el b/hydra-examples.el
index 271756b..872814b 100644
--- a/hydra-examples.el
+++ b/hydra-examples.el
@@ -88,7 +88,7 @@
(defvar whitespace-mode nil)
(global-set-key
(kbd "C-c C-v")
- (defhydra hydra-toggle (:color blue)
+ (defhydra hydra-toggle-simple (:color blue)
"toggle"
("a" abbrev-mode "abbrev")
("d" toggle-debug-on-error "debug")
@@ -97,7 +97,7 @@
("w" whitespace-mode "whitespace")
("q" nil "cancel"))))
-;; Note that in this case, `defhydra' returns the `hydra-toggle/body'
+;; Note that in this case, `defhydra' returns the `hydra-toggle-simple/body'
;; symbol, which is then passed to `global-set-key'.
;;
;; Another new thing is that both the keymap and the body prefix are
@@ -161,10 +161,11 @@
;; This example will bind "C-x `" in `global-map', but it will not
;; bind "C-x j" and "C-x k".
;; You can still "C-x `jjk" though.
+
;;** Example 7: toggle with Ruby-style docstring
-(when (bound-and-true-p hydra-examples-verbatim)
- (defhydra hydra-toggle (:color pink)
- "
+(defvar whitespace-mode nil)
+(defhydra hydra-toggle (:color pink)
+ "
_a_ abbrev-mode: %`abbrev-mode
_d_ debug-on-error: %`debug-on-error
_f_ auto-fill-mode: %`auto-fill-function
@@ -172,13 +173,14 @@ _t_ truncate-lines: %`truncate-lines
_w_ whitespace-mode: %`whitespace-mode
"
- ("a" abbrev-mode nil)
- ("d" toggle-debug-on-error nil)
- ("f" auto-fill-mode nil)
- ("t" toggle-truncate-lines nil)
- ("w" whitespace-mode nil)
- ("q" nil "quit"))
- (global-set-key (kbd "C-c C-v") 'hydra-toggle/body))
+ ("a" abbrev-mode nil)
+ ("d" toggle-debug-on-error nil)
+ ("f" auto-fill-mode nil)
+ ("t" toggle-truncate-lines nil)
+ ("w" whitespace-mode nil)
+ ("q" nil "quit"))
+;; Recommended binding:
+;; (global-set-key (kbd "C-c C-v") 'hydra-toggle/body)
;; Here, using e.g. "_a_" translates to "a" with proper face.
;; More interestingly:
@@ -186,6 +188,7 @@ _w_ whitespace-mode: %`whitespace-mode
;; "foobar %`abbrev-mode" means roughly (format "foobar %S" abbrev-mode)
;;
;; This means that you actually see the state of the mode that you're changing.
+
;;** Example 8: the whole menu for `Buffer-menu-mode'
(defhydra hydra-buffer-menu (:color pink
:hint nil)
@@ -218,6 +221,7 @@ _~_: modified ^ ^ ^ ^ ^^
("q" quit-window "quit" :color blue))
;; Recommended binding:
;; (define-key Buffer-menu-mode-map "." 'hydra-buffer-menu/body)
+
;;** Example 9: s-expressions in the docstring
;; You can inline s-expresssions into the docstring like this:
(when (bound-and-true-p hydra-examples-verbatim)
@@ -234,6 +238,7 @@ Number of marked items: %(length (dired-get-marked-files))
;; (length (dired-get-marked-files)))
;;
;; You can use `format'-style width specs, e.g. % 10(length nil).
+
;;** Example 10: apropos family
(defhydra hydra-apropos (:color blue
:hint nil)
@@ -252,7 +257,37 @@ _v_ariable _u_ser-option
;; Recommended binding:
;; (global-set-key (kbd "C-c h") 'hydra-apropos/body)
-;;* Windmove helpers
+;;** Example 11: rectangle-mark-mode
+(defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1)
+ :color pink
+ :post (deactivate-mark))
+ "
+ ^_k_^ _d_elete _s_tring |\\ _,,,--,,_
+_h_ _l_ _o_k _y_ank /,`.-'`' ._ \-;;,_
+ ^_j_^ _n_ew-copy _r_eset |,4- ) )_ .;.( `'-'
+^^^^ _e_xchange _u_ndo '---''(_/._)-'(_\_)
+^^^^ ^ ^ _p_aste
+"
+ ("h" backward-char nil)
+ ("l" forward-char nil)
+ ("k" previous-line nil)
+ ("j" next-line nil)
+ ("e" hydra-ex-point-mark nil)
+ ("n" copy-rectangle-as-kill nil)
+ ("d" delete-rectangle nil)
+ ("r" (if (region-active-p)
+ (deactivate-mark)
+ (rectangle-mark-mode 1)) nil)
+ ("y" yank-rectangle nil)
+ ("u" undo nil)
+ ("s" string-rectangle nil)
+ ("p" kill-rectangle nil)
+ ("o" nil nil))
+
+;; Recommended binding:
+;; (global-set-key (kbd "C-x SPC") 'hydra-rectangle/body)
+
+;;* Helpers
(require 'windmove)
(defun hydra-move-splitter-left (arg)
@@ -287,5 +322,15 @@ _v_ariable _u_ser-option
(shrink-window arg)
(enlarge-window arg)))
+(defvar rectangle-mark-mode)
+(defun hydra-ex-point-mark ()
+ "Exchange point and mark."
+ (interactive)
+ (if rectangle-mark-mode
+ (exchange-point-and-mark)
+ (let ((mk (mark)))
+ (rectangle-mark-mode 1)
+ (goto-char mk))))
+
(provide 'hydra-examples)
;;; hydra-examples.el ends here
- [elpa] master 7f4c835 11/28: README.md: finish up the rules, (continued)
- [elpa] master 7f4c835 11/28: README.md: finish up the rules, Oleh Krehel, 2015/03/22
- [elpa] master 556db52 14/28: Wiki link to the "Home" page instead., Oleh Krehel, 2015/03/22
- [elpa] master c9432e8 12/28: README.md: describe docstring, Oleh Krehel, 2015/03/22
- [elpa] master 3c4b3fd 16/28: lv.el: Update truncation rules, Oleh Krehel, 2015/03/22
- [elpa] master 3f11348 13/28: README.md: Add toc, Oleh Krehel, 2015/03/22
- [elpa] master 5e8c7f2 18/28: hydra.el (hydra--format): Extend key regex with "; :", Oleh Krehel, 2015/03/22
- [elpa] master 3a77bf6 20/28: hydra-examples.el (hydra-apropos): Add., Oleh Krehel, 2015/03/22
- [elpa] master 622c798 10/28: README.md: move some stuff to wiki, add more stuff, Oleh Krehel, 2015/03/22
- [elpa] master 9f9dcf9 17/28: Bind [switch-frame] to `hydra-keyboard-quit', Oleh Krehel, 2015/03/22
- [elpa] master 543e97b 19/28: Fix switch-frame handling., Oleh Krehel, 2015/03/22
- [elpa] master 97d6987 21/28: Add hydra-rectangle example,
Oleh Krehel <=
- [elpa] master bfe65da 15/28: README.md: Fix up typos, Oleh Krehel, 2015/03/22
- [elpa] master d44bf58 22/28: Don't bind `hydra-keyboard-quit' in foreign keymaps, Oleh Krehel, 2015/03/22
- [elpa] master eb181fd 23/28: Call :post for :timeout, Oleh Krehel, 2015/03/22
- [elpa] master 30a073b 25/28: hydra.el (hydra-keyboard-quit): Clean up the message area, Oleh Krehel, 2015/03/22
- [elpa] master 8e4b1fa 24/28: lv.el (lv-message): Use setq-local for window-min-height, Oleh Krehel, 2015/03/22
- [elpa] master 498d78b 26/28: Set pink/amaranth override recursively, Oleh Krehel, 2015/03/22
- [elpa] master 7783f89 27/28: Minor fixes, Oleh Krehel, 2015/03/22
- [elpa] master a071b60 09/28: README.md: update, Oleh Krehel, 2015/03/22
- [elpa] master 5aa7896 28/28: Merge commit '7783f89cdbb3e3ba57f232552729715148e0b9a1' from hydra, Oleh Krehel, 2015/03/22