Zhang, I finally got fcitx working, and saw the problem with my code.
NOTE: This patch has been committed.
lisp/ChangeLog addition:
2005-12-17 Aidan Kehoe <kehoea(a)parhasard.net>
* mule/mule-cmds.el (set-language-environment-coding-systems):
Initialise keyboard-coding-system, terminal-coding-system when
applying a language environment, together with the input and
output coding systems for any active TTY console.
* mule/mule-cmds.el (init-locale-at-early-startup):
If set-current-locale returns a `more-specified version' of the
current locale when passed a zero length argument, the magic used
to work out the current language environment from the C locale
will fail. Call current-locale instead.
src/ChangeLog addition:
2005-12-17 Aidan Kehoe <kehoea(a)parhasard.net>
* console-x.c (x_perhaps_init_unseen_key_defaults):
If the key name is a single character, and the keysym is NoSymbol,
give it a default binding, if that is possible. This addresses the
problem Zhang Wei points out in <871x118lc4.fsf(a)gmail.com>
* event-Xt.c (x_to_emacs_keysym):
Print the characters of a keysym's name directly if it's printable
ASCII, or as an octal escape if it's not.
Use keyboard-coding-system rather than undecided for decoding the
keysym name passed to us by an input method.
* file-coding.c (vars_of_file_coding):
Document that keyboard-coding-system is also used for X11.
XEmacs Trunk source patch:
Diff command: cvs -q diff -u
Files affected: src/file-coding.c src/event-Xt.c src/console-x.c lisp/mule/mule-cmds.el
Index: lisp/mule/mule-cmds.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lisp/mule/mule-cmds.el,v
retrieving revision 1.25
diff -u -u -r1.25 mule-cmds.el
--- lisp/mule/mule-cmds.el 2005/10/04 16:43:36 1.25
+++ lisp/mule/mule-cmds.el 2005/12/17 19:39:21
@@ -1271,6 +1271,20 @@
(warn "Invalid native-coding-system %s in language environment %s"
native language-name)))
(define-coding-system-alias 'file-name 'native)
+ ;; Set the default keyboard and terminal coding systems to the native
+ ;; coding system of the language environment.
+ ;;
+ (setq keyboard-coding-system native
+ terminal-coding-system native)
+
+ ;; And do the same for any TTYs.
+ (dolist (con (console-list))
+ (when (eq 'tty (device-type (car (console-device-list con))))
+ ;; Calling set-input-mode at the same time would be a sane thing
+ ;; to do here. I would prefer to default to accepting eight bit
+ ;; input and not using the top bit for Meta.
+ (set-console-tty-coding-system con native)))
+
;; process output should not have EOL conversion. under MS Windows
;; and Cygwin, this screws things up (`cmd' is fine with just LF and
;; `bash' chokes on CR-LF).
@@ -1327,7 +1341,7 @@
;; locale but we should still use the right code page, etc.
(declare-fboundp (mswindows-set-current-locale userdef)))
;; Unix:
- (let ((locstring (set-current-locale "")))
+ (let ((locstring (current-locale)))
;; assume C lib locale and LANG env var are set correctly. use
;; them to find the langenv.
(setq langenv
Index: src/console-x.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/console-x.c,v
retrieving revision 1.15
diff -u -u -r1.15 console-x.c
--- src/console-x.c 2005/06/29 09:47:35 1.15
+++ src/console-x.c 2005/12/17 19:39:21
@@ -349,6 +349,26 @@
xkeysym = XStringToKeysym(keysym_ext);
if (NoSymbol == xkeysym)
{
+ /* Keysym is NoSymbol; this may mean the key event passed to us came
+ from an input method, which stored the actual character intended to
+ be inserted in the key name, and didn't trouble itself to set the
+ keycode to anything useful. Thus, if the key name is a single
+ character, and the keysym is NoSymbol, give it a default binding,
+ if that is possible. */
+ Lisp_Object keychar;
+
+ if (1 != string_char_length(key_name))
+ {
+ /* Don't let them pass us more than one character. */
+ return Qnil;
+ }
+ keychar = make_char(itext_ichar(XSTRING_DATA(key_name)));
+ if (NILP (Flookup_key (Vcurrent_global_map, keychar, Qnil)))
+ {
+ Fdefine_key (Vcurrent_global_map, keychar, Qself_insert_command);
+ Fputhash (keychar, Qt, DEVICE_X_KEYSYM_MAP_HASH_TABLE (d));
+ return Qt;
+ }
return Qnil;
}
Index: src/event-Xt.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/event-Xt.c,v
retrieving revision 1.89
diff -u -u -r1.89 event-Xt.c
--- src/event-Xt.c 2005/11/26 11:46:07 1.89
+++ src/event-Xt.c 2005/12/17 19:39:26
@@ -898,7 +898,16 @@
int j;
stderr_out (" chars=\"");
for (j=0; j<len; j++)
- stderr_out ("%c", bufptr[j]);
+ {
+ if (040 <= bufptr[j] && bufptr[j] >= 0177)
+ {
+ stderr_out ("%c", bufptr[j]);
+ }
+ else
+ {
+ stderr_out ("\\%o", (unsigned)(bufptr[j]));
+ }
+ }
stderr_out ("\"");
}
else if (bufptr[0] <= 32 || bufptr[0] >= 127)
@@ -928,10 +937,18 @@
fb_instream = make_fixed_buffer_input_stream (bufptr, len);
- /* #### Use get_coding_system_for_text_file (Vcomposed_input_coding_system, 0)
*/
+ /* [[ Use get_coding_system_for_text_file
+ (Vcomposed_input_coding_system, 0) ]]
+
+ Nope. If it is possible for the X libraries to have multiple IM
+ connections on different DISPLAYs active at once, this should be
+ a console-specific variable (like a TTY's coding system) but I've
+ seen no evidence that that is possible. Aidan Kehoe,
+ 2005-12-17. */
+
instream =
make_coding_input_stream
- (XLSTREAM (fb_instream), Qundecided, CODING_DECODE, 0);
+ (XLSTREAM (fb_instream), Qkeyboard, CODING_DECODE, 0);
istr = XLSTREAM (instream);
Index: src/file-coding.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/file-coding.c,v
retrieving revision 1.49
diff -u -u -r1.49 file-coding.c
--- src/file-coding.c 2005/10/25 11:16:24 1.49
+++ src/file-coding.c 2005/12/17 19:39:33
@@ -4600,8 +4600,14 @@
#endif
DEFVAR_LISP ("keyboard-coding-system", &Vkeyboard_coding_system /*
-Coding system used for TTY keyboard input.
-Not used under a windowing system.
+Default coding system used for TTY and X11 keyboard input.
+Under X11, used only to interpet the character for a key event when that
+event has a KeySym of NoSymbol but does have an associated string keysym,
+something that's seen with input methods.
+
+If you need to set these things to different coding systems, call the
+function `set-console-tty-coding-system' for the TTY and use this variable
+for X11.
*/ );
Vkeyboard_coding_system = Qnil;
--
I AM IN JAIL AND ALLOWED SEND ONLY ONE CABLE SINCE WAS ARRESTED WHILE
MEASURING FIFTEEN FOOT WALL OUTSIDE PALACE AND HAVE JUST FINISHED COUNTING
THIRTY EIGHT THOUSAND FIVE HUNDERED TWENTY TWO NAMES WHOS WHO IN MIDEAST.