From 20ba0cb429e59716eeb84b0b6d828f675d53b1e2 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 29 Jul 2012 21:27:35 +0300 Subject: [PATCH] Fix bug #12082 with non-ASCII output in Windows GUI sessions. lisp/international/mule-cmds.el (set-locale-environment): Revert last change, since display-graphic-p returns nil when this function is called during startup. Instead... lisp/term/w32console.el (terminal-init-w32console): ...setup the keyboard and terminal encoding for TTY sessions here. --- lisp/ChangeLog | 9 ++++++++ lisp/international/mule-cmds.el | 41 +++++++++++++-------------------- lisp/term/w32console.el | 12 ++++++++++ 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 61ae993319a..a6fd9c3e0d3 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-07-29 Eli Zaretskii + + * international/mule-cmds.el (set-locale-environment): Revert last + change, since display-graphic-p returns nil when this function is + called during startup. Instead... + + * term/w32console.el (terminal-init-w32console): ...setup the + keyboard and terminal encoding for TTY sessions here. (Bug#12082) + 2012-07-29 Juri Linkov * simple.el (goto-line): Don't display default line number in the diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 0fbd6453c55..524840e05fd 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -2666,32 +2666,23 @@ See also `locale-charset-language-names', `locale-language-names', ;; On Windows, override locale-coding-system, ;; default-file-name-coding-system, keyboard-coding-system, - ;; terminal-coding-system with the appropriate codepages. + ;; terminal-coding-system with system codepage. (when (boundp 'w32-ansi-code-page) - (let ((ansi-code-page-coding (intern (format "cp%d" w32-ansi-code-page))) - (oem-code-page-coding - (intern (format "cp%d" (w32-get-console-codepage)))) - (oem-code-page-output-coding - (intern (format "cp%d" (w32-get-console-output-codepage)))) - ansi-cs-p oem-cs-p oem-o-cs-p) - (setq ansi-cs-p (coding-system-p ansi-code-page-coding)) - (setq oem-cs-p (coding-system-p oem-code-page-coding)) - (setq oem-o-cs-p (coding-system-p oem-code-page-output-coding)) - ;; Set the keyboard and display encoding to either the current - ;; ANSI codepage of the OEM codepage, depending on whether - ;; this is a GUI or a TTY frame. - (when ansi-cs-p - (unless frame (setq locale-coding-system ansi-code-page-coding)) - (when (display-graphic-p frame) - (set-keyboard-coding-system ansi-code-page-coding frame) - (set-terminal-coding-system ansi-code-page-coding frame)) - (setq default-file-name-coding-system ansi-code-page-coding)) - (when oem-cs-p - (unless (display-graphic-p frame) - (set-keyboard-coding-system oem-code-page-coding frame) - (set-terminal-coding-system - (if oem-o-cs-p oem-code-page-output-coding oem-code-page-coding) - frame))))) + (let ((code-page-coding (intern (format "cp%d" w32-ansi-code-page)))) + (when (coding-system-p code-page-coding) + (unless frame (setq locale-coding-system code-page-coding)) + (set-keyboard-coding-system code-page-coding frame) + (set-terminal-coding-system code-page-coding frame) + ;; Set default-file-name-coding-system last, so that Emacs + ;; doesn't try to use cpNNNN when it defines keyboard and + ;; terminal encoding. That's because the above two lines + ;; will want to load code-pages.el, where cpNNNN are + ;; defined; if default-file-name-coding-system were set to + ;; cpNNNN while these two lines run, Emacs will want to use + ;; it for encoding the file name it wants to load. And that + ;; will fail, since cpNNNN is not yet usable until + ;; code-pages.el finishes loading. + (setq default-file-name-coding-system code-page-coding)))) (when (eq system-type 'darwin) ;; On Darwin, file names are always encoded in utf-8, no matter diff --git a/lisp/term/w32console.el b/lisp/term/w32console.el index d52a4e68932..ceaa936e79b 100644 --- a/lisp/term/w32console.el +++ b/lisp/term/w32console.el @@ -52,6 +52,18 @@ "Terminal initialization function for w32 console." ;; Share function key initialization with w32 gui frames (x-setup-function-keys (selected-frame)) + ;; Set terminal and keyboard encodings to the current OEM codepage. + (let ((oem-code-page-coding + (intern (format "cp%d" (w32-get-console-codepage)))) + (oem-code-page-output-coding + (intern (format "cp%d" (w32-get-console-output-codepage)))) + oem-cs-p oem-o-cs-p) + (setq oem-cs-p (coding-system-p oem-code-page-coding)) + (setq oem-o-cs-p (coding-system-p oem-code-page-output-coding)) + (when oem-cs-p + (set-keyboard-coding-system oem-code-page-coding) + (set-terminal-coding-system + (if oem-o-cs-p oem-code-page-output-coding oem-code-page-coding)))) (let* ((colors w32-tty-standard-colors) (color (car colors))) (tty-color-clear) -- 2.39.2