branch: master commit 97d6987bb585c5e9967ef6719659a98186cabf57 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
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