25 |
;;; Commentary: |
;;; Commentary: |
26 |
|
|
27 |
;; This file provides tables mapping between Unicode numbers and |
;; This file provides tables mapping between Unicode numbers and |
28 |
;; emacs-mule characters from the iso8859 charsets (and others). It |
;; emacs-mule characters from the iso-8859 charsets (and others). It |
29 |
;; also provides some auxiliary functions. |
;; also provides some auxiliary functions. |
30 |
|
|
31 |
;; These tables are used to construct other mappings between the Mule |
;; These tables are used to construct other mappings between the Mule |
32 |
;; iso8859 charsets and the emacs-unicode charsets and a table that |
;; iso8859 charsets and the emacs-unicode charsets and a table that |
33 |
;; unifies iso8859 characters using a single charset as far as |
;; unifies iso-8859 characters using a single charset as far as |
34 |
;; possible. These tables are used by latin1-disp.el to display some |
;; possible. These tables are used by latin1-disp.el to display some |
35 |
;; Unicode characters without a Unicode font and by utf-8.el to unify |
;; Unicode characters without a Unicode font and by utf-8.el to unify |
36 |
;; Latin-N as far as possible on encoding. |
;; Latin-N as far as possible on encoding. |
44 |
;; not idempotent. |
;; not idempotent. |
45 |
|
|
46 |
;; Global minor modes are provided to unify on encoding and decoding. |
;; Global minor modes are provided to unify on encoding and decoding. |
47 |
|
;; These could be extended to non-iso-8859 charsets. However 8859 is |
48 |
|
;; all that users normally care about unifying although, for instance, |
49 |
|
;; Greek occurs in as many as nine Emacs charsets. |
50 |
|
|
51 |
|
;; The translation-table `utf-translation-table-for-encode' is |
52 |
|
;; populated, which could be used for more general unification on |
53 |
|
;; decoding. This is used by the `mule-utf-8' coding system to encode |
54 |
|
;; extra characters, and also by the coding systems set up by |
55 |
|
;; code-pages.el. The decoding tables here take account of |
56 |
|
;; `utf-fragment-on-decoding' which may specify decoding Greek and |
57 |
|
;; Cyrillic into 8859 charsets. |
58 |
|
|
59 |
|
;; Unification also arranges for `translation-table-for-input' to be |
60 |
|
;; set either globally or locally. This is used to translate input |
61 |
|
;; characters appropriately for the buffer's coding system (if |
62 |
|
;; possible). Unification on decoding sets it globally to translate |
63 |
|
;; to Unicode. Unification on encoding uses hooks to set it up |
64 |
|
;; locally to buffers. Thus in the latter case, typing `"a' into a |
65 |
|
;; Latin-1 buffer using the `latin-2-prefix' method translates the |
66 |
|
;; generated latin-iso8859-2 `,Bd(B' into latin-iso8859-1 `,Ad(B'. |
67 |
|
|
68 |
|
;; NB, this code depends on the default value of |
69 |
|
;; `enable-character-translation'. (Making it nil would anyway lead |
70 |
|
;; to inconsistent behaviour between CCL-based coding systems which |
71 |
|
;; use explicit translation tables and the rest.) |
72 |
|
|
73 |
;; The translation table `ucs-mule-to-mule-unicode' is populated. |
;; Command `ucs-insert' is convenient for inserting a given unicode. |
|
;; This is used by the `mule-utf-8' coding system to encode extra |
|
|
;; characters. |
|
|
|
|
|
;; Command `ucs-insert' is convenient for inserting a given Unicode. |
|
74 |
;; (See also the `ucs' input method.) |
;; (See also the `ucs' input method.) |
75 |
|
|
76 |
;;; Code: |
;;; Code: |
78 |
;;; Define tables, to be populated later. |
;;; Define tables, to be populated later. |
79 |
|
|
80 |
(defvar ucs-mule-8859-to-ucs-table (make-translation-table) |
(defvar ucs-mule-8859-to-ucs-table (make-translation-table) |
81 |
"Translation table from Emacs ISO-8859 characters to Unicode. |
"Char table from Emacs ISO-8859 characters to Unicode. |
82 |
This maps Emacs characters from the non-Latin-1 |
This maps Emacs characters from the non-Latin-1 |
83 |
...-iso8859-... charsets to their Unicode code points. This is a |
...-iso8859-... charsets to their Unicode code points. This is a |
84 |
many-to-one mapping.") |
many-to-one mapping.") |
85 |
|
|
86 |
(defvar ucs-mule-8859-to-mule-unicode (make-translation-table) |
(defvar ucs-mule-8859-to-mule-unicode (make-translation-table) |
87 |
"Translation table from Emacs ISO-8859 characters to Mule Unicode. |
"Char table from Emacs ISO-8859 characters to Mule Unicode. |
88 |
This maps Emacs characters from the non-Latin-1 |
This maps Emacs characters from the non-Latin-1 |
89 |
...-iso8859-... charsets to characters from the |
...-iso8859-... charsets to characters from the |
90 |
mule-unicode-... charsets. This is a many-to-one mapping. The |
mule-unicode-... charsets. This is a many-to-one mapping. The |
146 |
"Used as `translation-table-for-encode' for iso-8859-15. |
"Used as `translation-table-for-encode' for iso-8859-15. |
147 |
Translates from the iso8859 charsets and `mule-unicode-0100-24ff'.") |
Translates from the iso8859 charsets and `mule-unicode-0100-24ff'.") |
148 |
|
|
149 |
;; Probably defined by utf-8.el. |
(setq translation-table-for-input (make-translation-table)) |
150 |
(defvar ucs-mule-to-mule-unicode (make-translation-table)) |
;; It will normally be set locally, before the major mode is invoked. |
151 |
(unless (get 'ucs-mule-to-mule-unicode 'translation-table) |
(put 'translation-table-for-input 'permanent-local t) |
152 |
(define-translation-table 'ucs-mule-to-mule-unicode ucs-mule-to-mule-unicode)) |
|
153 |
|
(define-translation-table 'ucs-translation-table-for-decode) |
154 |
|
|
155 |
;;; Set up the tables. |
;;; Set up the tables. |
156 |
|
|
157 |
;; Most of these tables were derived from ones in Mule-UCS. |
;; Most of these tables were derived from ones in Mule-UCS. |
1090 |
(push (cons (make-char 'latin-iso8859-1 (- i 128)) i) |
(push (cons (make-char 'latin-iso8859-1 (- i 128)) i) |
1091 |
l) |
l) |
1092 |
(setq i (1+ i))) |
(setq i (1+ i))) |
1093 |
(nreverse l))) |
(nreverse l)))) |
1094 |
|
|
1095 |
;; (case-table (standard-case-table)) |
;; Note: Here, using decode-char is safe because |
1096 |
;; (syntax-table (standard-syntax-table)) |
;; utf-fragment-on-decoding is by default nil, thus the translation |
1097 |
) |
;; table `utf-translation-table-for-decode' does nothing. |
1098 |
|
|
1099 |
;; Convert the lists to the basic char tables. |
;; Convert the lists to the basic char tables. |
1100 |
(dolist (n (list 15 14 9 8 7 5 4 3 2 1)) |
(dolist (n (list 15 14 9 8 7 6 5 4 3 2 1)) |
1101 |
(let ((alist (symbol-value (intern (format "ucs-8859-%d-alist" n))))) |
(let ((alist (symbol-value (intern (format "ucs-8859-%d-alist" n))))) |
1102 |
(dolist (pair alist) |
(dolist (pair alist) |
1103 |
(let ((mule (car pair)) |
(let ((mule (car pair)) |
1107 |
;; (aset ucs-ucs-to-mule-8859-table uc mule) |
;; (aset ucs-ucs-to-mule-8859-table uc mule) |
1108 |
;; (aset ucs-mule-unicode-to-mule-8859 mu mule) |
;; (aset ucs-mule-unicode-to-mule-8859 mu mule) |
1109 |
(aset ucs-mule-8859-to-mule-unicode mule mu) |
(aset ucs-mule-8859-to-mule-unicode mule mu) |
1110 |
(aset ucs-mule-to-mule-unicode mule mu))) |
(aset ucs-mule-to-mule-unicode mule mu))))) |
1111 |
;; I think this is actually done OK in characters.el. |
|
|
;; Probably things like accents shouldn't have word syntax, but the |
|
|
;; Latin-N syntax tables currently aren't consistent for such |
|
|
;; characters anyhow. |
|
|
;; ;; Make the mule-unicode characters inherit syntax and case info |
|
|
;; ;; if they don't already have it. |
|
|
;; (dolist (pair alist) |
|
|
;; (let ((mule (car pair)) |
|
|
;; (uc (cdr pair)) |
|
|
;; (mu (decode-char 'ucs (cdr pair)))) |
|
|
;; (let ((syntax (aref syntax-table mule))) |
|
|
;; (if (eq mule (downcase mule)) |
|
|
;; (if (eq mule (upcase mule)) ; non-letter or uncased letter |
|
|
;; (progn |
|
|
;; (if (= 4 (car syntax)) ; left delim |
|
|
;; (progn |
|
|
;; (aset syntax-table |
|
|
;; mu |
|
|
;; (cons 4 (aref ucs-mule-8859-to-mule-unicode |
|
|
;; (cdr syntax)))) |
|
|
;; (aset syntax-table |
|
|
;; (aref ucs-mule-8859-to-mule-unicode |
|
|
;; (cdr syntax)) |
|
|
;; (cons 5 mu))) |
|
|
;; (aset syntax-table mu syntax)) |
|
|
;; (aset case-table mu mu))) |
|
|
;; ;; Upper case letter |
|
|
;; (let ((lower (aref ucs-mule-8859-to-mule-unicode |
|
|
;; (aref case-table mule)))) |
|
|
;; (aset case-table mu lower) |
|
|
;; (aset case-table lower lower) |
|
|
;; (modify-syntax-entry lower "w " syntax-table) |
|
|
;; (modify-syntax-entry mu "w " syntax-table)))))) |
|
|
)) |
|
1112 |
;; Derive tables that can be used as per-coding-system |
;; Derive tables that can be used as per-coding-system |
1113 |
;; `translation-table-for-encode's. |
;; `translation-table-for-encode's. |
1114 |
|
;; N.B., there's no 8859-6 coding system. |
1115 |
(dolist (n (list 15 14 9 8 7 5 4 3 2 1)) |
(dolist (n (list 15 14 9 8 7 5 4 3 2 1)) |
1116 |
(let* ((alist (symbol-value (intern (format "ucs-8859-%d-alist" n)))) |
(let* ((alist (symbol-value (intern (format "ucs-8859-%d-alist" n)))) |
1117 |
(encode-translator (set (intern (format "ucs-8859-%d-encode-table" |
(encode-translator (set (intern (format "ucs-8859-%d-encode-table" |
1118 |
n)) |
n)) |
1119 |
(make-translation-table))) |
(make-translation-table))) |
1120 |
|
(coding-system |
1121 |
|
(coding-system-base (intern (format "iso-8859-%d" n)))) |
1122 |
|
(dependency (coding-system-get coding-system 'dependency)) |
1123 |
elt) |
elt) |
1124 |
;; Start with the mule-unicode component. |
;; Start with the mule-unicode component (except for latin-iso8859-1). |
1125 |
(dolist (pair alist) |
(if (/= n 1) |
1126 |
(let ((mule (car pair)) |
(dolist (pair alist) |
1127 |
(mu (decode-char 'ucs (cdr pair)))) |
(let ((mule (car pair)) |
1128 |
(aset encode-translator mu mule))) |
(mu (decode-char 'ucs (cdr pair)))) |
1129 |
|
(aset encode-translator mu mule)))) |
1130 |
;; Find characters from other 8859 sets which map to the same |
;; Find characters from other 8859 sets which map to the same |
1131 |
;; unicode as some character in this set. |
;; unicode as some character in this set. |
1132 |
(map-char-table (lambda (k v) |
(map-char-table (lambda (k v) |
1133 |
(if (and (setq elt (rassq v alist)) |
(if (and (setq elt (rassq v alist)) |
1134 |
(not (assq k alist))) |
(not (assq k alist))) |
1135 |
(aset encode-translator k (car elt)))) |
(aset encode-translator k (car elt)))) |
1136 |
ucs-mule-8859-to-ucs-table)))) |
ucs-mule-8859-to-ucs-table) |
1137 |
|
(optimize-char-table encode-translator) |
1138 |
|
|
1139 |
|
(or (memq 'unify-8859-on-encoding-mode dependency) |
1140 |
|
(setq dependency (cons 'unify-8859-on-encoding-mode dependency))) |
1141 |
|
(or (memq 'unify-8859-on-decoding-mode dependency) |
1142 |
|
(setq dependency (cons 'unify-8859-on-decoding-mode dependency))) |
1143 |
|
(coding-system-put coding-system 'dependency dependency)))) |
1144 |
|
|
1145 |
;; Register for use in CCL. |
(defun ucs-unify-8859 (for-encode for-decode) |
1146 |
(define-translation-table 'ucs-mule-8859-to-mule-unicode |
"Set up translation-tables for unifying characters from ISO 8859. |
|
ucs-mule-8859-to-mule-unicode) |
|
|
|
|
|
;; Fixme: Make this reversible, which means frobbing |
|
|
;; `char-coding-system-table' directly to remove what we added -- see |
|
|
;; codepages.el. Also make it a user option. |
|
|
(defun ucs-unify-8859 (&optional encode-only) |
|
|
"Set up translation tables for unifying characters from ISO 8859. |
|
1147 |
|
|
1148 |
On decoding, non-ASCII characters are mapped into the `iso-latin-1' |
On decoding, non-ASCII characters are mapped into the `iso-latin-1' |
1149 |
and `mule-unicode-0100-24ff' charsets. On encoding, these are mapped |
and `mule-unicode-0100-24ff' charsets. On encoding, these are mapped |
1151 |
|
|
1152 |
With prefix arg, do unification on encoding only, i.e. don't unify |
With prefix arg, do unification on encoding only, i.e. don't unify |
1153 |
everything on input operations." |
everything on input operations." |
1154 |
(interactive "P") |
(when for-decode |
|
(unless encode-only |
|
1155 |
;; Unify 8859 on decoding. (Non-CCL coding systems only.) |
;; Unify 8859 on decoding. (Non-CCL coding systems only.) |
1156 |
(unify-8859-on-decoding-mode 1)) |
(if utf-fragment-on-decoding |
1157 |
;; Adjust the 8859 coding systems to fragment the unified characters |
(progn (map-char-table |
1158 |
;; on encoding. |
(lambda (k v) |
1159 |
(dolist (n '(1 2 3 4 5 7 8 9 14 15)) |
(if v (aset ucs-mule-8859-to-mule-unicode v nil))) |
1160 |
(let* ((coding-system |
utf-fragmentation-table) |
1161 |
(coding-system-base (intern (format "iso-8859-%d" n)))) |
(optimize-char-table ucs-mule-8859-to-mule-unicode)) |
1162 |
(table (symbol-value |
;; Reset in case it was changed. |
1163 |
(intern (format "ucs-8859-%d-encode-table" n)))) |
(map-char-table |
1164 |
(safe (coding-system-get coding-system 'safe-chars))) |
(lambda (k v) |
1165 |
;; Actually, the coding system's safe-chars are not normally |
(if v (aset ucs-mule-8859-to-mule-unicode v k))) |
1166 |
;; used after they've been registered, but we might as well |
utf-fragmentation-table)) |
1167 |
;; record them. Setting the parent here is a convenience. |
|
1168 |
(set-char-table-parent safe table) |
;; For non-CCL coding systems (e.g. iso-latin-2). |
1169 |
;; Update the table of what encodes to what. |
(set-char-table-parent standard-translation-table-for-decode |
1170 |
(register-char-codings coding-system table) |
ucs-mule-8859-to-mule-unicode) |
1171 |
(coding-system-put coding-system 'translation-table-for-encode table))) |
;; For CCL coding systems other than mule-utf-* |
1172 |
|
(define-translation-table 'ucs-translation-table-for-decode |
1173 |
;;; The following works for the bundled coding systems, but it's |
ucs-mule-8859-to-mule-unicode) |
1174 |
;;; better to use the Unicode-based ones and make it irrelevant. |
|
1175 |
|
;; Translate Quail input globally. |
1176 |
;;; ;; Update the Cyrillic special cases. |
(setq-default translation-table-for-input ucs-mule-to-mule-unicode) |
1177 |
;;; ;; `translation-table-for-encode' doesn't work for CCL coding |
;; In case this is set up, but we should use the global |
1178 |
;;; ;; systems, and `standard-translation-table-for-decode' isn't |
;; translation-table. |
1179 |
;;; ;; applied. |
(remove-hook 'minibuffer-setup-hook 'ucs-minibuffer-setup)) |
1180 |
;;; (let ((table (get 'cyrillic-koi8-r-encode-table 'translation-table))) |
|
1181 |
;;; (map-char-table |
(when for-encode |
1182 |
;;; (lambda (k v) |
;; Make mule-utf-* encode all characters in ucs-mule-to-mule-unicode. |
1183 |
;;; (aset table |
(let ((coding-list '(mule-utf-8 mule-utf-16-be mule-utf-16-le))) |
1184 |
;;; (or (aref ucs-8859-5-encode-table k) |
(define-translation-table 'utf-translation-table-for-encode |
1185 |
;;; k) |
ucs-mule-to-mule-unicode) |
1186 |
;;; v)) |
(dolist (coding coding-list) |
1187 |
;;; table) |
(set-char-table-parent (coding-system-get coding 'safe-chars) |
1188 |
;;; (register-char-codings 'cyrillic-koi8 table)) |
ucs-mule-to-mule-unicode))) |
1189 |
;;; (let ((table (get 'cyrillic-koi8-r-nonascii-translation-table |
|
1190 |
;;; 'translation-table))) |
;; Adjust the 8859 coding systems to fragment the unified characters |
1191 |
;;; (map-char-table |
;; on encoding. |
1192 |
;;; (lambda (k v) |
(dolist (n '(1 2 3 4 5 7 8 9 14 15)) |
1193 |
;;; (if v (aset table k (or (aref ucs-mule-8859-to-mule-unicode v) |
(let* ((coding-system |
1194 |
;;; v)))) |
(coding-system-base (intern (format "iso-8859-%d" n)))) |
1195 |
;;; table)) |
(table (symbol-value |
1196 |
;;; ;; Redefine this, since the orginal only translated 8859-5. |
(intern (format "ucs-8859-%d-encode-table" n)))) |
1197 |
;;; (define-ccl-program ccl-encode-koi8 |
(safe (coding-system-get coding-system 'safe-chars))) |
1198 |
;;; `(1 |
;; Actually, the coding system's safe-chars are not normally |
1199 |
;;; ((loop |
;; used after they've been registered, but we might as well |
1200 |
;;; (read-multibyte-character r0 r1) |
;; record them. Setting the parent here is a convenience. |
1201 |
;;; (translate-character cyrillic-koi8-r-encode-table r0 r1) |
(set-char-table-parent safe table) |
1202 |
;;; (write-repeat r1)))) |
(coding-system-put coding-system 'translation-table-for-encode table))) |
1203 |
;;; "CCL program to encode KOI8.") |
(add-hook 'minibuffer-setup-hook 'ucs-minibuffer-setup))) |
|
;;; (let ((table (get 'cyrillic-alternativnyj-encode-table 'translation-table))) |
|
|
;;; (map-char-table |
|
|
;;; (lambda (k v) |
|
|
;;; (aset table |
|
|
;;; (or (aref ucs-8859-5-encode-table k) |
|
|
;;; k) |
|
|
;;; v)) |
|
|
;;; table) |
|
|
;;; (register-char-codings 'cyrillic-alternativnyj table)) |
|
|
;;; (let ((table (get 'cyrillic-alternativnyj-nonascii-translation-table |
|
|
;;; 'translation-table))) |
|
|
;;; (map-char-table |
|
|
;;; (lambda (k v) |
|
|
;;; (if v (aset table |
|
|
;;; k |
|
|
;;; (or (aref ucs-mule-8859-to-mule-unicode v) |
|
|
;;; v)))) |
|
|
;;; table)) |
|
|
) |
|
1204 |
|
|
1205 |
(defun ucs-fragment-8859 (&optional encode-only) |
(defun ucs-fragment-8859 (for-encode for-decode) |
1206 |
"Undo the unification done by `ucs-unify-8859'. |
"Undo the unification done by `ucs-unify-8859'. |
1207 |
With prefix arg, undo unification on encoding only, i.e. don't undo |
With prefix arg, undo unification on encoding only, i.e. don't undo |
1208 |
unification on input operations." |
unification on input operations." |
1209 |
(interactive "P") |
(when for-decode |
1210 |
;; Maybe fix decoding. |
;; Don't Unify 8859 on decoding. |
1211 |
(unless encode-only |
;; For non-CCL coding systems (e.g. iso-latin-2). |
1212 |
;; Unify 8859 on decoding. (Non-CCL coding systems only.) |
(set-char-table-parent standard-translation-table-for-decode nil) |
1213 |
(unify-8859-on-decoding-mode -1)) |
;; For CCL coding systems other than mule-utf-* (e.g. cyrillic-koi8). |
1214 |
;; Fix encoding. For each charset, remove the entries in |
(define-translation-table 'ucs-translation-table-for-decode) |
1215 |
;; `char-coding-system-table' added to its safe-chars table (as its |
(setq-default translation-table-for-input nil)) |
1216 |
;; parent). |
|
1217 |
(dolist (n '(1 2 3 4 5 7 8 9 14 15)) |
(when for-encode |
1218 |
(let* ((coding-system |
;; Disable mule-utf-* encoding for all characters in |
1219 |
(coding-system-base (intern (format "iso-8859-%d" n)))) |
;; ucs-mule-to-mule-unicode except what was originally supported |
1220 |
(table (symbol-value |
;; and what is translated by utf-translation-table-for-decode when |
1221 |
(intern (format "ucs-8859-%d-encode-table" n)))) |
;; `utf-fragment-on-decoding' is non-nil. |
1222 |
(safe (coding-system-get coding-system 'safe-chars))) |
(let ((coding-list '(mule-utf-8 mule-utf-16-be mule-utf-16-le)) |
1223 |
(map-char-table |
(safe (coding-system-get 'mule-utf-8 'safe-chars))) |
1224 |
(lambda (key val) |
(dolist (coding coding-list) |
1225 |
(if (and (>= key 128) val) |
(set-char-table-parent (coding-system-get coding 'safe-chars) nil)) |
1226 |
(let ((codings (aref char-coding-system-table key))) |
(if (not utf-fragment-on-decoding) |
1227 |
(aset char-coding-system-table key |
(define-translation-table 'utf-translation-table-for-encode) |
1228 |
(delq coding-system codings))))) |
(define-translation-table 'utf-translation-table-for-encode |
1229 |
(char-table-parent safe)) |
utf-defragmentation-table))) |
1230 |
(set-char-table-parent safe nil) |
|
1231 |
(coding-system-put coding-system 'translation-table-for-encode nil)))) |
;; For each charset, remove the parent of `safe-chars' property of |
1232 |
|
;; the corresponding coding system. |
1233 |
(define-minor-mode unify-8859-on-encoding-mode |
(dolist (n '(1 2 3 4 5 7 8 9 14 15)) |
1234 |
"Set up translation tables for unifying ISO 8859 characters on encoding. |
(let* ((coding-system |
1235 |
|
(coding-system-base (intern (format "iso-8859-%d" n)))) |
1236 |
The ISO 8859 characters sets overlap, e.g. 8859-1 (Latin-1) and |
(safe (coding-system-get coding-system 'safe-chars))) |
1237 |
8859-15 (Latin-9) differ only in a few characters. Emacs normally |
(if (char-table-parent safe) |
1238 |
distinguishes equivalent characters from those ISO-8859 character sets |
(set-char-table-parent safe nil)) |
1239 |
which are built in to Emacs. This behaviour is essentially inherited |
(coding-system-put coding-system 'translation-table-for-encode nil))) |
1240 |
from the European-originated international standards. Treating them |
(remove-hook 'minibuffer-setup-hook 'ucs-minibuffer-setup))) |
|
equivalently, by translating to and from a single representation is |
|
|
called `unification'. (The `utf-8' coding system treats the |
|
|
characters of European scripts in a unified manner.) |
|
|
|
|
|
In this mode, on encoding -- i.e. output operations -- non-ASCII |
|
|
characters from the built-in ISO 8859 and `mule-unicode-0100-24ff' |
|
|
charsets are handled automatically by the coding system used if it can |
|
|
represent them. Thus, say, an e-acute from the Latin-1 charset (the |
|
|
unified representation) in a buffer saved as Latin-9 will be encoded |
|
|
directly to a byte value 233. By default, in contrast, you would be |
|
|
prompted for a general coding system to use for saving the file, which |
|
|
can cope with separate Latin-1 and Latin-9 representations of e-acute. |
|
|
|
|
|
See also command `unify-8859-on-decoding-mode'." |
|
|
:group 'mule |
|
|
:global t |
|
|
:version "21.3" ; who knows...? |
|
|
:init-value nil |
|
|
(if unify-8859-on-encoding-mode |
|
|
(ucs-unify-8859 t) |
|
|
(ucs-fragment-8859 t))) |
|
|
|
|
|
(define-minor-mode unify-8859-on-decoding-mode |
|
|
"Set up translation table for unifying ISO 8859 characters on decoding. |
|
|
On decoding -- i.e. input operations -- non-ASCII characters from the |
|
|
built-in ISO 8859 charsets are unified by mapping them into the |
|
|
`iso-latin-1' and `mule-unicode-0100-24ff' charsets. |
|
|
|
|
|
This sets the parent of `standard-translation-table-for-decode'. |
|
|
Also sets `translation-table-for-input' globally, so that Quail input |
|
|
methods produce unified characters. |
|
|
|
|
|
See also command `unify-8859-on-encoding-mode'." |
|
|
:group 'mule |
|
|
:global t |
|
|
:version "21.3" ; who knows...? |
|
|
:init-value nil |
|
|
(let ((table (if unify-8859-on-decoding-mode ucs-mule-8859-to-mule-unicode))) |
|
|
(set-char-table-parent standard-translation-table-for-decode table) |
|
|
(setq-default translation-table-for-input table))) |
|
1241 |
|
|
1242 |
(defun ucs-insert (arg) |
(defun ucs-insert (arg) |
1243 |
"Insert the Emacs character representation of the given Unicode. |
"Insert the Emacs character representation of the given Unicode. |
1244 |
Interactively, prompts for a hex string giving the code." |
Interactively, prompts for a hex string giving the code." |
1245 |
(interactive "sUnicode (hex): ") |
(interactive "sUnicode (hex): ") |
1246 |
(insert (or (decode-char 'ucs (if (integerp arg) |
(let ((c (decode-char 'ucs (if (integerp arg) |
1247 |
arg |
arg |
1248 |
(string-to-number arg 16))) |
(string-to-number arg 16))))) |
1249 |
(error "Unknown Unicode character")))) |
(if c |
1250 |
|
(insert c) |
1251 |
|
(error "Character can't be decoded to UCS")))) |
1252 |
|
|
1253 |
;;; Dealing with non-8859 character sets. |
;;; Dealing with non-8859 character sets. |
1254 |
|
|
2379 |
(?(1x(B . ?$,1Dx(B) |
(?(1x(B . ?$,1Dx(B) |
2380 |
(?(1y(B . ?$,1Dy(B) |
(?(1y(B . ?$,1Dy(B) |
2381 |
(?(1|(B . ?$,1D|(B) |
(?(1|(B . ?$,1D|(B) |
2382 |
(?(1}(B . ?$,1D}(B)))) |
(?(1}(B . ?$,1D}(B))) |
2383 |
|
|
2384 |
|
(other |
2385 |
|
'( |
2386 |
|
;; latin-jisx0201 is mostly decoded to ascii, with these |
2387 |
|
;; exceptions, so we don't bother with tables for the whole |
2388 |
|
;; thing. |
2389 |
|
(?(J\(B . ?,A%(B) |
2390 |
|
(?(J~(B . ?$,1s>(B)))) |
2391 |
(let ((table (make-char-table 'safe-chars)) |
(let ((table (make-char-table 'safe-chars)) |
2392 |
safe-charsets) |
safe-charsets) |
2393 |
(dolist (cs '(vietnamese-viscii lao chinese-sisheng ipa |
(dolist (cs '(vietnamese-viscii lao chinese-sisheng ipa |
2394 |
katakana-jisx0201 thai-tis620 tibetan-iso-8bit |
katakana-jisx0201 thai-tis620 tibetan-iso-8bit |
2395 |
indian-is13194 ethiopic)) |
indian-is13194 ethiopic other)) |
2396 |
;; These tables could be used as translation-table-for-encode by |
;; These tables could be used as translation-table-for-encode by |
2397 |
;; the relevant coding systems. |
;; the relevant coding systems. |
2398 |
(let ((encode-translator |
(let ((encode-translator |
2403 |
(aset ucs-mule-to-mule-unicode (car pair) (cdr pair)) |
(aset ucs-mule-to-mule-unicode (car pair) (cdr pair)) |
2404 |
(if encode-translator |
(if encode-translator |
2405 |
(aset encode-translator (cdr pair) (car pair)))) |
(aset encode-translator (cdr pair) (car pair)))) |
2406 |
|
(if encode-translator |
2407 |
|
(optimize-char-table encode-translator)) |
2408 |
(if (charsetp cs) |
(if (charsetp cs) |
2409 |
(push cs safe-charsets) |
(push cs safe-charsets) |
2410 |
(setq safe-charsets |
(if (coding-system-p cs) |
2411 |
(append (delq 'ascii (coding-system-get cs 'safe-charsets)) |
(setq safe-charsets |
2412 |
safe-charsets))))) |
(append (delq 'ascii (coding-system-get cs 'safe-charsets)) |
2413 |
|
safe-charsets)))) |
2414 |
|
(cond ((eq cs 'vietnamese-viscii) |
2415 |
|
(coding-system-put 'vietnamese-viscii |
2416 |
|
'translation-table-for-input |
2417 |
|
encode-translator) |
2418 |
|
(coding-system-put 'vietnamese-viqr |
2419 |
|
'translation-table-for-input |
2420 |
|
encode-translator)) |
2421 |
|
((memq cs '(lao thai-tis620 tibetan-iso-8bit)) |
2422 |
|
(coding-system-put cs 'translation-table-for-input |
2423 |
|
encode-translator))))) |
2424 |
(dolist (c safe-charsets) |
(dolist (c safe-charsets) |
2425 |
(aset table (make-char c) t)) |
(aset table (make-char c) t)))) |
2426 |
(coding-system-put 'mule-utf-8 'safe-charsets |
|
2427 |
(append (coding-system-get 'mule-utf-8 'safe-charsets) |
(define-minor-mode unify-8859-on-encoding-mode |
2428 |
safe-charsets)) |
"Set up translation-tables for unifying ISO 8859 characters on encoding. |
2429 |
(register-char-codings 'mule-utf-8 table))) |
|
2430 |
|
The ISO 8859 characters sets overlap, e.g. 8859-1 (Latin-1) and |
2431 |
|
8859-15 (Latin-9) differ only in a few characters. Emacs normally |
2432 |
|
distinguishes equivalent characters from those ISO-8859 character sets |
2433 |
|
which are built in to Emacs. This behaviour is essentially inherited |
2434 |
|
from the European-originated international standards. Treating them |
2435 |
|
equivalently, by translating to and from a single representation is |
2436 |
|
called `unification'. (The `utf-8' coding system treats the |
2437 |
|
characters of European scripts in a unified manner.) |
2438 |
|
|
2439 |
|
In this mode, on encoding -- i.e. output operations -- non-ASCII |
2440 |
|
characters from the built-in ISO 8859 and `mule-unicode-0100-24ff' |
2441 |
|
charsets are handled automatically by the coding system used if it can |
2442 |
|
represent them. Thus, say, an e-acute from the Latin-1 charset (the |
2443 |
|
unified representation) in a buffer saved as Latin-9 will be encoded |
2444 |
|
directly to a byte value 233. By default, in contrast, you would be |
2445 |
|
prompted for a general coding system to use for saving the file, which |
2446 |
|
can cope with separate Latin-1 and Latin-9 representations of e-acute. |
2447 |
|
|
2448 |
|
Also sets hooks that arrange `translation-table-for-input' to be set |
2449 |
|
up locally. This will often allow input generated by Quail input |
2450 |
|
methods to conform with what the buffer's file coding system can |
2451 |
|
encode. Thus you could use a Latin-2 input method to search for |
2452 |
|
e-acute in a Latin-1 buffer. |
2453 |
|
|
2454 |
|
See also command `unify-8859-on-decoding-mode'." |
2455 |
|
:group 'mule |
2456 |
|
:global t |
2457 |
|
:init-value t |
2458 |
|
(if unify-8859-on-encoding-mode |
2459 |
|
(ucs-unify-8859 t nil) |
2460 |
|
(ucs-fragment-8859 t nil))) |
2461 |
|
|
2462 |
|
(custom-add-version 'unify-8859-on-encoding-mode "21.3") |
2463 |
|
|
2464 |
|
(define-minor-mode unify-8859-on-decoding-mode |
2465 |
|
"Set up translation-tables for unifying ISO 8859 characters on decoding. |
2466 |
|
On decoding, i.e. input operations, non-ASCII characters from the |
2467 |
|
built-in ISO 8859 charsets are unified by mapping them into the |
2468 |
|
`iso-latin-1' and `mule-unicode-0100-24ff' charsets. |
2469 |
|
|
2470 |
|
Also sets `translation-table-for-input' globally, so that keyboard input |
2471 |
|
produces unified characters. |
2472 |
|
|
2473 |
|
See also command `unify-8859-on-encoding-mode' and the user option |
2474 |
|
`utf-fragment-on-decoding'." |
2475 |
|
:group 'mule |
2476 |
|
:global t |
2477 |
|
:init-value nil |
2478 |
|
(if unify-8859-on-decoding-mode |
2479 |
|
(ucs-unify-8859 nil t) |
2480 |
|
(ucs-fragment-8859 nil t))) |
2481 |
|
|
2482 |
|
(custom-add-version 'unify-8859-on-decoding-mode "21.3") |
2483 |
|
|
2484 |
|
;; Synchronize the status with the initial value of |
2485 |
|
;; unify-8859-on-encoding-mode and unify-8859-on-decoding-mode. |
2486 |
|
(ucs-unify-8859 t nil) |
2487 |
|
|
2488 |
|
;; Arrange to set up the translation-table for keyboard input. This |
2489 |
|
;; is called from get-buffer-create, set-buffer-file-coding-system, |
2490 |
|
;; normal-mode and minibuffer-setup-hook. |
2491 |
|
(defun ucs-set-table-for-input (&optional buffer) |
2492 |
|
"Set up an appropriate `translation-table-for-input' for BUFFER. |
2493 |
|
BUFFER defaults to the current buffer." |
2494 |
|
(when (and unify-8859-on-encoding-mode |
2495 |
|
(char-table-p translation-table-for-input)) |
2496 |
|
(let ((cs (and buffer-file-coding-system |
2497 |
|
(coding-system-base buffer-file-coding-system))) |
2498 |
|
table) |
2499 |
|
(if (or (null cs) |
2500 |
|
(eq cs 'undecided)) |
2501 |
|
(setq cs |
2502 |
|
(and default-buffer-file-coding-system |
2503 |
|
(coding-system-base default-buffer-file-coding-system)))) |
2504 |
|
(when cs |
2505 |
|
(setq table (coding-system-get cs 'translation-table-for-encode)) |
2506 |
|
(unless (char-table-p table) |
2507 |
|
(setq table (coding-system-get cs 'translation-table-for-input))) |
2508 |
|
(when (char-table-p table) |
2509 |
|
(if buffer |
2510 |
|
(with-current-buffer buffer |
2511 |
|
(set (make-variable-buffer-local 'translation-table-for-input) |
2512 |
|
table)) |
2513 |
|
(set (make-variable-buffer-local 'translation-table-for-input) |
2514 |
|
table))))))) |
2515 |
|
|
2516 |
|
;; The minibuffer needs to acquire a `buffer-file-coding-system' for |
2517 |
|
;; the above to work in it. |
2518 |
|
(defun ucs-minibuffer-setup () |
2519 |
|
"Set up an appropriate `buffer-file-coding-system' for current buffer. |
2520 |
|
Intended to be added to `minibuffer-setup-hook'." |
2521 |
|
(set (make-local-variable 'buffer-file-coding-system) |
2522 |
|
(with-current-buffer (let ((win (minibuffer-selected-window))) |
2523 |
|
(if (window-live-p win) (window-buffer win) |
2524 |
|
(cadr (buffer-list)))) |
2525 |
|
buffer-file-coding-system)) |
2526 |
|
(ucs-set-table-for-input)) |
2527 |
|
|
2528 |
(provide 'ucs-tables) |
(provide 'ucs-tables) |
2529 |
|
|