all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to implement the function? Identify state of input method.
@ 2008-08-20  5:39 xiaopeng hu
  2008-08-20 15:15 ` [AUCTeX] " auxsvr
  0 siblings, 1 reply; 2+ messages in thread
From: xiaopeng hu @ 2008-08-20  5:39 UTC (permalink / raw)
  To: auctex; +Cc: help-gnu-emacs

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

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

[-- Attachment #2: Type: text/html, Size: 566 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [AUCTeX] How to implement the function? Identify state of input method.
  2008-08-20  5:39 How to implement the function? Identify state of input method xiaopeng hu
@ 2008-08-20 15:15 ` auxsvr
  0 siblings, 0 replies; 2+ messages in thread
From: auxsvr @ 2008-08-20 15:15 UTC (permalink / raw)
  To: auctex-devel, help-gnu-emacs; +Cc: xiaopeng hu

[-- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-08-20 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-20  5:39 How to implement the function? Identify state of input method xiaopeng hu
2008-08-20 15:15 ` [AUCTeX] " auxsvr

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.