|
|
|
|
@ -66,7 +66,7 @@ If you want to quickly understand the concept, see [the video demo](https://www. |
|
|
|
|
|
|
|
|
|
## The one with the least amount of code |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-zoom (global-map "<f2>") |
|
|
|
|
"zoom" |
|
|
|
|
("g" text-scale-increase "in") |
|
|
|
|
@ -95,7 +95,7 @@ Here's the result of pressing <kbd>.</kbd> in the good-old Buffer menu: |
|
|
|
|
|
|
|
|
|
The code is large but very simple: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-buffer-menu (:color pink |
|
|
|
|
:hint nil) |
|
|
|
|
" |
|
|
|
|
@ -171,22 +171,26 @@ If you name your hydra `hydra-awesome`, the return result of `defhydra` will be |
|
|
|
|
|
|
|
|
|
Here's what `hydra-zoom/body` looks like, if you're interested: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
(defun hydra-zoom/body nil |
|
|
|
|
"Create a hydra with a \"<f2>\" body and the heads: |
|
|
|
|
```elisp |
|
|
|
|
(defun hydra-zoom/body () |
|
|
|
|
"Call the body in the \"hydra-zoom\" hydra. |
|
|
|
|
|
|
|
|
|
The heads for the associated hydra are: |
|
|
|
|
|
|
|
|
|
\"g\": `text-scale-increase', |
|
|
|
|
\"l\": `text-scale-decrease' |
|
|
|
|
|
|
|
|
|
The body can be accessed via `hydra-zoom/body'." |
|
|
|
|
The body can be accessed via `hydra-zoom/body', which is bound to \"<f2>\"." |
|
|
|
|
(interactive) |
|
|
|
|
(require 'hydra) |
|
|
|
|
(hydra-default-pre) |
|
|
|
|
(when hydra-is-helpful |
|
|
|
|
(if hydra-lv |
|
|
|
|
(lv-message |
|
|
|
|
(eval hydra-zoom/hint)) |
|
|
|
|
(message |
|
|
|
|
(eval hydra-zoom/hint)))) |
|
|
|
|
(let ((hydra--ignore nil)) |
|
|
|
|
(hydra-keyboard-quit) |
|
|
|
|
(setq hydra-curr-body-fn |
|
|
|
|
'hydra-zoom/body)) |
|
|
|
|
(hydra-show-hint |
|
|
|
|
hydra-zoom/hint |
|
|
|
|
'hydra-zoom) |
|
|
|
|
(hydra-set-transient-map |
|
|
|
|
hydra-zoom/keymap |
|
|
|
|
(lambda nil |
|
|
|
|
@ -203,7 +207,7 @@ This can be any keymap, for instance, `global-map` or `isearch-mode-map`. |
|
|
|
|
|
|
|
|
|
For this example: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-zoom (global-map "<f2>") |
|
|
|
|
"zoom" |
|
|
|
|
("g" text-scale-increase "in") |
|
|
|
|
@ -215,7 +219,7 @@ For this example: |
|
|
|
|
|
|
|
|
|
And here's the relevant generated code: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(unless (keymapp (lookup-key global-map (kbd "<f2>"))) |
|
|
|
|
(define-key global-map (kbd "<f2>") nil)) |
|
|
|
|
(define-key global-map [f2 103] |
|
|
|
|
@ -229,7 +233,7 @@ As you see, `"<f2>"` is used as a prefix for <kbd>g</kbd> (char value 103) and < |
|
|
|
|
|
|
|
|
|
If you don't want to use a map right now, you can skip it like this: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-zoom (nil nil) |
|
|
|
|
"zoom" |
|
|
|
|
("g" text-scale-increase "in") |
|
|
|
|
@ -238,7 +242,7 @@ If you don't want to use a map right now, you can skip it like this: |
|
|
|
|
|
|
|
|
|
Or even simpler: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-zoom () |
|
|
|
|
"zoom" |
|
|
|
|
("g" text-scale-increase "in") |
|
|
|
|
@ -260,7 +264,7 @@ Below is a list of each key. |
|
|
|
|
|
|
|
|
|
You can specify code that will be called before each head, and after the body. For example: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-vi (:pre (set-cursor-color "#40e0d0") |
|
|
|
|
:post (progn |
|
|
|
|
(set-cursor-color "#ffffff") |
|
|
|
|
@ -359,7 +363,7 @@ If the result of the Elisp expression is a string and you don't want to quote it |
|
|
|
|
|
|
|
|
|
Each head looks like this: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(head-binding head-command head-hint head-plist) |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
@ -392,7 +396,7 @@ The `head-command` can be: |
|
|
|
|
|
|
|
|
|
Here's an example of the last option: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-launcher (:color blue) |
|
|
|
|
"Launch" |
|
|
|
|
("h" man "man") |
|
|
|
|
@ -411,7 +415,7 @@ You can set the head hint to `nil` to do this. |
|
|
|
|
|
|
|
|
|
Example: |
|
|
|
|
|
|
|
|
|
```cl |
|
|
|
|
```elisp |
|
|
|
|
(defhydra hydra-zoom (global-map "<f2>") |
|
|
|
|
" |
|
|
|
|
Press _g_ to zoom in. |
|
|
|
|
|