emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

keyboard-coding-system in Carbon Emacs


From: YAMAMOTO Mitsuharu
Subject: keyboard-coding-system in Carbon Emacs
Date: Wed, 06 Apr 2005 12:26:57 +0900
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)

I think the default value of keyboard-coding-system in Carbon Emacs
has been source of annoyance.  Users have to set an appropriate value
to input non-ASCII characters using external input methods or
combinations with the option key.

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.  Because I can test this only in limited environments,
I'd like to ask Carbon Emacs users, especially non-US keyboard users,
to test this patch in various environments.  It makes the variable
`mac-keyboard-text-encoding' and related constants (kTextEncoding...)
obsolete, so please comment out the setting of this variable if you
have one in your ~/.emacs before testing.

                                     YAMAMOTO Mitsuharu
                                address@hidden

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        6 Apr 2005 03:23:05 -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,1110 ----
  (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
!     (25 . cn-gb)                      ; smSimpChinese
!     )
!   "Alist of Mac script codes vs Emacs coding systems.")
  
! (defun mac-set-keyboard-coding-system (event)
!   (interactive "e")
!   (let ((coding-system
!        (cdr (assq (nth 1 (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] "\\"))))
  
+ (global-set-key [language-change] 'mac-set-keyboard-coding-system)
  
  ;;;; Selections and cut buffers
  
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      6 Apr 2005 03:23:05 -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,4044 ----
            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 (FRAME KEY_SCRIPT)).  */
+         obj = Fcons (make_number (event->code), Qnil);
+         obj = Fcons (event->frame_or_window, obj);
+ #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
--- 10843,10849 ----
    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       6 Apr 2005 03:23:05 -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     6 Apr 2005 03:23:06 -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]