[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing language input method by addressee

From: Eric Abrahamsen
Subject: Re: Changing language input method by addressee
Date: Fri, 09 Mar 2018 15:15:16 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Bob Newell <> writes:

> 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?

A small improvement would be to store the addresses elsewhere, say in a
variable, and then use `regexp-opt' on the lists to build one regexp
for French and another for German. Then you can collapse your
`string-match-p' calls to one per language.

A better solution might involve giving your BBDB contacts a "language"
xfield, holding values like "fr" or "de". Then in the
message-setup-hook just retrieve the actual BBDB contact, check if it
has a language xfield, and set the input method accordingly.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]