Subject: bug#12082: 24.1.50; Wrong character showed by "C-h c"

From: Eli Zaretskii <[email-masked]>
Date: Mon, 30 Jul 2012 17:32:23 +0300

> From: Juanma Barranquero <[email-masked]>
> Date: Mon, 30 Jul 2012 13:47:44 +0200
> 
> On Mon, Jul 30, 2012 at 5:37 AM, Eli Zaretskii <[email-masked]> wrote:
> 
> > Interesting.  How did you two type M-ç?  And what are your values of
> > keyboard and terminal coding-systems, and also what does
> > w32-get-console-codepage return?
> 
> Ah, now I see a difference. Interesting, yes.
> 
> I did the last check from a TCC console, not CMD, the difference being
> that in TCC I set the codepage to 1252, while CMD uses 850.
> 
> So yes, starting emacs from CMD in window mode, C-h c M-ç indeed
> produces the ‡ message.
> 
> I type M-ç with the left Alt key and the ç key of the Spanish keyboard.
> 
> So, to summarize:
> 
> - In CMD, with active codepage = 437
>   - Window mode:
>     keyboard-coding-system = windows-1252-unix
>     (terminal-coding-system) =  cp1252
>     (w32-get-console-codepage) = 437
>     Messages: "M-‡ is undefined"
> 
>   - Non-window mode:
>     keyboard-coding-system = cp437-unix
>     (terminal-coding-system) = cp437
>     (w32-get-console-codepage) = 437
>     Messages: "M-ç is undefined"
> 
> - In CMD, with active codepage = 850
> 
>   - Window mode:
>     keyboard-coding-system = windows-1252-unix
>     (terminal-coding-system) = cp1252
>     (w32-get-console-codepage) = 850
>     Message: "M-‡ is undefined"
> 
>   - Non-window mode:
>     keyboard-coding-system = cp850-unix
>     (terminal-coding-system) = cp850
>     (w32-get-console-codepage) = 850
>     Message: "M-ç is undefined"
> 
> - In CMD, with active codepage = 1252
> 
>   - Window mode:
>     keyboard-coding-system = windows-1252-unix
>     (terminal-coding-system) = cp1252
>     (w32-get-console-codepage) = 1252
>     Message: "M-ç is undefined"
> 
>   - Non-window mode:
>     keyboard-coding-system = windows-1252-unix
>     (terminal-coding-system) = cp1252
>     (w32-get-console-codepage) = 1252
>     Message: "M-ç is undefined"

Looks like Windows lies to us about the input codepage.  Please apply
the patches below, run Emacs in GUI mode under GDB, and do the
following experiments:

  . switch the keyboard to English ("EN" near the system tray), if you
    can, and type a couple of pure ASCII characters

  . switch the keyboard to Spanish and type ç and M-ç

  . do the latter both with active codepage 850 and 1252

In each case, show the DebPrint messages shown by GDB as result of
typing each character.

Thanks.

=== modified file 'src/w32fns.c'
--- src/w32fns.c	2012-07-29 08:18:29 +0000
+++ src/w32fns.c	2012-07-30 14:06:20 +0000
@@ -2918,6 +2918,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARA
 
     case WM_SYSCHAR:
     case WM_CHAR:
+      DebPrint (("w32fns: WM_CHAR 0x%x\n", wParam));
       post_character_message (hwnd, msg, wParam, lParam,
 			      w32_get_key_modifiers (wParam, lParam));
       break;
@@ -2939,6 +2940,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARA
 
       {
         W32Msg wmsg;
+	DebPrint (("w32fns: WM_UNICHAR 0x%x\n", wParam));
         wmsg.dwModifiers = w32_get_key_modifiers (wParam, lParam);
         signal_user_input ();
         my_post_msg (&wmsg, hwnd, msg, wParam, lParam);

=== modified file 'src/w32term.c'
--- src/w32term.c	2012-07-29 08:18:29 +0000
+++ src/w32term.c	2012-07-30 14:07:21 +0000
@@ -4295,6 +4295,7 @@ w32_read_socket (struct terminal *termin
 
               if (msg.msg.message == WM_UNICHAR)
                 {
+		  DebPrint (("w32term: WM_UNICHAR 0x%x\n", msg.msg.wParam));
                   inev.code = msg.msg.wParam;
                 }
               else if (msg.msg.wParam < 256)
@@ -4336,6 +4337,9 @@ w32_read_socket (struct terminal *termin
                           break;
                         }
                     }
+
+		  DebPrint (("w32term: 0x%x => 0x%x (cp%d)\n",
+			     (char) msg.msg.wParam, code, keyboard_codepage));
                   inev.code = code;
                 }
               else