From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: auxsvr@gmail.com Newsgroups: gmane.emacs.auctex.devel,gmane.emacs.help Subject: Re: [AUCTeX] How to implement the function? Identify state of input method. Date: Wed, 20 Aug 2008 18:15:03 +0300 Message-ID: <200808201815.04707.auxsvr@gmail.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_4TDrIrsHVqo6Edg" X-Trace: ger.gmane.org 1219245428 30198 80.91.229.12 (20 Aug 2008 15:17:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 20 Aug 2008 15:17:08 +0000 (UTC) Cc: xiaopeng hu To: auctex-devel@gnu.org, help-gnu-emacs@gnu.org Original-X-From: auctex-devel-bounces+gead-auctex-devel=m.gmane.org@gnu.org Wed Aug 20 17:17:59 2008 Return-path: Envelope-to: gead-auctex-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KVpQQ-0002fx-J3 for gead-auctex-devel@m.gmane.org; Wed, 20 Aug 2008 17:16:43 +0200 Original-Received: from localhost ([127.0.0.1]:44367 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KVpPT-0003zg-5f for gead-auctex-devel@m.gmane.org; Wed, 20 Aug 2008 11:15:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KVpPP-0003ye-IH for auctex-devel@gnu.org; Wed, 20 Aug 2008 11:15:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KVpPO-0003xT-KU for auctex-devel@gnu.org; Wed, 20 Aug 2008 11:15:38 -0400 Original-Received: from [199.232.76.173] (port=54355 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KVpPO-0003xA-CS for auctex-devel@gnu.org; Wed, 20 Aug 2008 11:15:38 -0400 Original-Received: from yx-out-1718.google.com ([74.125.44.156]:63172) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KVpPN-0007TS-Ut for auctex-devel@gnu.org; Wed, 20 Aug 2008 11:15:38 -0400 Original-Received: by yx-out-1718.google.com with SMTP id 34so183555yxf.66 for ; Wed, 20 Aug 2008 08:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :user-agent:cc:references:in-reply-to:mime-version:message-id :content-type; bh=l0sTdXa77rfT/q7vcH1Nw++NZ1oQSBkFpf7dns5i+QA=; b=N8VRblW0cS9/uc5RpV7OuCFsZWJR6vn6fKKpO5vLBtuwza6JXOo/ow+MR6Te4+W8NT VOt9RlgXI/iqMuD8n4GcPqaar9hIq1EqEC12v7HPImsG5XPDT4N2931XbZmObqL5PKZi InbdNlwwqaAAqgR6u0uCTBG31tbJGcHtH35zo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:message-id:content-type; b=eFWR/ny6pgGrjEbTLu/Hi+i0GgHkPbs2Y4cdPaBVg4Knvu2xunmAMTiq0QBgWdKKJn 153pgPuCYacxd95pwKHTB81AabBRRy3Jl+MS6OQTMecYSQGOTjpmgyv5e+xRmXpF/SeT zsg1XhXOvtXDt0x95H5CK0yJLfEo0m/EeJRno= Original-Received: by 10.103.247.14 with SMTP id z14mr168196mur.39.1219245336177; Wed, 20 Aug 2008 08:15:36 -0700 (PDT) Original-Received: from linux.localnet ( [77.49.84.139]) by mx.google.com with ESMTPS id u9sm9266504muf.9.2008.08.20.08.15.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 20 Aug 2008 08:15:35 -0700 (PDT) User-Agent: KMail/1.10.0 (Linux/2.6.25.11-0.1-default; KDE/4.1.1; i686; ; ) In-Reply-To: X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: auctex-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion list for AUCTeX developers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: auctex-devel-bounces+gead-auctex-devel=m.gmane.org@gnu.org Errors-To: auctex-devel-bounces+gead-auctex-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.auctex.devel:2243 gmane.emacs.help:56823 Archived-At: --Boundary-00=_4TDrIrsHVqo6Edg Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wednesday 20 August 2008, xiaopeng hu wrote: > I use Ctrol to switch my input method between chinese and english. > When I input $, coming in math mode,I need to automatically switch to > english input method (push "Ctrl" key). > > First, I simulate a keystrike "t"+, I will get a chinese character > (not equal "t ")if my input method is chinese. Now I need Emacs > automatically simulate a "Ctrl" key to switch to english input method. > All of these is just after when I input $. > > How to implement the function? > > Thanks I have attached a minor mode that changes the input encoding when entering and exiting math-mode or after a backslash. Copy it to a directory that is in the emacs load path (such as /usr/share/emacs/site-lisp/) and add: (autoload 'latex-i18n-mode "latex-i18n" t) (add-hook 'LaTeX-mode-hook 'latex-i18n-mode) to ~/.emacs. Hope this helps. --Boundary-00=_4TDrIrsHVqo6Edg Content-Type: text/x-emacs-lisp; charset="iso-8859-15"; name="latex-i18n.el" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="latex-i18n.el" ;;; latex-i18n.el --- Support for i18n in LaTeX documents. ;; ;; Maintainer: ;; Version: 0.1 ;; Keywords: i18n, wp ;; X-URL: ;; ;; Copyright 2002 ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 1, or (at your option) ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;;; Code: (require 'latex) ;;; Setup: (provide 'latex-i18n) ;; Keymap ;(defvar latex-i18n-keymap ;(let ((map(copy-keymap LaTeX-mode-map))) ; (define-key map "\\" 'latex-i18n-backslash) ; (define-key map "\}" 'latex-i18n-rmoustache) ; (define-key map "\{" 'latex-i18n-lmoustache) ; (define-key map " " 'latex-i18n-space) ; (define-key map "$" 'latex-i18n-dollar) ; map)) ;(defun latex-i18n-mode () ; (interactive) ; (make-variable-buffer-local 'slash-done) ; (make-variable-buffer-local 'starting-input-method) ; (make-variable-buffer-local 'starting-math-input-method) ; (make-variable-buffer-local 'been-in-math-mode) ; (make-variable-buffer-local 'starting-moustache) ; (make-variable-buffer-local 'latex-i18n-mode) ; (setq latex-i18n-mode t) ; (use-local-map latex-i18n-keymap)) ; (set-buffer-modified-p (buffer-modified-p))) (define-minor-mode latex-i18n-mode "Easy LaTeX input for foreign languages." nil "i18n" '(("\\" . latex-i18n-backslash) ("\}" . latex-i18n-rmoustache) ("\{" . latex-i18n-lmoustache) (" " . latex-i18n-space) ("$" . latex-i18n-dollar)) (interactive) (make-variable-buffer-local 'slash-done) (make-variable-buffer-local 'starting-input-method) (make-variable-buffer-local 'starting-math-input-method) (make-variable-buffer-local 'been-in-math-mode) (make-variable-buffer-local 'starting-moustache) (make-variable-buffer-local 'latex-i18n-mode) (setq latex-i18n-mode t) (TeX-set-mode-name)) ;(or (assoc 'latex-i18n-mode minor-mode-alist) ; (setq minor-mode-alist (cons '(latex-i18n-mode " i18n") minor-mode-alist))) ; (or (assoc 'latex-i18n-mode minor-mode-map-alist) ; (setq minor-mode-map-alist ; (cons (cons 'latex-i18n-mode latex-i18n-keymap) ; minor-mode-map-alist))) (defvar latex-i18n-regexp-list '("section" "subsection" "subsubsection" "text" "author" "title" "paragraph" "caption") "Environments that accept input in various languages (not just ASCII") (defun latex-i18n-backslash () (interactive) ;(unless(TeX-point-is-escaped) (setq starting-input-method current-input-method) (inactivate-input-method) (setq slash-done t) (insert "\\")) (defun latex-i18n-rmoustache () (interactive) (insert "\}") (when slash-done (save-excursion (backward-word 2) (if (and been-in-math-mode (looking-at "end")) (progn (activate-input-method starting-math-input-method) (setq been-in-math-mode nil)))) (when (texmathp) (if (save-excursion (backward-word 2) (looking-at "begin")) (progn (setq starting-math-input-method starting-input-method) (setq been-in-math-mode t) (inactivate-input-method)) (inactivate-input-method))) (setq starting-moustache nil) (setq slash-done nil))) (defun latex-i18n-lmoustache () (interactive) (when slash-done (save-excursion (backward-word 1) (let (non-math) (setq non-math (catch 'found (dolist (temp latex-i18n-regexp-list) (if (looking-at temp) (throw 'found t))))) (if non-math (activate-input-method starting-input-method)))) (setq starting-moustache t)) (insert "\{")) (defun latex-i18n-space () (interactive) (when slash-done (when (not starting-moustache) (activate-input-method starting-input-method) (setq slash-done nil))) (insert ?\ ) (do-auto-fill)) (defun latex-i18n-dollar () (interactive) (if (texmathp) (activate-input-method starting-math-input-method) (setq starting-math-input-method current-input-method) (inactivate-input-method)) (insert "$")) --Boundary-00=_4TDrIrsHVqo6Edg Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ auctex-devel mailing list auctex-devel@gnu.org http://lists.gnu.org/mailman/listinfo/auctex-devel --Boundary-00=_4TDrIrsHVqo6Edg--