Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: Bob Newell <bobnewell@bobnewell.net>
To: info-gnus-english <info-gnus-english@gnu.org>
Subject: Re: Changing language input method by addressee
Date: Fri, 09 Mar 2018 09:29:45 -1000	[thread overview]
Message-ID: <873719ujx2.fsf@bobnewell.net> (raw)
In-Reply-To: <87vae5yb23.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Fri, 09 Mar 2018 15:15:16 +0800")

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 ()
  (interactive)
  (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
thing.

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


      parent reply	other threads:[~2018-03-09 19:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09  5:13 Bob Newell
2018-03-09  7:15 ` Eric Abrahamsen
2018-03-09 17:02   ` Bob Newell
2018-03-09 19:18     ` Tim Landscheidt
2018-03-09 19:36       ` Bob Newell
2018-03-09 19:29   ` Bob Newell [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873719ujx2.fsf@bobnewell.net \
    --to=bobnewell@bobnewell.net \
    --cc=info-gnus-english@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).