An Emacs package for rendering hats over characters, allowing words to be indexed quickly from any point in the buffer.
This package provides a mechanism for building interfaces overcoming a core limitation of tools like avy. With avy, it is necessary to perform a command to make the interface for choosing a position visible. This in turn means that performing an action cannot be done as one fluent operation.
In contrast, hatty always renders a small symbol over one of the characters in each word. This makes it possible to refer to the word immediately, without the intermediate step of bringing up an interface.
This library was designed while attempting to make voice control of Emacs more fluent, where the two-step system of avy made it impossible to string together a sequence of actions in a single utterance. This method of indexing positions was inspired by the cursorless project, whose hat designs this project reuses.
Clone this repo and add the following to your configuration:
(add-to-list 'load-path "path/to/hatty/directory")
(require 'hatty)
(global-hatty-mode 1)
This starts rendering hats in visited buffers. To get the position of
a hat, use hatty-locate
. For example,
(hatty-locate ?n 'yellow 'bolt)
will return the position of the yellow bolt over character “n”.
Similarly, hatty-locate-token-region
returns the region of the token
that the hat is placed over.
The available colors and shapes are specified by the variables
hatty-colors
and hatty-shapes
. The keys in these alists are the
symbols used to invoke hatty-locate
. The special identifier
default
denotes the color or shape to use whenever the argument is
nil or absent.
When loading hatty, it will attempt to set the color themes for the hats appropriately. You might want to customize the colors to fit your theme.
To change the hat colors, customize hatty-colors
. This can be done
through the customize interface with M-x customize-variable RET
hatty-colors RET
. Alternatively, you can set it in your
configuration file.
hatty-colors
should be an association list mapping an identifier
symbol to a color. A color can be a hex code like "#aa7023"
or a
named color like "magenta"
(M-x list-colors-display RET
to see
available color names). hatty-colors
may contain or exclude
arbitrary identifiers and colors, allowing you to remove, add or
change them to your liking.
This project uses semantic versioning. While still on 0.y.z, an increment of y signals breaking changes.
emacs -Q -l hatty.el -l test.el --eval '(ert t)'
It is not possible to run the ERT tests in batch mode, as the tests require a graphical display to measure the size of rendered text.