I want to create a minor mode that helps to input thai tone character. This is what I wrote:
(defvar thai-input-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "2" (lambda () (interactive)
(replace-string "o" "ô")
))
map)
"Keymap used by `thai-input-mode'.")
(easy-mmode-define-minor-mode thai-input-mode
"Input mode for Thai"
nil " TH" thai-input-mode-map)
(global-set-key "\C-x\C-t" 'thai-input-mode)
Of course I must implement more details, but I'm already have problems.
First of all the replace-string function doesn't work even if there is o in a buffer.
Secondly I couldn't figure out how to replace only a character that is at the cursor.
How can I write to implement that kind of function?
Edit
By following Gilles's advice I wrote like this:
(defvar thai-tone-conversion-list
'(("o" . "ô") ("u" . "û")))
(defun thai-add-tone ()
(interactive "*")
(when (let ((case-fold-search t))
(looking-back "[ou]"))
(replace-match (assoc (match-string 0) (thai-tone-conversion-list)))))
(defvar thai-input-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "2" 'thai-add-tone)
map)
"Keymap used by `thai-input-mode'.")
(easy-mmode-define-minor-mode thai-input-mode
"Input mode for Thai"
nil " TH" thai-input-mode-map)
(global-set-key "\C-x\C-t" 'thai-input-mode)
But I get assoc: Symbol's function definition is void: thai-tone-conversion-list error, when I put 2 in thai-input-mode.