From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "A.Politz" Newsgroups: gmane.emacs.help Subject: Re: How to make emacs switch input method automatically ? Date: Wed, 5 Aug 2009 11:24:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: <117e4453-b9cb-4abe-b6d1-b116aec1b965@b15g2000yqd.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1249497707 8131 80.91.229.12 (5 Aug 2009 18:41:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 5 Aug 2009 18:41:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 05 20:41:40 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MYlQh-00044F-9U for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Aug 2009 20:41:39 +0200 Original-Received: from localhost ([127.0.0.1]:44589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MYlQg-0007pW-P2 for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Aug 2009 14:41:38 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!b15g2000yqd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 52 Original-NNTP-Posting-Host: 84.59.214.78 Original-X-Trace: posting.google.com 1249496664 19334 127.0.0.1 (5 Aug 2009 18:24:24 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 5 Aug 2009 18:24:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b15g2000yqd.googlegroups.com; posting-host=84.59.214.78; posting-account=Cb0eCQoAAADOp8Qt5mU0s83Gs6qJzY70 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009061208 Iceweasel/3.0.9 (Debian-3.0.9-1),gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:171634 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:66809 Archived-At: On Aug 5, 2:15=A0pm, waterloo wrote: > I use chinese to input normal text in latex . > And in math mode we almost use english . > > I use `shift' to switch between chinese and english . > > So now I use shift too frequently , my shift key is not sensitive . > > How to make emacs switch =A0automatically ? > > When =A0in math mode , =A0emacs switchs to english . > When =A0in normal text ,emacs switchs to chinese. > > Can here anyone =A0give some instructions of doing this ? > > I know there is function `texmathp' in auctex which determines if point i= s > inside latex mode . > > Thanks Write a function, that does the job. In this case switching between english (current-input-method =3D nil) and your preferred method, depending on the circumstances. (defun LaTeX-dynamic-input-method-toggle-maybe () (when (or (and current-input-method (texmathp)) (and (not current-input-method) (not (texmathp)))) (toggle-input-method))) Define a minor-mode, so this behaviour can be conviniently enabled/disabled. The minor-mode puts the above function on the `post-command-hook', so that the above function gets called everytime you do something (e.g. move point). (define-minor-mode LaTeX-dynamic-input-method "Dynamically disable input-method in math-mode." nil nil nil (if LaTeX-dynamic-input-method (add-hook 'post-command-hook 'LaTeX-dynamic-input-method-toggle- maybe nil t) (remove-hook 'post-command-hook 'LaTeX-dynamic-input-method-toggle- maybe t))) Enable the mode in LaTeX-mode. (add-hook 'LaTeX-mode-hook 'LaTeX-dynamic-input-method) Sorry, I suck at explaining stuff, especially my own. -ap