Bob Newell
2018-03-09 05:13:09 UTC
Aloha everyone,
I mostly correspond in English, but I have a few French correspondents
and a couple of German ones. So I wanted to automatically enter French
input mode or German input mode respectively when writing to one of
those folks. After an embarrassing amount of time I came up with
something that works. (I'm on Emacs 25.3 and corresponding Gnus, and I
use message mode, gnus-alias, and BBDB completion. Obviously, I've
anonymized the addressees.)
--
(defun rjn-change-lang-by-addressee (&rest args)
(let* ((addressee (message-fetch-field "To")))
(if addressee
(if (or
(string-match-p "french1" addressee)
(string-match-p "french2" addressee)
(string-match-p "french3" addressee)
(string-match-p "french4" addressee)
(string-match-p "french5" addressee)
(string-match-p "french6" addressee)
(string-match-p "french7" addressee)
(string-match-p "french8" addressee))
(set-input-method "french-postfix")
(if (or
(string-match-p "german1" addressee)
(string-match-p "german2" addressee)
(string-match-p "german3" addressee))
(set-input-method "german-postfix"))))))
(add-hook 'message-setup-hook 'rjn-change-lang-by-addressee t)
(advice-add 'bbdb-complete-mail :after #'rjn-change-lang-by-addressee)
--
But this seems excessively crude and clunky. Surely I'm not the first
person ever to do this sort of thing, but I can't find any other
examples.
Any suggestions about doing this better, perhaps much better?
Mahalo,
I mostly correspond in English, but I have a few French correspondents
and a couple of German ones. So I wanted to automatically enter French
input mode or German input mode respectively when writing to one of
those folks. After an embarrassing amount of time I came up with
something that works. (I'm on Emacs 25.3 and corresponding Gnus, and I
use message mode, gnus-alias, and BBDB completion. Obviously, I've
anonymized the addressees.)
--
(defun rjn-change-lang-by-addressee (&rest args)
(let* ((addressee (message-fetch-field "To")))
(if addressee
(if (or
(string-match-p "french1" addressee)
(string-match-p "french2" addressee)
(string-match-p "french3" addressee)
(string-match-p "french4" addressee)
(string-match-p "french5" addressee)
(string-match-p "french6" addressee)
(string-match-p "french7" addressee)
(string-match-p "french8" addressee))
(set-input-method "french-postfix")
(if (or
(string-match-p "german1" addressee)
(string-match-p "german2" addressee)
(string-match-p "german3" addressee))
(set-input-method "german-postfix"))))))
(add-hook 'message-setup-hook 'rjn-change-lang-by-addressee t)
(advice-add 'bbdb-complete-mail :after #'rjn-change-lang-by-addressee)
--
But this seems excessively crude and clunky. Surely I'm not the first
person ever to do this sort of thing, but I can't find any other
examples.
Any suggestions about doing this better, perhaps much better?
Mahalo,
--
Bob Newell
Honolulu, Hawai`i
* Via Gnus/BBDB/Org/Emacs/Linux *
Bob Newell
Honolulu, Hawai`i
* Via Gnus/BBDB/Org/Emacs/Linux *