-
-
Notifications
You must be signed in to change notification settings - Fork 113
Verbosity Long Short
Large hints over several lines are great for casual usage. Sometimes, thought, experienced users may find them annoying.
Of course, hints can be turned off with the :verbosity
property.
What about something in the middle? What about a hint that occupies just one line, and this line is displayed in the echo area? The layout of windows would not be disturbed.
How to do that? With defhydra
, only one hint can be specified.
;;╭──────────────────────╮
;;│ 1. define some Hydra │
;;╰──────────────────────╯
(defhydra hydra-hintable (:exit nil :hint nil)
"
_a_ action a
_b_ action b
_c_ action c
_t_ toggle hints"
("a" (action 'a))
("b" (action 'b))
("c" (action 'c))
("t" toggle-hint-size))
(defun action (something)
(insert (format "(%s)" something)))
;;╭─────────────────────╮
;;│ 2. boolean variable │
;;╰─────────────────────╯
(defvar full-hint-p t)
;;╭──────────────────────────╮
;;│ 3. pack 2 hints into one │
;;╰──────────────────────────╯
(setq hydra-hintable/hint
`(if full-hint-p
,hydra-hintable/hint
"actions: abc, toggle hint: t"))
;;╭────────────────────╮
;;│ 4. toggle function │
;;╰────────────────────╯
(defun toggle-hint-size ()
(interactive)
(setq full-hint-p (not full-hint-p))
(hydra-set-property
'hydra-hintable
:verbosity
(if full-hint-p t 1)))
-
First, we have a standard Hydra, with a long hint. The
"t"
head flips hints. -
We need a state-variable telling which is the current hint size:
-
t
: full fledged standard hint -
nil
: one-liner hint in the echo-area
-
-
Now we tweak the standard hint so that it depends on this state-variable. The idea is to pack the long and the short hints into the standard hint variable. We do that just once.
This works because Hydra evaluates the hint each time it wants to display it ("dynamic hint").
-
Now we implement the function to flip hints. It flips the state-variable, and changes the Hydra verbosity accordingly. The
:verbosity
property can be:-
t
: standard display usually through the lv library -
1
: display in the echo area -
0
: no display (the above example does not use0
, but it could).
-
That's all (folks).
Of course, it would be nice to have this feature built-in.
It could be done by extending the possible values for the
:verbosity
property (currently t
, 1
, 0
).
A :verbosity
of maybe :short
, for instance, would display the short version.
Now, where can we store the alternate one-liner hint?
- Maybe in the
:verbosity
property itself? - In a new parameter to the
defhydra
macro? Without breaking compatibility.
- Binding-Styles
- Basics
- Verbosity
- Verbosity-Long-Short
- Conditional-Hydra
- defcustom
- Hydra-Colors
- internals
- Nesting-Hydras
- Prefix-map