[Top][All Lists]

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

Re: Changing language input method by addressee

From: Bob Newell
Subject: Re: Changing language input method by addressee
Date: Fri, 09 Mar 2018 09:29:45 -1000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Aloha everyone,

Just for completeness, here's the final result, and it's much much
better. In BBDB just 'i' a 'language' field for those correspondents
with whom you correspond in whatever language, and then enter the input
mode, like 'french-postfix'. As long as you're using message mode and
BBDB completion, this works. If you use gnu-alias, initialize that
before you get to the code below, as the message-setup-hook I add
should be the last in the chain.


(defun rjn-change-lang-by-addressee ()
  (let ((addressee (message-fetch-field "To"))
        netaddr person langpref)
    (if addressee
        (setq netaddr (cadr (mail-extract-address-components addressee))))
    (if netaddr
        (setq person (car (bbdb-search (bbdb-records) :mail netaddr))))
    (if person
        (setq langpref (bbdb-record-field person 'language)))
    (if langpref
        (set-input-method langpref))))

(add-hook 'message-setup-hook 'rjn-change-lang-by-addressee t)
(advice-add 'bbdb-complete-mail :after #'rjn-change-lang-by-addressee)


This could but shouldn't be simplified with multiple let* assignments,
as nil fields cause error messages to be emitted in some of the
functions. The serial 'if' statements cause negligible additional run
time. If 'langpref' is invalid, there's a message, and that's a good

Bob Newell
Honolulu, Hawai`i
* Via Gnus/BBDB/Org/Emacs/Linux *

reply via email to

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