1

I would like to set up things so that when I type Iuulius, the sequence uu is seamlessly replaced by ū (and a few more such pairs), as soon as I type the second u. I.e. the keystrokes and buffer text would go like this:

  • <I>I∎
  • <u>Iu∎
  • <u>Iū∎
  • <l>Iūl∎

How could I set that up that kind of expansion—without interfering with existing input methods?

3

I asked the same question recently on emacs-devel and Kenichi Handa told me I could do:

(defvar my-TeX-input-method-tweaked nil)
(defun my-quail-activate-hook ()
  (when (and (not (member (quail-name)
                          my-TeX-input-method-tweaked))
             (member (quail-name) '("TeX" "latin-1-prefix")))
    (quail-defrule "uu" "ū")
    (push (quail-name) my-TeX-input-method-tweaked)))

(add-hook 'quail-activate-hook #'my-quail-activate-hook)

Of course, you'll want to adjust the list of input-methods you want to modify. If you don't want to touch input methods, or if you want the "uu" rewriting to only take place in some specific contexts, you could do something like:

(defun my-uu-rewrite ()
  (when (looking-back "Iuu" (- (point) 3))
    (delete-region (- (point) 2) (point))
    (insert-and-inherit "ū")))
(add-hook 'post-self-insert-hook #'my-uu-rewrite)
  • Thank you for your answer! I do a lot of input method switching though (both on-off and in-between), so I was hoping for an orthogonal solution which didn't depend on having an IM on or hacking their definition (like a minor mode or something)… – melissa_boiko Apr 25 '17 at 14:05
  • You can probably some up with another implementation which doesn't use input-methods (and is hence orthogonal), but I think the behavior will be cleaner with input-methods. You can easily modify the code above to modify various input-methods at once. – Stefan Apr 25 '17 at 14:09
  • There's a 'post-self-insert-hook? That's good enough for me! thank you again @Stefan. – melissa_boiko Apr 25 '17 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.