Function: set-keyboard-coding-system

set-keyboard-coding-system is an interactive and byte-compiled function defined in mule.el.gz.

Signature

(set-keyboard-coding-system CODING-SYSTEM &optional TERMINAL)

Documentation

Set coding system for keyboard input on TERMINAL to CODING-SYSTEM.

For a list of possible values of CODING-SYSTEM, use M-x list-coding-systems (list-coding-systems). The default is determined by the selected language environment or by the previous use of this command.

If CODING-SYSTEM is nil or the coding-type of CODING-SYSTEM is raw-text, the decoding of keyboard input is disabled.

TERMINAL may be a terminal object, a frame, or nil for the selected frame's terminal.

The setting has no effect on graphical terminals. It also has no effect on MS-Windows text-mode terminals, except on Windows 9X systems. For Windows 9X, see also w32-set-console-codepage.

View in manual

Probably introduced at or before Emacs version 20.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/international/mule.el.gz
(defun set-keyboard-coding-system (coding-system &optional terminal)
  "Set coding system for keyboard input on TERMINAL to CODING-SYSTEM.

For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
The default is determined by the selected language environment
or by the previous use of this command.

If CODING-SYSTEM is nil or the coding-type of CODING-SYSTEM is
`raw-text', the decoding of keyboard input is disabled.

TERMINAL may be a terminal object, a frame, or nil for the
selected frame's terminal.

The setting has no effect on graphical terminals.  It also
has no effect on MS-Windows text-mode terminals, except on
Windows 9X systems.  For Windows 9X, see also `w32-set-console-codepage'."
  (interactive
   (list (let* ((coding (keyboard-coding-system nil))
		(default (if (eq (coding-system-type coding) 'raw-text)
			     default-keyboard-coding-system)))
	   (read-coding-system
	    (format-prompt "Coding system for keyboard input" default)
	    default))))
  (let ((coding-type (coding-system-type coding-system))
	(saved-meta-mode
	 (terminal-parameter terminal 'keyboard-coding-saved-meta-mode)))
    (let (accept-8-bit)
      (if (not (or (coding-system-get coding-system :suitable-for-keyboard)
                   (coding-system-get coding-system :ascii-compatible-p)))
          (error "Unsuitable coding system for keyboard: %s" coding-system))
      (cond ((memq coding-type '(raw-text charset utf-8 shift-jis big5 ccl))
             (setq accept-8-bit t))
            ((eq coding-type 'iso-2022)
             (let ((flags (coding-system-get coding-system :flags)))
               (or (memq '7-bit flags)
                   (setq accept-8-bit t))))
            (t
             (error "Unsupported coding system for keyboard: %s"
                    coding-system)))
      (if accept-8-bit
          (progn
            (or saved-meta-mode
                (set-terminal-parameter terminal
                                        'keyboard-coding-saved-meta-mode
                                        (cons (nth 2 (current-input-mode))
                                              nil)))
            (set-input-meta-mode 8 terminal))
        (when saved-meta-mode
          (set-input-meta-mode (car saved-meta-mode) terminal)
          (set-terminal-parameter terminal
                                  'keyboard-coding-saved-meta-mode
                                  nil)))
      ;; Avoid end-of-line conversion.
      (setq coding-system
            (coding-system-change-eol-conversion coding-system 'unix))))
  (set-keyboard-coding-system-internal coding-system terminal)
  (setq keyboard-coding-system coding-system))