;;; mule-keyboard.el --- Direct input of multilingual chars from keyboard.;; Copyright (C) 1992 Free Software Foundation, Inc.;; This file is part of XEmacs.;; XEmacs is free software; you can redistribute it and/or modify it;; under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 2, or (at your option);; any later version.;; XEmacs is distributed in the hope that it will be useful, but;; WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU;; General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with XEmacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,;; Boston, MA 02111-1307, USA.;;; 92.3.5 created for Mule Ver.0.9.0 by K.Handa <handa@etl.go.jp>;;;###autoload(defvarkeyboard-allow-latin-inputnil"If non-nil, \"ESC , Fe\" and \"ESC - Fe\" are used for inputtingLatin characters.");; common global variables of internal use(defvar_keyboard-first-byte_nil"Character buffer for the first byte of two-byte character.")(defvar_keyboard-SS2_nil"Flag to indicate Single Shift SS2.")(defvar_keyboard-SS3_nil"Flag to indicate Single Shift SS3.")(defvar_keyboard-saved-local-map_nil"Saved local keymap.")(defvar_saved-local-map-single-shift_nil"Saved single shift local map.")(defvar_current-g0_0)(defvar_current-g1_nil)(defvar_current-g2_nil)(defvar_current-g3_nil)(defconstlocal-map-isonil"Local keymap used while inputing ISO2022 code directly.")(defconstlocal-map-shift-jisnil"Local keymap used while inputing Shift-JIS code directly.")(defconstlocal-map-big5nil"Local keymap used while inputing Big5 code directly.")(defconstesc-dol-mapnil"Keys to designate 94n or 96n charset.")(defconstesc-openpar-mapnil"Keys to designate 94 charset to GL.")(defconstesc-closepar-mapnil"Keys to designate 94 charset to GR.")(defconstesc-comma-mapnil"Keys to designate 96 charset to GL.")(defconstesc-minus-mapnil"Keys to designate 96 charset to GR.")(defconstesc-dol-openpar-mapnil"Keys to designate 94n charset to GL.")(defconstesc-dol-closepar-mapnil"Keys to designate 94n charset to GR.")(defconstesc-dol-comma-mapnil"Keys to designate 96n charset to GL.")(defconstesc-dol-minus-mapnil"Keys to designate 96n charset to GR.");;;###autoload(defunset-keyboard-coding-system(codesys)"Set variable keyboard-coding-system to CODESYS and modify keymap for it."(interactive"zKeyboard-coding-system: ")(let((type(coding-system-typecodesys)))(cond((eqtype'shift-jis)(set-keyboard-coding-system-shift-jis))((eqtype'iso2022)(set-keyboard-coding-system-iso2022codesys))((eqtype'big5)(set-keyboard-coding-system-big5))(t(error"Direct input of code %s is not supported."codesys)))))(defsubstkeyboard-define-key(mapkeycommand)(define-keymap(char-to-stringkey)commandt))(defunkeyboard-set-input-mode(value)(let((mode(current-input-mode)));; current-input-mode returns (INTERRUPT FLOW META QUIT-CHAR);; set META to value.(setcar(nthcdr2mode)value)(apply(functionset-input-mode)mode)))(defunkeyboard-select-keymap(&restmaps)(or(nth(get-code-typekeyboard-coding-system)maps)(error"invalid keyboard-coding-system")))(defunkeyboard-self-insert-do-insert(char)(self-insert-internalchar)(check-auto-fill));; ### I think this is the right function to put this on... must check further;; wire us into pending-delete(put'keyboard-self-insert-do-insert'pending-deletet)(defunkeyboard-use-local-map-do-insert(map)(use-local-mapmap))(defunkeyboard-current-local-map-do-insert()(current-local-map))(defunkeyboard-local-map-do-insert()(keyboard-select-keymapnillocal-map-shift-jislocal-map-isolocal-map-big5))(defconstkeyboard-self-insert-function(functionkeyboard-self-insert-do-insert))(defconstkeyboard-use-local-map-function(functionkeyboard-use-local-map-do-insert))(defconstkeyboard-current-local-map-function(functionkeyboard-current-local-map-do-insert))(defconstkeyboard-local-map-function(functionkeyboard-local-map-do-insert))(defunkeyboard-self-insert(char)(funcallkeyboard-self-insert-functionchar))(defunkeyboard-current-local-map()(funcallkeyboard-current-local-map-function))(defunkeyboard-use-local-map(map)(funcallkeyboard-use-local-map-functionmap))(defunkeyboard-local-map()(funcallkeyboard-local-map-function))(defunkeyboard-reset-state()(setq_keyboard-first-byte_nil_keyboard-SS2_nil_keyboard-SS3_nil))(defunkeyboard-define-global-map-iso(map)(let((i160))(while(<i256)(keyboard-define-keymapi'self-insert-iso)(setqi(1+i))))(define-keymap"\216"'keyboard-SS2t)(define-keymap"\217"'keyboard-SS3t)(define-keymap"\e("'esc-openpar-prefix)(define-keymap"\e)"'esc-closepar-prefix)(ifkeyboard-allow-latin-input(progn(define-keymap"\e,"'esc-comma-prefix)(define-keymap"\e-"'esc-minus-prefix)))(define-keymap"\e$"'esc-dol-prefix))(defunkeyboard-define-local-map-iso(map)(let((i33))(while(<i127)(keyboard-define-keymapi'self-insert-iso)(setqi(1+i)))))(defunset-keyboard-coding-system-iso2022(code)(setq_current-g0_(coding-system-charsetcode0))(setq_current-g1_(coding-system-charsetcode1))(setq_current-g2_(coding-system-charsetcode2))(setq_current-g3_(coding-system-charsetcode3))(if(null_current-g1_)(keyboard-set-input-modet); enable Meta-key(keyboard-set-input-mode0)); enable 8bit input as chars.(let(i)(setqi160)(while(<i256)(keyboard-define-keyglobal-mapi'self-insert-iso)(setqi(1+i))))(iflocal-map-isonil(setqlocal-map-iso(make-keymap))(let(imap)(setqi33)(while(<i127)(keyboard-define-keylocal-map-isoi'self-insert-iso)(setqi(1+i)))(setqmap(current-global-map))(setqi161)(while(<i255)(keyboard-define-keymapi'self-insert-iso)(setqi(1+i))))(define-keylocal-map-iso"\C-g"'mule-keyboard-quit))(ifesc-dol-mapnil(setqesc-dol-map(make-keymap)esc-openpar-map(make-keymap)esc-closepar-map(make-keymap)esc-comma-map(make-keymap)esc-minus-map(make-keymap)esc-dol-openpar-map(make-keymap)esc-dol-closepar-map(make-keymap)esc-dol-comma-map(make-keymap)esc-dol-minus-map(make-keymap))(fset'esc-dol-prefixesc-dol-map)(fset'esc-openpar-prefixesc-openpar-map)(fset'esc-closepar-prefixesc-closepar-map)(fset'esc-comma-prefixesc-comma-map)(fset'esc-minus-prefixesc-minus-map)(fset'esc-dol-openpar-prefixesc-dol-openpar-map)(fset'esc-dol-closepar-prefixesc-dol-closepar-map)(fset'esc-dol-comma-prefixesc-dol-comma-map)(fset'esc-dol-minus-prefixesc-dol-minus-map)(define-keyesc-dol-map"("'esc-dol-openpar-prefix)(define-keyesc-dol-map")"'esc-dol-closepar-prefix)(define-keyesc-dol-map","'esc-dol-comma-prefix)(define-keyesc-dol-map"-"'esc-dol-minus-prefix)(let(i)(setqi?0)(while(<i?`)(keyboard-define-keyesc-openpar-mapi'keyboard-designate-94-GL)(keyboard-define-keyesc-closepar-mapi'keyboard-designate-94-GR)(keyboard-define-keyesc-comma-mapi'keyboard-designate-96-GL)(keyboard-define-keyesc-minus-mapi'keyboard-designate-96-GR)(keyboard-define-keyesc-dol-mapi'keyboard-designate-94n-GL)(keyboard-define-keyesc-dol-openpar-mapi'keyboard-designate-94n-GL)(keyboard-define-keyesc-dol-closepar-mapi'keyboard-designate-94n-GR)(keyboard-define-keyesc-dol-comma-mapi'keyboard-designate-96n-GL)(keyboard-define-keyesc-dol-minus-mapi'keyboard-designate-96n-GR)(setqi(1+i)))))(define-keyglobal-map"\216"'keyboard-SS2t)(define-keyglobal-map"\217"'keyboard-SS3t)(define-keyesc-map"("'esc-openpar-prefix)(define-keyesc-map")"'esc-closepar-prefix)(ifkeyboard-allow-latin-input(progn(define-keyesc-map","'esc-comma-prefix)(define-keyesc-map"-"'esc-minus-prefix)))(define-keyesc-map"$"'esc-dol-prefix)(keyboard-reset-state)(setqkeyboard-coding-systemcode))(defunmule-keyboard-quit()(interactive)(keyboard-reset-state)(if_keyboard-saved-local-map_(keyboard-use-local-map_keyboard-saved-local-map_))(keyboard-quit))(defunkeyboard-change-local-map-for-iso()(if(eq(keyboard-current-local-map)(keyboard-local-map))nil(setq_keyboard-saved-local-map_(keyboard-current-local-map))(keyboard-use-local-map(keyboard-local-map))))(defunkeyboard-designate-94-GL()(interactive)(if(and(coding-system-use-japanese-jisx0201-romankeyboard-coding-system)(eq'japanese-jisx0201-roman(charset-from-attributes194last-command-char)))(setq_current-g0_'ascii)(setq_current-g0_(charset-from-attributes194last-command-char)))(if(eq_current-g0_'ascii)(keyboard-use-local-map_keyboard-saved-local-map_)(keyboard-change-local-map-for-iso)))(defunkeyboard-designate-94-GR()(interactive)(setq_current-g1_(charset-from-attributes194last-command-char)))(defunkeyboard-designate-96-GL()(interactive)(setq_current-g0_(charset-from-attributes196last-command-char))(keyboard-change-local-map-for-iso))(defunkeyboard-designate-96-GR()(interactive)(setq_current-g1_(charset-from-attributes196last-command-char)))(defunkeyboard-designate-94n-GL()(interactive)(if(and(coding-system-use-japanese-jisx0208-1978keyboard-coding-system)(eq'japanese-jisx0208-1978(charset-from-attributes294last-command-char)))(setq_current-g0_'japanese-jisx0208)(setq_current-g0_(charset-from-attributes294last-command-char)))(keyboard-change-local-map-for-iso))(defunkeyboard-designate-94n-GR()(interactive)(setq_current-g1_(charset-from-attributes294last-command-char)))(defunkeyboard-designate-96n-GL()(interactive)(setq_current-g0_(charset-from-attributes296last-command-char))(keyboard-change-local-map-for-iso))(defunkeyboard-designate-96n-GR()(interactive)(setq_current-g1_(charset-from-attributes296last-command-char)))(defunkeyboard-SS2()(interactive)(setq_keyboard-SS2_t)(setq_saved-local-map-single-shift_(keyboard-current-local-map))(keyboard-change-local-map-for-iso))(defunkeyboard-SS3()(interactive)(setq_keyboard-SS3_t)(setq_saved-local-map-single-shift_(keyboard-current-local-map))(keyboard-change-local-map-for-iso))(defunself-insert-iso()(interactive)(let((charset(cond(_keyboard-SS2__current-g2_)(_keyboard-SS3__current-g3_)((<last-command-char128)_current-g0_)(t_current-g1_))))(if(notcharset)(mule-keyboard-quit))(if(=(charset-dimensioncharset)1)(progn(keyboard-self-insert(make-charcharsetlast-command-char))(if(or_keyboard-SS2__keyboard-SS3_)(keyboard-use-local-map_saved-local-map-single-shift_))(keyboard-reset-state))(if_keyboard-first-byte_(progn(keyboard-self-insert(make-charcharset_keyboard-first-byte_last-command-char))(if(or_keyboard-SS2__keyboard-SS3_)(keyboard-use-local-map_saved-local-map-single-shift_))(keyboard-reset-state))(setq_keyboard-first-byte_last-command-char)))))(defunkeyboard-define-global-map-shift-jis(map)(let((i128))(while(<i160)(keyboard-define-keymapi'self-insert-shift-jis-japanese)(setqi(1+i)))(while(<i224)(keyboard-define-keymapi'self-insert-shift-jis-kana)(setqi(1+i)))(while(<i256)(keyboard-define-keymapi'self-insert-shift-jis-japanese)(setqi(1+i)))))(defunkeyboard-define-local-map-shift-jis(map)(let((i64))(while(<i256)(keyboard-define-keymapi'self-insert-shift-jis-japanese2)(setqi(1+i)))))(defunset-keyboard-coding-system-shift-jis()(keyboard-set-input-mode0); enable 8bit input as chars(keyboard-define-global-map-shift-jisglobal-map)(iflocal-map-shift-jisnil(setqlocal-map-shift-jis(make-keymap))(keyboard-define-local-map-shift-jislocal-map-shift-jis)(define-keylocal-map-shift-jis"\C-g"'mule-keyboard-quit))(setq_keyboard-first-byte_nil)(setqkeyboard-coding-system'shift-jis))(defunself-insert-shift-jis-japanese()(interactive)(setq_keyboard-first-byte_last-command-char)(setq_keyboard-saved-local-map_(keyboard-current-local-map))(keyboard-use-local-map(keyboard-local-map)))(defunself-insert-shift-jis-japanese2()(interactive)(if_keyboard-first-byte_(let((char(decode-shift-jis-char_keyboard-first-byte_last-command-char)))(keyboard-self-insertchar)(setq_keyboard-first-byte_nil)))(keyboard-use-local-map_keyboard-saved-local-map_))(defunself-insert-shift-jis-kana()(interactive)(keyboard-self-insert(make-char'japanese-jisx0201-kanalast-command-char)))(defunkeyboard-define-global-map-big5(map)(let((i?\xA1))(while(<i?\xFE)(keyboard-define-keymapi'self-insert-big5-1)(setqi(1+i)))))(defunkeyboard-define-local-map-big5(map)(let((i?\x40))(while(<i?\x7F)(keyboard-define-keymapi'self-insert-big5-2)(setqi(1+i)))(setqi?\xA1)(while(<i?\xFF)(keyboard-define-keymapi'self-insert-big5-2)(setqi(1+i)))))(defunset-keyboard-coding-system-big5()(require'chinese)(keyboard-set-input-mode0); enable 8bit input as chars(keyboard-define-global-map-big5global-map)(iflocal-map-big5nil(setqlocal-map-big5(make-keymap))(keyboard-define-local-map-big5local-map-big5)(define-keylocal-map-big5"\C-g"'mule-keyboard-quit))(setq_keyboard-first-byte_0)(setqkeyboard-coding-system'big5))(defunself-insert-big5-1()(interactive)(setq_keyboard-first-byte_last-command-char)(setq_keyboard-saved-local-map_(keyboard-current-local-map))(keyboard-use-local-map(keyboard-local-map)))(defunself-insert-big5-2()(interactive)(if_keyboard-first-byte_(progn(keyboard-self-insert(decode-big5-char_keyboard-first-byte_last-command-char'character))(setq_keyboard-first-byte_nil)))(keyboard-use-local-map_keyboard-saved-local-map_))(defuncheck-auto-fill()(if(andauto-fill-function(>(current-column)fill-column))(funcallauto-fill-function)))