From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.devel Subject: Re: keyboard-coding-system in Carbon Emacs Date: Fri, 08 Apr 2005 14:18:23 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: sea.gmane.org 1112937449 21543 80.91.229.2 (8 Apr 2005 05:17:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 8 Apr 2005 05:17:29 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 08 07:17:22 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DJlrl-00047F-9f for ged-emacs-devel@m.gmane.org; Fri, 08 Apr 2005 07:17:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DJlRC-0001Km-9q for ged-emacs-devel@m.gmane.org; Fri, 08 Apr 2005 00:49:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DJlQx-0001JG-HB for emacs-devel@gnu.org; Fri, 08 Apr 2005 00:49:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DJlQs-0001G4-O9 for emacs-devel@gnu.org; Fri, 08 Apr 2005 00:49:27 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DJlQs-0001Ff-Jo for emacs-devel@gnu.org; Fri, 08 Apr 2005 00:49:26 -0400 Original-Received: from [133.82.132.2] (helo=mathmail.math.s.chiba-u.ac.jp) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DJltj-00065L-Ql for emacs-devel@gnu.org; Fri, 08 Apr 2005 01:19:16 -0400 Original-Received: from church.math.s.chiba-u.ac.jp (church [133.82.132.36]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id B391F1A63A8 for ; Fri, 8 Apr 2005 14:18:23 +0900 (JST) Original-To: emacs-devel@gnu.org In-Reply-To: User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.6 (Marutamachi) APEL/10.6 Emacs/22.0.50 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:35740 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:35740 >>>>> On Wed, 06 Apr 2005 12:26:57 +0900, YAMAMOTO Mitsuharu said: > The patch below is an attempt to solve such a problem by dynamically > changing the value of keyboard-coding-system by detecting keyboard > layout changes. In the previous patch, I used global-set-key to bind a handler function for the `language-change' event. But it seems to work best if it is bound in special-event-map so that the event may not be ignored by read-char-exclusive or explicitly read by read-key-sequence. Is it OK to use special-event-map for this purpose? Below is the revised patch. Input methods whose script is either Roman, Japanese, Traditional Chinese, Korean, Cyrillic, Simplified Chinese, or Central European (in order of Mac script code) should work, but not for Unicode. Scripts of input methods are displayed at the `Script' column in System Preferences -> International -> Input Menu. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp Index: lisp/term/mac-win.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/term/mac-win.el,v retrieving revision 1.36 diff -c -r1.36 mac-win.el *** lisp/term/mac-win.el 6 Apr 2005 02:15:29 -0000 1.36 --- lisp/term/mac-win.el 8 Apr 2005 04:43:31 -0000 *************** *** 1085,1097 **** (put 'escape 'ascii-character ?\e) ! ;;;; Keysyms ! ;; Define constant values to be set to mac-keyboard-text-encoding ! (defconst kTextEncodingMacRoman 0) ! (defconst kTextEncodingISOLatin1 513 "0x201") ! (defconst kTextEncodingISOLatin2 514 "0x202") ;;;; Selections and cut buffers --- 1085,1113 ---- (put 'escape 'ascii-character ?\e) ! ;;;; Keyboard layout/language change events ! (defconst mac-script-code-coding-systems ! '((0 . mac-roman) ; smRoman ! (1 . sjis) ; smJapanese ! (2 . big5) ; smTradChinese ! (3 . euc-kr) ; smKorean ! (7 . mac-cyrillic) ; smCyrillic ! (25 . cn-gb) ; smSimpChinese ! (29 . mac-centraleurroman) ; smCentralEuroRoman ! ) ! "Alist of Mac script codes vs Emacs coding systems.") ! ;;;; Keyboard layout/language change events ! (defun mac-handle-language-change (event) ! (interactive "e") ! (let ((coding-system ! (cdr (assq (car (cadr event)) mac-script-code-coding-systems)))) ! (set-keyboard-coding-system (or coding-system 'mac-roman)) ! ;; MacJapanese maps reverse solidus to ?\x80. ! (if (eq coding-system 'sjis) ! (define-key key-translation-map [?\x80] "\\")))) + (define-key special-event-map [language-change] 'mac-handle-language-change) ;;;; Selections and cut buffers *************** *** 1139,1159 **** (setq frame-creation-function 'x-create-frame-with-faces) ! (define-ccl-program ccl-encode-mac-roman-font ! `(0 ! (if (r0 != ,(charset-id 'ascii)) ! (if (r0 <= ?\x8f) ! (translate-character mac-roman-encoder r0 r1) ! ((r1 <<= 7) ! (r1 |= r2) ! (translate-character mac-roman-encoder r0 r1))))) ! "CCL program for Mac Roman font") ! ! (let ! ((encoding-vector (make-vector 256 nil)) ! (i 0) ! (vec ;; mac-centraleurroman (128..255) -> UCS mapping ! [ #x00C4 ;; 128:LATIN CAPITAL LETTER A WITH DIAERESIS #x0100 ;; 129:LATIN CAPITAL LETTER A WITH MACRON #x0101 ;; 130:LATIN SMALL LETTER A WITH MACRON #x00C9 ;; 131:LATIN CAPITAL LETTER E WITH ACUTE --- 1155,1168 ---- (setq frame-creation-function 'x-create-frame-with-faces) ! (cp-make-coding-system ! mac-centraleurroman ! (apply ! 'vector ! (mapcar ! (lambda (c) (decode-char 'ucs c)) ! ;; mac-centraleurroman (128..255) -> UCS mapping ! [ #x00C4 ;; 128:LATIN CAPITAL LETTER A WITH DIAERESIS #x0100 ;; 129:LATIN CAPITAL LETTER A WITH MACRON #x0101 ;; 130:LATIN SMALL LETTER A WITH MACRON #x00C9 ;; 131:LATIN CAPITAL LETTER E WITH ACUTE *************** *** 1281,1306 **** #x017C ;; 253:LATIN SMALL LETTER Z WITH DOT ABOVE #x0122 ;; 254:LATIN CAPITAL LETTER G WITH CEDILLA #x02C7 ;; 255:CARON ! ]) ! translation-table) ! (while (< i 128) ! (aset encoding-vector i i) ! (setq i (1+ i))) ! (while (< i 256) ! (aset encoding-vector i ! (decode-char 'ucs (aref vec (- i 128)))) ! (setq i (1+ i))) ! (setq translation-table ! (make-translation-table-from-vector encoding-vector)) ! ;; (define-translation-table 'mac-centraleurroman-decoder translation-table) ! (define-translation-table 'mac-centraleurroman-encoder ! (char-table-extra-slot translation-table 0))) ! ! (let ! ((encoding-vector (make-vector 256 nil)) ! (i 0) ! (vec ;; mac-cyrillic (128..255) -> UCS mapping ! [ #x0410 ;; 128:CYRILLIC CAPITAL LETTER A #x0411 ;; 129:CYRILLIC CAPITAL LETTER BE #x0412 ;; 130:CYRILLIC CAPITAL LETTER VE #x0413 ;; 131:CYRILLIC CAPITAL LETTER GHE --- 1290,1307 ---- #x017C ;; 253:LATIN SMALL LETTER Z WITH DOT ABOVE #x0122 ;; 254:LATIN CAPITAL LETTER G WITH CEDILLA #x02C7 ;; 255:CARON ! ])) ! "Mac Central European Roman Encoding (MIME:x-mac-centraleurroman).") ! (coding-system-put 'mac-centraleurroman 'mime-charset 'x-mac-centraleurroman) ! ! (cp-make-coding-system ! mac-cyrillic ! (apply ! 'vector ! (mapcar ! (lambda (c) (decode-char 'ucs c)) ! ;; mac-cyrillic (128..255) -> UCS mapping ! [ #x0410 ;; 128:CYRILLIC CAPITAL LETTER A #x0411 ;; 129:CYRILLIC CAPITAL LETTER BE #x0412 ;; 130:CYRILLIC CAPITAL LETTER VE #x0413 ;; 131:CYRILLIC CAPITAL LETTER GHE *************** *** 1428,1454 **** #x044D ;; 253:CYRILLIC SMALL LETTER E #x044E ;; 254:CYRILLIC SMALL LETTER YU #x20AC ;; 255:EURO SIGN ! ]) ! translation-table) ! (while (< i 128) ! (aset encoding-vector i i) ! (setq i (1+ i))) ! (while (< i 256) ! (aset encoding-vector i ! (decode-char 'ucs (aref vec (- i 128)))) ! (setq i (1+ i))) ! (setq translation-table ! (make-translation-table-from-vector encoding-vector)) ! ;; (define-translation-table 'mac-cyrillic-decoder translation-table) ! (define-translation-table 'mac-cyrillic-encoder ! (char-table-extra-slot translation-table 0))) (defvar mac-font-encoder-list '(("mac-roman" mac-roman-encoder ccl-encode-mac-roman-font "%s") ! ("mac-centraleurroman" mac-centraleurroman-encoder ccl-encode-mac-centraleurroman-font "%s ce") ! ("mac-cyrillic" mac-cyrillic-encoder ccl-encode-mac-cyrillic-font "%s cy"))) (let ((encoder-list --- 1429,1444 ---- #x044D ;; 253:CYRILLIC SMALL LETTER E #x044E ;; 254:CYRILLIC SMALL LETTER YU #x20AC ;; 255:EURO SIGN ! ])) ! "Mac Cyrillic Encoding (MIME:x-mac-cyrillic).") ! (coding-system-put 'mac-cyrillic 'mime-charset 'x-mac-cyrillic) (defvar mac-font-encoder-list '(("mac-roman" mac-roman-encoder ccl-encode-mac-roman-font "%s") ! ("mac-centraleurroman" encode-mac-centraleurroman ccl-encode-mac-centraleurroman-font "%s ce") ! ("mac-cyrillic" encode-mac-cyrillic ccl-encode-mac-cyrillic-font "%s cy"))) (let ((encoder-list *************** *** 1468,1491 **** (if mac-encoded (aset table c mac-encoded)))))))) (define-ccl-program ccl-encode-mac-centraleurroman-font `(0 (if (r0 != ,(charset-id 'ascii)) (if (r0 <= ?\x8f) ! (translate-character mac-centraleurroman-encoder r0 r1) ((r1 <<= 7) (r1 |= r2) ! (translate-character mac-centraleurroman-encoder r0 r1))))) "CCL program for Mac Central European Roman font") (define-ccl-program ccl-encode-mac-cyrillic-font `(0 (if (r0 != ,(charset-id 'ascii)) (if (r0 <= ?\x8f) ! (translate-character mac-cyrillic-encoder r0 r1) ((r1 <<= 7) (r1 |= r2) ! (translate-character mac-cyrillic-encoder r0 r1))))) "CCL program for Mac Cyrillic font") --- 1458,1491 ---- (if mac-encoded (aset table c mac-encoded)))))))) + (define-ccl-program ccl-encode-mac-roman-font + `(0 + (if (r0 != ,(charset-id 'ascii)) + (if (r0 <= ?\x8f) + (translate-character mac-roman-encoder r0 r1) + ((r1 <<= 7) + (r1 |= r2) + (translate-character mac-roman-encoder r0 r1))))) + "CCL program for Mac Roman font") + (define-ccl-program ccl-encode-mac-centraleurroman-font `(0 (if (r0 != ,(charset-id 'ascii)) (if (r0 <= ?\x8f) ! (translate-character encode-mac-centraleurroman r0 r1) ((r1 <<= 7) (r1 |= r2) ! (translate-character encode-mac-centraleurroman r0 r1))))) "CCL program for Mac Central European Roman font") (define-ccl-program ccl-encode-mac-cyrillic-font `(0 (if (r0 != ,(charset-id 'ascii)) (if (r0 <= ?\x8f) ! (translate-character encode-mac-cyrillic r0 r1) ((r1 <<= 7) (r1 |= r2) ! (translate-character encode-mac-cyrillic r0 r1))))) "CCL program for Mac Cyrillic font") Index: src/keyboard.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/keyboard.c,v retrieving revision 1.817 diff -c -r1.817 keyboard.c *** src/keyboard.c 31 Mar 2005 10:11:14 -0000 1.817 --- src/keyboard.c 8 Apr 2005 04:43:31 -0000 *************** *** 530,536 **** /* Symbols to denote kinds of events. */ Lisp_Object Qfunction_key; Lisp_Object Qmouse_click; ! #ifdef WINDOWSNT Lisp_Object Qlanguage_change; #endif Lisp_Object Qdrag_n_drop; --- 530,536 ---- /* Symbols to denote kinds of events. */ Lisp_Object Qfunction_key; Lisp_Object Qmouse_click; ! #if defined (WINDOWSNT) || defined (MAC_OS) Lisp_Object Qlanguage_change; #endif Lisp_Object Qdrag_n_drop; *************** *** 4028,4038 **** x_activate_menubar (XFRAME (event->frame_or_window)); } #endif ! #ifdef WINDOWSNT else if (event->kind == LANGUAGE_CHANGE_EVENT) { /* Make an event (language-change (FRAME CHARSET LCID)). */ obj = Fcons (event->frame_or_window, Qnil); obj = Fcons (Qlanguage_change, Fcons (obj, Qnil)); kbd_fetch_ptr = event + 1; } --- 4028,4043 ---- x_activate_menubar (XFRAME (event->frame_or_window)); } #endif ! #if defined (WINDOWSNT) || defined (MAC_OS) else if (event->kind == LANGUAGE_CHANGE_EVENT) { + #ifdef MAC_OS + /* Make an event (language-change (KEY_SCRIPT)). */ + obj = Fcons (make_number (event->code), Qnil); + #else /* Make an event (language-change (FRAME CHARSET LCID)). */ obj = Fcons (event->frame_or_window, Qnil); + #endif obj = Fcons (Qlanguage_change, Fcons (obj, Qnil)); kbd_fetch_ptr = event + 1; } *************** *** 10837,10843 **** staticpro (&Qfunction_key); Qmouse_click = intern ("mouse-click"); staticpro (&Qmouse_click); ! #ifdef WINDOWSNT Qlanguage_change = intern ("language-change"); staticpro (&Qlanguage_change); #endif --- 10842,10848 ---- staticpro (&Qfunction_key); Qmouse_click = intern ("mouse-click"); staticpro (&Qmouse_click); ! #if defined (WINDOWSNT) || defined (MAC_OS) Qlanguage_change = intern ("language-change"); staticpro (&Qlanguage_change); #endif Index: src/macterm.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/macterm.c,v retrieving revision 1.106 diff -c -r1.106 macterm.c *** src/macterm.c 16 Mar 2005 08:08:06 -0000 1.106 --- src/macterm.c 8 Apr 2005 04:43:32 -0000 *************** *** 7148,7155 **** --- 7148,7157 ---- /* convert input from Mac keyboard (assumed to be in Mac Roman coding) to this text encoding */ + #if 0 int mac_keyboard_text_encoding; int current_mac_keyboard_text_encoding = kTextEncodingMacRoman; + #endif /* Set in term/mac-win.el to indicate that event loop can now generate drag and drop events. */ *************** *** 8964,8969 **** --- 8966,8991 ---- break; } #endif + { + static SInt16 last_key_script = -1; + SInt16 current_key_script = GetScriptManagerVariable (smKeyScript); + + if (last_key_script != current_key_script) + { + struct input_event event; + + EVENT_INIT (event); + event.kind = LANGUAGE_CHANGE_EVENT; + event.arg = Qnil; + XSETFRAME (event.frame_or_window, + mac_window_to_frame (front_emacs_window ())); + event.timestamp = er.when * (1000 / 60); + event.code = current_key_script; + kbd_buffer_store_event_hold (&event, hold_quit); + count++; + } + last_key_script = current_key_script; + } ObscureCursor (); *************** *** 9016,9021 **** --- 9038,9044 ---- } } + #if 0 /* If variable mac-convert-keyboard-input-to-latin-1 is non-nil, convert non-ASCII characters typed at the Mac keyboard (presumed to be in the Mac Roman encoding) to *************** *** 9079,9084 **** --- 9102,9108 ---- } } } + #endif #if USE_CARBON_EVENTS inev.modifiers = mac_event_to_emacs_modifiers (eventRef); *************** *** 9893,9898 **** --- 9917,9923 ---- may anti-alias the text. */); Vmac_use_core_graphics = Qnil; + #if 0 DEFVAR_INT ("mac-keyboard-text-encoding", &mac_keyboard_text_encoding, doc: /* One of the Text Encoding Base constant values defined in the Basic Text Constants section of Inside Macintosh - Text Encoding *************** *** 9907,9912 **** --- 9932,9938 ---- command, this enables the Mac keyboard to be used to enter non-ASCII characters directly. */); mac_keyboard_text_encoding = kTextEncodingMacRoman; + #endif } /* arch-tag: f2259165-4454-4c04-a029-a133c8af7b5b Index: src/termhooks.h =================================================================== RCS file: /cvsroot/emacs/emacs/src/termhooks.h,v retrieving revision 1.67 diff -c -r1.67 termhooks.h *** src/termhooks.h 27 Feb 2004 23:48:49 -0000 1.67 --- src/termhooks.h 8 Apr 2005 04:43:32 -0000 *************** *** 252,261 **** the wheel event occurred in. .timestamp gives a timestamp (in milliseconds) for the event. */ ! #ifdef WINDOWSNT ! LANGUAGE_CHANGE_EVENT, /* A LANGUAGE_CHANGE_EVENT is generated ! on WINDOWSNT when the keyboard layout ! or input language is changed by the user. */ #endif SCROLL_BAR_CLICK_EVENT, /* .code gives the number of the mouse button --- 252,262 ---- the wheel event occurred in. .timestamp gives a timestamp (in milliseconds) for the event. */ ! #if defined (WINDOWSNT) || defined (MAC_OS) ! LANGUAGE_CHANGE_EVENT, /* A LANGUAGE_CHANGE_EVENT is ! generated on WINDOWSNT or Mac OS ! when the keyboard layout or input ! language is changed by the user. */ #endif SCROLL_BAR_CLICK_EVENT, /* .code gives the number of the mouse button