Charrot is a project mainly written in Emacs Lisp, it's free.
Emacs commands to interactively replace text before point, rotating among replacements.
Introduction
CharRot provides a command charrot-replace' to replace the text before point with an arbitrary string, like the Emacs standard
abbrev-mode'. There are two main differences with `abbrev-mode':
Any text string can be defined as an abbreviation, not just words. (On the other hand, this means that CharRot cannot provide any case-matching feature: abbreviation and replacement are matched verbatim.)
Replacement is not performed automatically but must be invoked by calling the command `charrot-replace'.
charrot-replace' scans the text *before* point; if it matches any abbreviation defined with
charrot-define-abbrev' or
charrot-define-rotating', it will be replaced with the appropriate replacement string. The longest-matching string is replaced. Point is kept at the end of the replacement string -- thus, repeated application of
charrot-replace' is possible. Undo works as usual,
so any replacement can be undone with `C-_'.
Example usage
Load the file charrot.el
::
(require 'charrot)
CharRot is most useful when charrot-replace' is bound to an easily accessible key chord; I use
C-;` for that:
(global-set-key (kbd "C-;") #'charrot-replace)
Replacements can now be defined with charrot-define-abbrev
(which
also works interactively):
(charrot-define-abbrev "->" " o") (charrot-define-abbrev "|->" "mapsto")
Now typing C-;
just after ->
will turn it into the LaTeX
command o
; if the text before point is |->
then the
replacement will be mapsto
instead.
One can define rotating replacements with charrot-define-rotating
:
(charrot-define-rotating "..." "ldots" "cdots") (charrot-define-rotating "a" "alpha")
Then, pressing C-;
once after entring ...
will turn it into
ldots
; pressing it once more will replace this with cdots
;
one more stroke of C-;
turns back to the starting ...
.
Likewise, invoking charrot-replace
when point is past an a
will
turn it into alpha
and then back into a
.
If you have ever used X-Symbol with LaTeX, you already know (and
perhaps miss) this feature. The file charrot-latex.el
provides a
list of replacements useful with TeX/LaTeX.
Caveats
The replacements table is global: you can't bind ^
to hat
in
LaTeX-mode and <sup></sup>
in html-mode. (See TO-DO section.)
It is no error to define rotating replacements that cross; the latter definition partially overrides the former:
(charrot-define-rotating "f*" "foo") (charrot-define-rotating "foo" "bar" "baz" "quux")
Then calling charrot-replace
turns f*
into foo
, but
successive invocations will cycle through the strings bar
, baz
,
and quux
, without ever going back to f*
.
TO-DO
mode-local replacements
ignore white space before point
rotate replacements forwards and backwards?
interactive definition of rotations?
** add "point placement" information? e.g., to replace ^
with hat{}
and place point in between {
and }