[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do you write input methods?
From: |
Filipp Gunbin |
Subject: |
Re: How do you write input methods? |
Date: |
Wed, 01 Sep 2021 20:50:04 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin) |
FWIW, I use this (hack?) to employ available input methods for
transliteration.
Filipp
--8<---------------cut here---------------start------------->8---
(defun fg-dotemacs-translit (str input-method)
(with-temp-buffer
(let ((input-method-verbose-flag nil)
res)
(activate-input-method input-method)
(discard-input)
(setq unread-command-events
;; add newline so input method doesn't wait for more input
;; in case of multiple translation possibilities
(listify-key-sequence (concat str "\n")))
(while (input-pending-p)
(push (read-char nil t) res))
(concat (reverse
;; don't forget to remove newline
(cdr res))))))
(ert-deftest fg-dotemacs-translit-test()
(should (equal "русский" (fg-dotemacs-translit "russkij"
"cyrillic-translit")))
;; `u' / `sh' may have different completions
(should (equal "гу" (fg-dotemacs-translit "gu" "cyrillic-translit")))
(should (equal "ш" (fg-dotemacs-translit "sh" "cyrillic-translit"))))
--8<---------------cut here---------------end--------------->8---
- Re: How do you write input methods?,
Filipp Gunbin <=