]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/hydra/README.md
Merge commit '0c08964462812942db51d177e6ea922b26019e65' from hydra
[gnu-emacs-elpa] / packages / hydra / README.md
index 72720989039a3b3698f37a1e532df9f55be5cd0d..c7c1dff6f2973fb9e13546e9f4e6130c51b3532a 100644 (file)
@@ -16,29 +16,42 @@ Hydra, will still serve his orignal purpose, calling his proper
 command.  This makes the Hydra very seamless, it's like a minor mode
 that disables itself auto-magically.
 
-## Simplified usage
-
-Here's how to quickly bind the examples bundled with Hydra:
+## Sample global Hydras
+### Zoom
 
 ```cl
-(require 'hydra-examples)
-(hydra-create "C-M-y" hydra-example-move-window-splitter)
-(hydra-create "M-g" hydra-example-goto-error)
-(hydra-create "<f2>" hydra-example-text-scale)
+(defhydra hydra-zoom (global-map "<f2>")
+  "zoom"
+  ("g" text-scale-increase "in")
+  ("l" text-scale-decrease "out"))
 ```
 
-## Using Hydra for global bindings
+### Goto-error
 
-But it's much better to just take the examples as a template and write
-down everything explicitly:
+```cl
+(defhydra hydra-error (global-map "M-g")
+  "goto-error"
+  ("h" first-error "first")
+  ("j" next-error "next")
+  ("k" previous-error "prev")
+  ("v" recenter-top-bottom "recenter")
+  ("q" nil "quit"))
+```
+
+### Splitter
 
 ```cl
-(defhydra hydra-zoom (global-map "<f2>")
-  "zoom"
-  ("g" text-scale-increase "in")
-  ("l" text-scale-decrease "out"))
+(require 'hydra-examples)
+(defhydra hydra-splitter (global-map "C-M-s")
+  "splitter"
+  ("h" hydra-move-splitter-left)
+  ("j" hydra-move-splitter-down)
+  ("k" hydra-move-splitter-up)
+  ("l" hydra-move-splitter-right))
 ```
 
+## Using the functions generated by `defhydra`
+
 With the example above, you can e.g.:
 
 ```cl
@@ -234,6 +247,22 @@ use an amaranth Hydra instead of a red one, if for you the cost of being able to
 though certain bindings is less than the cost of accidentally exiting a red Hydra by
 pressing the wrong prefix.
 
-Note that it does not make sense to define a singe amaranth head, so this color can only
+Note that it does not make sense to define a single amaranth head, so this color can only
 be assigned to the body. An amaranth body will always have some amaranth heads and some
 blue heads (otherwise, it's impossible to exit), no reds.
+
+## Generate simple lambdas in-place:
+
+Since version `0.9.0` it's possible to pass a single sexp instead of a function name or a lambda
+to a head. This sexp will be wrapped in an interactive lambda. Here's an example:
+
+```cl
+(defhydra hydra-launcher (:color blue)
+   "Launch"
+   ("h" man "man")
+   ("r" (browse-url "http://www.reddit.com/r/emacs/") "reddit")
+   ("w" (browse-url "http://www.emacswiki.org/") "emacswiki")
+   ("s" shell "shell")
+   ("q" nil "cancel"))
+(global-set-key (kbd "C-c r") 'hydra-launcher/body)
+```