[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to make emacs switch input method automatically ?
From: |
A.Politz |
Subject: |
Re: How to make emacs switch input method automatically ? |
Date: |
Wed, 5 Aug 2009 11:24:24 -0700 (PDT) |
User-agent: |
G2/1.0 |
On Aug 5, 2:15 pm, waterloo <waterloo2...@gmail.com> 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 automatically ?
>
> When in math mode , emacs switchs to english .
> When in normal text ,emacs switchs to chinese.
>
> Can here anyone give some instructions of doing this ?
>
> I know there is function `texmathp' in auctex which determines if point is
> inside latex mode .
>
> Thanks
Write a function, that does the job. In this case switching
between english (current-input-method = 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