Huàn (换; meaning change in Mandarin) is a tiny library for replacing a symbol at point with one of its predefined alternatives. It is an alternative to grugru and cycle-at-point.
The differences from those options are:
- It is created with embark integration in mind. If there are multiple candidates, you will use
completing-read
for selecting a candidate rather than firing the same command multiple times. - It is minimal. I didn’t consider support for natural languages, because it should be handled by a dedicated package (with spell and grammar checking).
As huan is an inferior alternative to other packages on MELPA, I probably won’t submit this package to MELPA.
Add huan.el
to your load path, or use one of the source-based package managers such as straight.el, borg, quelpa, etc.
If you are using embark, you can use the following snippet for integration:
(with-eval-after-load 'embark
(define-key embark-defun-map "`" #'huan-defun)
(define-key embark-identifier-map "`" #'huan-symbol))
To define your own substitutions, customize huan-mode-symbols-alist
.
If you are using setup.el for your init.el, you can define :huan
keyword as follows:
(define-setup-macro
:huan (&rest entries)
"Add ENTRIES to `huan-mode-symbols-alist'."
:indent 0
`(with-eval-after-load 'huan
(let ((mode ',(setup-get 'mode))
(entries ',entries))
(if-let (cell (assq mode huan-mode-symbols-alist))
(let ((sym (make-symbol "entries")))
(set sym (cdr cell))
(dolist (ent (reverse entries))
(add-to-list sym ent))
(setcdr cell (symbol-value sym)))
(push (cons mode entries)
huan-mode-symbols-alist)))))
define-setup-macro
is the alternative macro definer described in the EmacsWiki.
You can use the keyword to add entries to the default settings:
(setup elisp-mode
(:with-mode emacs-lisp-mode
(:huan
("eval-after-load" "with-eval-after-load")
("add-hook" "remove-hook")
(":around" ":override" ":before" ":after"))))
The following interactive functions are available:
huan-defun
huan-symbol