all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: auxsvr@gmail.com
To: auctex-devel@gnu.org, help-gnu-emacs@gnu.org
Cc: xiaopeng hu <huxiaopengstat@gmail.com>
Subject: Re: [AUCTeX] How to implement the function? Identify state of input method.
Date: Wed, 20 Aug 2008 18:15:03 +0300	[thread overview]
Message-ID: <200808201815.04707.auxsvr@gmail.com> (raw)
In-Reply-To: <ffe0539f0808192239h300e0c10u46cc1a9454e3471a@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 883 bytes --]

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"+<space>, 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.

[-- Attachment #2: latex-i18n.el --]
[-- Type: text/x-emacs-lisp, Size: 4396 bytes --]

;;; latex-i18n.el --- Support for i18n in LaTeX documents.
;; 
;; Maintainer: <auxsvr@yahoo.com>
;; 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 "$"))

[-- Attachment #3: Type: text/plain, Size: 146 bytes --]

_______________________________________________
auctex-devel mailing list
auctex-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/auctex-devel

      reply	other threads:[~2008-08-20 15:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-20  5:39 How to implement the function? Identify state of input method xiaopeng hu
2008-08-20 15:15 ` auxsvr [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=200808201815.04707.auxsvr@gmail.com \
    --to=auxsvr@gmail.com \
    --cc=auctex-devel@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=huxiaopengstat@gmail.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.