Using and writing Emacs 22 input methods
Emacs 21 had a generic function called iso-accents-mode for writing âççéntèd çhàrâçtërs, but that was removed in Emacs 22. It took me a while, but I found the replacement was to use set-input-method
, and then select whichever language you want to be able to type the accented characters of.
The default keybinding for set-input-method is not very convenient (C-x RET C-\
), and I almost always use the same input method, so I put this small helper function in my .emacs
and bound it to an easy key sequence:
(defun ciaran-toggle-french-input-method ()
"toggle between French and no input method"
(interactive)
(if (string= current-input-method "french-alt-postfix")
(set-input-method nil)
(set-input-method "french-alt-postfix")))
(global-set-key [?\C-c ?.] 'ciaran-toggle-french-input-method)
Sometimes I need Dutch characters, but the "dutch
" input method contains some completely unnecessary conversion sequences which make it frustrating to use. And sometimes I want the "á" character so I can write my name properly. So what do I do if I want a personalised input method?
About modifying input methods, the Emacs Lisp Reference Manual just says "How to define input methods is not yet documented in this manual". So I went to the Emacs page on sv.gnu.org, checked out a CVS copy of the emacs source, grepped around, and found that the Dutch input is defined in the file /emacs/leim/quail/latin-alt.el. Looking inside, it’s not so complicated.
Here’s a minimalist example of what you could put in your .emacs to create your own very basic input method:
(quail-define-package
"ciarans-chars" "MYlanguage" "MY" t
"Ciaran’s personal input method defining only the
conversion sequence he wants
" nil t nil nil nil nil nil nil nil nil t)
(quail-define-rules
("\"a" ?ä) ;; LATIN SMALL LETTER A WITH DIAERESIS
;; remember to comment your code, if you like 🙂
("\"e" ?ë) ;; LATIN SMALL LETTER E WITH DIAERESIS
("a’" ?á) ;; LATIN SMALL LETTER A WITH GRAVE
)
For more information on those two quail-*
functions, you can get help in the usual way with C-h f
and then type the name of the function at the prompt. If you want to test the above code, just paste those two code snippets into an Emacs buffer and run M-x eval-last-sexp
after each. Then you can select the "ciarans-chars" input method, and you can read about the input method by pressing C-h I
and typing "ciarans-chars" at the prompt.
You will also see that, like with the existing input methods, when you type the first character of what could be a conversion sequence (in the above example, this is just " or ‘a’), you will see in the minibuffer which characters could follow it to cause both characters to be converted into another character. So with ciarans-chars
, when you type "
the minibuffer will display: "[ae]
.
Looking at the source in /emacs/leim/quail/latin-alt.el
should give you ideas for what other conversion sequences you’d use, and the other files in that directory contain the conversion code for more complex alphabets.
Me, I’ll make a minimal input method for the characters I use from French, Dutch, plus the Irish a-fada "á". I filed a bug report about the current Dutch input method, but seeing how uncomplicated it is, I might be able to fix it and submit a patch now.
—
Ciarán O’Riordan,
Support free software: Join FSFE’s Fellowship