[Arcana] extending input methods in emacs sucks
Noah Friedman
friedman at splode.com
Thu Feb 12 20:39:01 CST 2009
There is a babel of different input method systems in emacs. A lot of them
use "quail". Some are more direct (e.g. `ucs'). Some of them I just can't
tell how they work.
Anyway. All I wanted was to be able to type a euro symbol without having
to remember what its unicode character number was. I usually use the
rfc1345 input method, but of course the euro isn't defined in that.
And as long as I was adding currency symbols, I wanted a common mnemonic
prefix for all of them since I couldn't remember the others either.
This is my completely graceless solution.
;; This is a macro so it can be used with approximately the same syntax as
;; quail-define-rules.
(defmacro quail-annotate-input-method (method &rest bindings)
"Add new bindings to quail-based input methods"
(when (symbolp method)
(setq method (symbol-name method)))
`(progn
(require 'quail)
(unless (assoc ,method quail-package-alist)
(load ,(format "quail/%s" method)))
(let ((quail-orig (quail-name)))
(unwind-protect
(progn
(quail-select-package ,method)
(quail-define-rules ((append t)) , at bindings))
(when quail-orig
(quail-select-package quail-orig))))))
;; Put all the common currency symbols on a "&$" prefix.
;; Calling decode-char is a no-op in emacs 23, but emacs 22 doesn't use ucs
;; native coding.
(eval-after-load 'rfc1345
'(let ((bindings (mapcar (lambda (p)
(list (car p) (decode-char 'ucs (cadr p))))
'(("&$c" #x00a2) ; cent
("&$p" #x00a3) ; british pound
("&$u" #x00a4) ; generic currency sign
("&$y" #x00a5) ; yen
("&$e" #x20ac) ; euro
))))
;; macro application for the lose
(eval `(quail-annotate-input-method rfc1345 , at bindings))))
More information about the Arcana
mailing list