| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
(require 'help-fns) |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
(defun print-list (&rest args) |
|---|
| 40 |
(while (cdr args) |
|---|
| 41 |
(when (car args) |
|---|
| 42 |
(princ (car args)) |
|---|
| 43 |
(princ " ")) |
|---|
| 44 |
(setq args (cdr args))) |
|---|
| 45 |
(princ (car args)) |
|---|
| 46 |
(princ "\n")) |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
(defun sort-charset-list () |
|---|
| 50 |
(setq charset-list |
|---|
| 51 |
(sort charset-list |
|---|
| 52 |
(lambda (x y) (< (charset-id x) (charset-id y)))))) |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
(define-button-type 'sort-listed-character-sets |
|---|
| 57 |
'help-echo (purecopy "mouse-2, RET: sort on this column") |
|---|
| 58 |
'face 'bold |
|---|
| 59 |
'action #'(lambda (button) |
|---|
| 60 |
(sort-listed-character-sets (button-get button 'sort-key)))) |
|---|
| 61 |
|
|---|
| 62 |
(define-button-type 'list-charset-chars |
|---|
| 63 |
:supertype 'help-xref |
|---|
| 64 |
'help-function #'list-charset-chars |
|---|
| 65 |
'help-echo "mouse-2, RET: show table of characters for this character set") |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
(defvar non-iso-charset-alist |
|---|
| 69 |
`((mac-roman |
|---|
| 70 |
(ascii latin-iso8859-1 mule-unicode-2500-33ff |
|---|
| 71 |
mule-unicode-0100-24ff mule-unicode-e000-ffff) |
|---|
| 72 |
mac-roman-decoder |
|---|
| 73 |
((0 255))) |
|---|
| 74 |
(viscii |
|---|
| 75 |
(ascii vietnamese-viscii-lower vietnamese-viscii-upper) |
|---|
| 76 |
viet-viscii-nonascii-translation-table |
|---|
| 77 |
((0 255))) |
|---|
| 78 |
(vietnamese-tcvn |
|---|
| 79 |
(ascii vietnamese-viscii-lower vietnamese-viscii-upper) |
|---|
| 80 |
viet-tcvn-nonascii-translation-table |
|---|
| 81 |
((0 255))) |
|---|
| 82 |
(koi8-r |
|---|
| 83 |
(ascii cyrillic-iso8859-5) |
|---|
| 84 |
cyrillic-koi8-r-nonascii-translation-table |
|---|
| 85 |
((32 255))) |
|---|
| 86 |
(alternativnyj |
|---|
| 87 |
(ascii cyrillic-iso8859-5) |
|---|
| 88 |
cyrillic-alternativnyj-nonascii-translation-table |
|---|
| 89 |
((32 255))) |
|---|
| 90 |
(koi8-u |
|---|
| 91 |
(ascii cyrillic-iso8859-5 mule-unicode-0100-24ff) |
|---|
| 92 |
cyrillic-koi8-u-nonascii-translation-table |
|---|
| 93 |
((32 255))) |
|---|
| 94 |
(big5 |
|---|
| 95 |
(ascii chinese-big5-1 chinese-big5-2) |
|---|
| 96 |
decode-big5-char |
|---|
| 97 |
((32 127) |
|---|
| 98 |
((?\xA1 ?\xFE) . (?\x40 ?\x7E ?\xA1 ?\xFE)))) |
|---|
| 99 |
(sjis |
|---|
| 100 |
(ascii katakana-jisx0201 japanese-jisx0208) |
|---|
| 101 |
decode-sjis-char |
|---|
| 102 |
((32 127 ?\xA1 ?\xDF) |
|---|
| 103 |
((?\x81 ?\x9F ?\xE0 ?\xEF) . (?\x40 ?\x7E ?\x80 ?\xFC))))) |
|---|
| 104 |
"Alist of charset names vs the corresponding information. |
|---|
| 105 |
This is mis-named for historical reasons. The charsets are actually |
|---|
| 106 |
non-built-in ones. They correspond to Emacs coding systems, not Emacs |
|---|
| 107 |
charsets, i.e. what Emacs can read (or write) by mapping to (or |
|---|
| 108 |
from) Emacs internal charsets that typically correspond to a limited |
|---|
| 109 |
set of ISO charsets. |
|---|
| 110 |
|
|---|
| 111 |
Each element has the following format: |
|---|
| 112 |
(CHARSET CHARSET-LIST TRANSLATION-METHOD [ CODE-RANGE ]) |
|---|
| 113 |
|
|---|
| 114 |
CHARSET is the name (symbol) of the charset. |
|---|
| 115 |
|
|---|
| 116 |
CHARSET-LIST is a list of Emacs charsets into which characters of |
|---|
| 117 |
CHARSET are mapped. |
|---|
| 118 |
|
|---|
| 119 |
TRANSLATION-METHOD is a translation table (symbol) to translate a |
|---|
| 120 |
character code of CHARSET to the corresponding Emacs character |
|---|
| 121 |
code. It can also be a function to call with one argument, a |
|---|
| 122 |
character code in CHARSET. |
|---|
| 123 |
|
|---|
| 124 |
CODE-RANGE specifies the valid code ranges of CHARSET. |
|---|
| 125 |
It is a list of RANGEs, where each RANGE is of the form: |
|---|
| 126 |
(FROM1 TO1 FROM2 TO2 ...) |
|---|
| 127 |
or |
|---|
| 128 |
((FROM1-1 TO1-1 FROM1-2 TO1-2 ...) . (FROM2-1 TO2-1 FROM2-2 TO2-2 ...)) |
|---|
| 129 |
In the first form, valid codes are between FROM1 and TO1, or FROM2 and |
|---|
| 130 |
TO2, or... |
|---|
| 131 |
The second form is used for 2-byte codes. The car part is the ranges |
|---|
| 132 |
of the first byte, and the cdr part is the ranges of the second byte.") |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
(defun list-character-sets (arg) |
|---|
| 136 |
"Display a list of all character sets. |
|---|
| 137 |
|
|---|
| 138 |
The ID-NUM column contains a charset identification number for |
|---|
| 139 |
internal Emacs use. |
|---|
| 140 |
|
|---|
| 141 |
The MULTIBYTE-FORM column contains the format of the buffer and string |
|---|
| 142 |
multibyte sequence of characters in the charset using one to four |
|---|
| 143 |
hexadecimal digits. |
|---|
| 144 |
`xx' stands for any byte in the range 0..127. |
|---|
| 145 |
`XX' stands for any byte in the range 160..255. |
|---|
| 146 |
|
|---|
| 147 |
The D column contains the dimension of this character set. The CH |
|---|
| 148 |
column contains the number of characters in a block of this character |
|---|
| 149 |
set. The FINAL-CHAR column contains an ISO-2022 <final-char> to use |
|---|
| 150 |
for designating this character set in ISO-2022-based coding systems. |
|---|
| 151 |
|
|---|
| 152 |
With prefix arg, the output format gets more cryptic, |
|---|
| 153 |
but still shows the full information." |
|---|
| 154 |
(interactive "P") |
|---|
| 155 |
(help-setup-xref (list #'list-character-sets arg) (interactive-p)) |
|---|
| 156 |
(with-output-to-temp-buffer "*Character Set List*" |
|---|
| 157 |
(with-current-buffer standard-output |
|---|
| 158 |
(if arg |
|---|
| 159 |
(list-character-sets-2) |
|---|
| 160 |
|
|---|
| 161 |
(insert "Indirectly supported character sets are shown below.\n") |
|---|
| 162 |
(insert |
|---|
| 163 |
(substitute-command-keys |
|---|
| 164 |
(concat "Use " |
|---|
| 165 |
(if (display-mouse-p) "\\[help-follow-mouse] or ") |
|---|
| 166 |
"\\[help-follow]:\n"))) |
|---|
| 167 |
(insert " on a column title to sort by that title,") |
|---|
| 168 |
(indent-to 56) |
|---|
| 169 |
(insert "+----DIMENSION\n") |
|---|
| 170 |
(insert " on a charset name to list characters.") |
|---|
| 171 |
(indent-to 56) |
|---|
| 172 |
(insert "| +--CHARS\n") |
|---|
| 173 |
(let ((columns '(("ID-NUM" . id) "\t" |
|---|
| 174 |
("CHARSET-NAME" . name) "\t\t\t" |
|---|
| 175 |
("MULTIBYTE-FORM" . id) "\t" |
|---|
| 176 |
("D CH FINAL-CHAR" . iso-spec))) |
|---|
| 177 |
pos) |
|---|
| 178 |
(while columns |
|---|
| 179 |
(if (stringp (car columns)) |
|---|
| 180 |
(insert (car columns)) |
|---|
| 181 |
(insert-text-button (car (car columns)) |
|---|
| 182 |
:type 'sort-listed-character-sets |
|---|
| 183 |
'sort-key (cdr (car columns))) |
|---|
| 184 |
(goto-char (point-max))) |
|---|
| 185 |
(setq columns (cdr columns))) |
|---|
| 186 |
(insert "\n")) |
|---|
| 187 |
(insert "------\t------------\t\t\t--------------\t- -- ----------\n") |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
(list-character-sets-1 'id) |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
(insert-char ?- 72) |
|---|
| 194 |
(insert "\n\nINDIRECTLY SUPPORTED CHARSETS SETS:\n\n" |
|---|
| 195 |
(propertize "CHARSET NAME\tMAPPED TO" 'face 'bold) |
|---|
| 196 |
"\n------------\t---------\n") |
|---|
| 197 |
(dolist (elt non-iso-charset-alist) |
|---|
| 198 |
(insert-text-button (symbol-name (car elt)) |
|---|
| 199 |
:type 'list-charset-chars |
|---|
| 200 |
'help-args (list (car elt))) |
|---|
| 201 |
(indent-to 16) |
|---|
| 202 |
(dolist (e (nth 1 elt)) |
|---|
| 203 |
(when (>= (+ (current-column) 1 (string-width (symbol-name e))) |
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
78) |
|---|
| 207 |
(insert "\n") |
|---|
| 208 |
(indent-to 16)) |
|---|
| 209 |
|
|---|
| 210 |
(insert (format "%s " e))) |
|---|
| 211 |
(insert "\n")))))) |
|---|
| 212 |
|
|---|
| 213 |
(defun sort-listed-character-sets (sort-key) |
|---|
| 214 |
(if sort-key |
|---|
| 215 |
(save-excursion |
|---|
| 216 |
(help-setup-xref (list #'list-character-sets nil) t) |
|---|
| 217 |
(let ((buffer-read-only nil)) |
|---|
| 218 |
(goto-char (point-min)) |
|---|
| 219 |
(re-search-forward "[0-9][0-9][0-9]") |
|---|
| 220 |
(beginning-of-line) |
|---|
| 221 |
(let ((pos (point))) |
|---|
| 222 |
(search-forward "----------") |
|---|
| 223 |
(beginning-of-line) |
|---|
| 224 |
(save-restriction |
|---|
| 225 |
(narrow-to-region pos (point)) |
|---|
| 226 |
(delete-region (point-min) (point-max)) |
|---|
| 227 |
(list-character-sets-1 sort-key))))))) |
|---|
| 228 |
|
|---|
| 229 |
(defun charset-multibyte-form-string (charset) |
|---|
| 230 |
(let ((info (charset-info charset))) |
|---|
| 231 |
(cond ((eq charset 'ascii) |
|---|
| 232 |
"xx") |
|---|
| 233 |
((eq charset 'eight-bit-control) |
|---|
| 234 |
(format "%2X Xx" (aref info 6))) |
|---|
| 235 |
((eq charset 'eight-bit-graphic) |
|---|
| 236 |
"XX") |
|---|
| 237 |
(t |
|---|
| 238 |
(let ((str (format "%2X" (aref info 6)))) |
|---|
| 239 |
(if (> (aref info 7) 0) |
|---|
| 240 |
(setq str (format "%s %2X" |
|---|
| 241 |
str (aref info 7)))) |
|---|
| 242 |
(setq str (concat str " XX")) |
|---|
| 243 |
(if (> (aref info 2) 1) |
|---|
| 244 |
(setq str (concat str " XX"))) |
|---|
| 245 |
str))))) |
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
(defun list-character-sets-1 (sort-key) |
|---|
| 252 |
(or sort-key |
|---|
| 253 |
(setq sort-key 'id)) |
|---|
| 254 |
(let ((tail (charset-list)) |
|---|
| 255 |
charset-info-list elt charset info sort-func) |
|---|
| 256 |
(while tail |
|---|
| 257 |
(setq charset (car tail) tail (cdr tail) |
|---|
| 258 |
info (charset-info charset)) |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
(setq charset-info-list |
|---|
| 262 |
(cons (list (charset-id charset) |
|---|
| 263 |
charset |
|---|
| 264 |
(charset-multibyte-form-string charset) |
|---|
| 265 |
(aref info 2) |
|---|
| 266 |
(aref info 3) |
|---|
| 267 |
(aref info 8) |
|---|
| 268 |
) |
|---|
| 269 |
charset-info-list))) |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
(setq sort-func |
|---|
| 273 |
(cond ((eq sort-key 'id) |
|---|
| 274 |
(lambda (x y) (< (car x) (car y)))) |
|---|
| 275 |
|
|---|
| 276 |
((eq sort-key 'name) |
|---|
| 277 |
(lambda (x y) (string< (nth 1 x) (nth 1 y)))) |
|---|
| 278 |
|
|---|
| 279 |
((eq sort-key 'iso-spec) |
|---|
| 280 |
|
|---|
| 281 |
(lambda (x y) |
|---|
| 282 |
(or (< (nth 3 x) (nth 3 y)) |
|---|
| 283 |
(and (= (nth 3 x) (nth 3 y)) |
|---|
| 284 |
(or (< (nth 4 x) (nth 4 y)) |
|---|
| 285 |
(and (= (nth 4 x) (nth 4 y)) |
|---|
| 286 |
(< (nth 5 x) (nth 5 y)))))))) |
|---|
| 287 |
(t |
|---|
| 288 |
(error "Invalid charset sort key: %s" sort-key)))) |
|---|
| 289 |
|
|---|
| 290 |
(setq charset-info-list (sort charset-info-list sort-func)) |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
(while charset-info-list |
|---|
| 294 |
(setq elt (car charset-info-list) |
|---|
| 295 |
charset-info-list (cdr charset-info-list)) |
|---|
| 296 |
(insert (format "%03d(%02X)" (car elt) (car elt))) |
|---|
| 297 |
(indent-to 8) |
|---|
| 298 |
(insert-text-button (symbol-name (nth 1 elt)) |
|---|
| 299 |
:type 'list-charset-chars |
|---|
| 300 |
'help-args (list (nth 1 elt))) |
|---|
| 301 |
(goto-char (point-max)) |
|---|
| 302 |
(insert "\t") |
|---|
| 303 |
(indent-to 40) |
|---|
| 304 |
(insert (nth 2 elt)) |
|---|
| 305 |
(indent-to 56) |
|---|
| 306 |
(insert (format "%d %2d " (nth 3 elt) (nth 4 elt)) |
|---|
| 307 |
(if (< (nth 5 elt) 0) "none" (nth 5 elt))) |
|---|
| 308 |
(insert "\n")))) |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
(defun list-character-sets-2 () |
|---|
| 314 |
(insert "######################### |
|---|
| 315 |
## LIST OF CHARSETS |
|---|
| 316 |
## Each line corresponds to one charset. |
|---|
| 317 |
## The following attributes are listed in this order |
|---|
| 318 |
## separated by a colon `:' in one line. |
|---|
| 319 |
## CHARSET-ID, |
|---|
| 320 |
## CHARSET-SYMBOL-NAME, |
|---|
| 321 |
## DIMENSION (1 or 2) |
|---|
| 322 |
## CHARS (94 or 96) |
|---|
| 323 |
## BYTES (of multibyte form: 1, 2, 3, or 4), |
|---|
| 324 |
## WIDTH (occupied column numbers: 1 or 2), |
|---|
| 325 |
## DIRECTION (0:left-to-right, 1:right-to-left), |
|---|
| 326 |
## ISO-FINAL-CHAR (character code of ISO-2022's final character) |
|---|
| 327 |
## ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR) |
|---|
| 328 |
## DESCRIPTION (describing string of the charset) |
|---|
| 329 |
") |
|---|
| 330 |
(let ((l charset-list) |
|---|
| 331 |
charset) |
|---|
| 332 |
(while l |
|---|
| 333 |
(setq charset (car l) l (cdr l)) |
|---|
| 334 |
(princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n" |
|---|
| 335 |
(charset-id charset) |
|---|
| 336 |
charset |
|---|
| 337 |
(charset-dimension charset) |
|---|
| 338 |
(charset-chars charset) |
|---|
| 339 |
(charset-bytes charset) |
|---|
| 340 |
(charset-width charset) |
|---|
| 341 |
(charset-direction charset) |
|---|
| 342 |
(charset-iso-final-char charset) |
|---|
| 343 |
(charset-iso-graphic-plane charset) |
|---|
| 344 |
(charset-description charset)))))) |
|---|
| 345 |
|
|---|
| 346 |
(defun decode-codepage-char (codepage code) |
|---|
| 347 |
"Decode a character that has code CODE in CODEPAGE. |
|---|
| 348 |
Return a decoded character string. Each CODEPAGE corresponds to a |
|---|
| 349 |
coding system cpCODEPAGE." |
|---|
| 350 |
(let ((coding-system (intern (format "cp%d" codepage)))) |
|---|
| 351 |
(or (coding-system-p coding-system) |
|---|
| 352 |
(codepage-setup codepage)) |
|---|
| 353 |
(string-to-char |
|---|
| 354 |
(decode-coding-string (char-to-string code) coding-system)))) |
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
(defvar charset-history nil) |
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
|
|---|
| 361 |
(defun read-charset (prompt &optional default-value initial-input) |
|---|
| 362 |
"Read a character set from the minibuffer, prompting with string PROMPT. |
|---|
| 363 |
It must be an Emacs character set listed in the variable `charset-list' |
|---|
| 364 |
or a non-ISO character set listed in the variable |
|---|
| 365 |
`non-iso-charset-alist'. |
|---|
| 366 |
|
|---|
| 367 |
Optional arguments are DEFAULT-VALUE and INITIAL-INPUT. |
|---|
| 368 |
DEFAULT-VALUE, if non-nil, is the default value. |
|---|
| 369 |
INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially. |
|---|
| 370 |
See the documentation of the function `completing-read' for the |
|---|
| 371 |
detailed meanings of these arguments." |
|---|
| 372 |
(let* ((table (append (mapcar (lambda (x) (list (symbol-name x))) |
|---|
| 373 |
charset-list) |
|---|
| 374 |
(mapcar (lambda (x) (list (symbol-name (car x)))) |
|---|
| 375 |
non-iso-charset-alist))) |
|---|
| 376 |
(charset (completing-read prompt table |
|---|
| 377 |
nil t initial-input 'charset-history |
|---|
| 378 |
default-value))) |
|---|
| 379 |
(if (> (length charset) 0) |
|---|
| 380 |
(intern charset)))) |
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
(defun list-block-of-chars (charset row min max) |
|---|
| 392 |
(let (i ch) |
|---|
| 393 |
(insert-char ?- (+ 4 (* 3 16))) |
|---|
| 394 |
(insert "\n ") |
|---|
| 395 |
(setq i 0) |
|---|
| 396 |
(while (< i 16) |
|---|
| 397 |
(insert (format "%3X" i)) |
|---|
| 398 |
(setq i (1+ i))) |
|---|
| 399 |
(setq i (* (/ min 16) 16)) |
|---|
| 400 |
(while (<= i max) |
|---|
| 401 |
(if (= (% i 16) 0) |
|---|
| 402 |
(insert (format "\n%3Xx" (/ (+ (* row 256) i) 16)))) |
|---|
| 403 |
(setq ch (cond ((< i min) |
|---|
| 404 |
32) |
|---|
| 405 |
((charsetp charset) |
|---|
| 406 |
(if (= row 0) |
|---|
| 407 |
(make-char charset i) |
|---|
| 408 |
(make-char charset row i))) |
|---|
| 409 |
((and (symbolp charset) (get charset 'translation-table)) |
|---|
| 410 |
(aref (get charset 'translation-table) i)) |
|---|
| 411 |
(t (funcall charset (+ (* row 256) i))))) |
|---|
| 412 |
(if (and (char-table-p charset) |
|---|
| 413 |
(or (< ch 32) (and (>= ch 127) (<= ch 255)))) |
|---|
| 414 |
|
|---|
| 415 |
(setq ch 32)) |
|---|
| 416 |
(unless ch (setq ch 32)) |
|---|
| 417 |
(if (eq ch ?\t) |
|---|
| 418 |
|
|---|
| 419 |
(setq ch (propertize "\t" 'display "^I"))) |
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 |
(indent-to (+ (* (% i 16) 3) 6)) |
|---|
| 425 |
(insert ch) |
|---|
| 426 |
(setq i (1+ i)))) |
|---|
| 427 |
(insert "\n")) |
|---|
| 428 |
|
|---|
| 429 |
(defun list-iso-charset-chars (charset) |
|---|
| 430 |
(let ((dim (charset-dimension charset)) |
|---|
| 431 |
(chars (charset-chars charset)) |
|---|
| 432 |
(plane (charset-iso-graphic-plane charset)) |
|---|
| 433 |
min max) |
|---|
| 434 |
(insert (format "Characters in the coded character set %s.\n" charset)) |
|---|
| 435 |
|
|---|
| 436 |
(cond ((eq charset 'eight-bit-control) |
|---|
| 437 |
(setq min 128 max 159)) |
|---|
| 438 |
((eq charset 'eight-bit-graphic) |
|---|
| 439 |
(setq min 160 max 255)) |
|---|
| 440 |
(t |
|---|
| 441 |
(if (= chars 94) |
|---|
| 442 |
(setq min 33 max 126) |
|---|
| 443 |
(setq min 32 max 127)) |
|---|
| 444 |
(or (= plane 0) |
|---|
| 445 |
(setq min (+ min 128) max (+ max 128))))) |
|---|
| 446 |
|
|---|
| 447 |
(if (= dim 1) |
|---|
| 448 |
(list-block-of-chars charset 0 min max) |
|---|
| 449 |
(let ((i min)) |
|---|
| 450 |
(while (<= i max) |
|---|
| 451 |
(list-block-of-chars charset i min max) |
|---|
| 452 |
(setq i (1+ i))))))) |
|---|
| 453 |
|
|---|
| 454 |
(defun list-non-iso-charset-chars (charset) |
|---|
| 455 |
"List all characters in non-built-in coded character set CHARSET." |
|---|
| 456 |
(let* ((slot (assq charset non-iso-charset-alist)) |
|---|
| 457 |
(charsets (nth 1 slot)) |
|---|
| 458 |
(translate-method (nth 2 slot)) |
|---|
| 459 |
(ranges (nth 3 slot)) |
|---|
| 460 |
range) |
|---|
| 461 |
(or slot |
|---|
| 462 |
(error "Unknown character set: %s" charset)) |
|---|
| 463 |
(insert (format "Characters in the coded character set %s.\n" charset)) |
|---|
| 464 |
(if charsets |
|---|
| 465 |
(insert "They are mapped to: " |
|---|
| 466 |
(mapconcat #'symbol-name charsets ", ") |
|---|
| 467 |
"\n")) |
|---|
| 468 |
(while ranges |
|---|
| 469 |
(setq range (pop ranges)) |
|---|
| 470 |
(if (integerp (car range)) |
|---|
| 471 |
|
|---|
| 472 |
(if (and (not (functionp translate-method)) |
|---|
| 473 |
(< (car (last range)) 256)) |
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
(list-block-of-chars translate-method |
|---|
| 479 |
0 (car range) (car (last range))) |
|---|
| 480 |
(while range |
|---|
| 481 |
(list-block-of-chars translate-method |
|---|
| 482 |
0 (car range) (nth 1 range)) |
|---|
| 483 |
(setq range (nthcdr 2 range)))) |
|---|
| 484 |
|
|---|
| 485 |
(let ((row-range (car range)) |
|---|
| 486 |
row row-max |
|---|
| 487 |
col-range col col-max) |
|---|
| 488 |
(while row-range |
|---|
| 489 |
(setq row (car row-range) row-max (nth 1 row-range) |
|---|
| 490 |
row-range (nthcdr 2 row-range)) |
|---|
| 491 |
(while (<= row row-max) |
|---|
| 492 |
(setq col-range (cdr range)) |
|---|
| 493 |
(while col-range |
|---|
| 494 |
(setq col (car col-range) col-max (nth 1 col-range) |
|---|
| 495 |
col-range (nthcdr 2 col-range)) |
|---|
| 496 |
(list-block-of-chars translate-method row col col-max)) |
|---|
| 497 |
(setq row (1+ row))))))))) |
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
(defun list-charset-chars (charset) |
|---|
| 502 |
"Display a list of characters in the specified character set. |
|---|
| 503 |
This can list both Emacs `official' (ISO standard) charsets and the |
|---|
| 504 |
characters encoded by various Emacs coding systems which correspond to |
|---|
| 505 |
PC `codepages' and other coded character sets. See `non-iso-charset-alist'." |
|---|
| 506 |
(interactive (list (read-charset "Character set: "))) |
|---|
| 507 |
(with-output-to-temp-buffer "*Character List*" |
|---|
| 508 |
(with-current-buffer standard-output |
|---|
| 509 |
(setq mode-line-format (copy-sequence mode-line-format)) |
|---|
| 510 |
(let ((slot (memq 'mode-line-buffer-identification mode-line-format))) |
|---|
| 511 |
(if slot |
|---|
| 512 |
(setcdr slot |
|---|
| 513 |
(cons (format " (%s)" charset) |
|---|
| 514 |
(cdr slot))))) |
|---|
| 515 |
(setq indent-tabs-mode nil) |
|---|
| 516 |
(set-buffer-multibyte t) |
|---|
| 517 |
(cond ((charsetp charset) |
|---|
| 518 |
(list-iso-charset-chars charset)) |
|---|
| 519 |
((assq charset non-iso-charset-alist) |
|---|
| 520 |
(list-non-iso-charset-chars charset)) |
|---|
| 521 |
(t |
|---|
| 522 |
(error "Invalid character set %s" charset)))))) |
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
(defun describe-character-set (charset) |
|---|
| 527 |
"Display information about built-in character set CHARSET." |
|---|
| 528 |
(interactive (list (let ((non-iso-charset-alist nil)) |
|---|
| 529 |
(read-charset "Charset: ")))) |
|---|
| 530 |
(or (charsetp charset) |
|---|
| 531 |
(error "Invalid charset: %S" charset)) |
|---|
| 532 |
(let ((info (charset-info charset))) |
|---|
| 533 |
(help-setup-xref (list #'describe-character-set charset) (interactive-p)) |
|---|
| 534 |
(with-output-to-temp-buffer (help-buffer) |
|---|
| 535 |
(with-current-buffer standard-output |
|---|
| 536 |
(insert "Character set: " (symbol-name charset) |
|---|
| 537 |
(format " (ID:%d)\n\n" (aref info 0))) |
|---|
| 538 |
(insert (aref info 13) "\n\n") |
|---|
| 539 |
(insert "Number of contained characters: " |
|---|
| 540 |
(if (= (aref info 2) 1) |
|---|
| 541 |
(format "%d\n" (aref info 3)) |
|---|
| 542 |
(format "%dx%d\n" (aref info 3) (aref info 3)))) |
|---|
| 543 |
(insert "Final char of ISO2022 designation sequence: ") |
|---|
| 544 |
(if (>= (aref info 8) 0) |
|---|
| 545 |
(insert (format "`%c'\n" (aref info 8))) |
|---|
| 546 |
(insert "not assigned\n")) |
|---|
| 547 |
(insert (format "Width (how many columns on screen): %d\n" |
|---|
| 548 |
(aref info 4))) |
|---|
| 549 |
(insert (format "Internal multibyte sequence: %s\n" |
|---|
| 550 |
(charset-multibyte-form-string charset))) |
|---|
| 551 |
(let ((coding (plist-get (aref info 14) 'preferred-coding-system))) |
|---|
| 552 |
(when coding |
|---|
| 553 |
(insert (format "Preferred coding system: %s\n" coding)) |
|---|
| 554 |
(search-backward (symbol-name coding)) |
|---|
| 555 |
(help-xref-button 0 'help-coding-system coding))))))) |
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
|
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
(defun print-designation (flags) |
|---|
| 563 |
(let ((graphic-register 0) |
|---|
| 564 |
charset) |
|---|
| 565 |
(while (< graphic-register 4) |
|---|
| 566 |
(setq charset (aref flags graphic-register)) |
|---|
| 567 |
(princ (format |
|---|
| 568 |
" G%d -- %s\n" |
|---|
| 569 |
graphic-register |
|---|
| 570 |
(cond ((null charset) |
|---|
| 571 |
"never used") |
|---|
| 572 |
((eq charset t) |
|---|
| 573 |
"no initial designation, and used by any charsets") |
|---|
| 574 |
((symbolp charset) |
|---|
| 575 |
(format "%s:%s" |
|---|
| 576 |
charset (charset-description charset))) |
|---|
| 577 |
((listp charset) |
|---|
| 578 |
(if (charsetp (car charset)) |
|---|
| 579 |
(format "%s:%s, and also used by the following:" |
|---|
| 580 |
(car charset) |
|---|
| 581 |
(charset-description (car charset))) |
|---|
| 582 |
"no initial designation, and used by the following:")) |
|---|
| 583 |
(t |
|---|
| 584 |
"invalid designation information")))) |
|---|
| 585 |
(when (listp charset) |
|---|
| 586 |
(setq charset (cdr charset)) |
|---|
| 587 |
(while charset |
|---|
| 588 |
(cond ((eq (car charset) t) |
|---|
| 589 |
(princ "\tany other charsets\n")) |
|---|
| 590 |
((charsetp (car charset)) |
|---|
| 591 |
(princ (format "\t%s:%s\n" |
|---|
| 592 |
(car charset) |
|---|
| 593 |
(charset-description (car charset))))) |
|---|
| 594 |
(t |
|---|
| 595 |
"invalid designation information")) |
|---|
| 596 |
(setq charset (cdr charset)))) |
|---|
| 597 |
(setq graphic-register (1+ graphic-register))))) |
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
(defun describe-coding-system (coding-system) |
|---|
| 601 |
"Display information about CODING-SYSTEM." |
|---|
| 602 |
(interactive "zDescribe coding system (default current choices): ") |
|---|
| 603 |
(if (null coding-system) |
|---|
| 604 |
(describe-current-coding-system) |
|---|
| 605 |
(help-setup-xref (list #'describe-coding-system coding-system) |
|---|
| 606 |
(interactive-p)) |
|---|
| 607 |
(with-output-to-temp-buffer (help-buffer) |
|---|
| 608 |
(print-coding-system-briefly coding-system 'doc-string) |
|---|
| 609 |
(princ "\n") |
|---|
| 610 |
(let ((vars (coding-system-get coding-system 'dependency))) |
|---|
| 611 |
(when vars |
|---|
| 612 |
(princ "See also the documentation of these customizable variables |
|---|
| 613 |
which alter the behavior of this coding system.\n") |
|---|
| 614 |
(dolist (v vars) |
|---|
| 615 |
(princ " `") |
|---|
| 616 |
(princ v) |
|---|
| 617 |
(princ "'\n")) |
|---|
| 618 |
(princ "\n"))) |
|---|
| 619 |
|
|---|
| 620 |
(princ "Type: ") |
|---|
| 621 |
(let ((type (coding-system-type coding-system)) |
|---|
| 622 |
(flags (coding-system-flags coding-system))) |
|---|
| 623 |
(princ type) |
|---|
| 624 |
(cond ((eq type nil) |
|---|
| 625 |
(princ " (do no conversion)")) |
|---|
| 626 |
((eq type t) |
|---|
| 627 |
(princ " (do automatic conversion)")) |
|---|
| 628 |
((eq type 0) |
|---|
| 629 |
(princ " (Emacs internal multibyte form)")) |
|---|
| 630 |
((eq type 1) |
|---|
| 631 |
(princ " (Shift-JIS, MS-KANJI)")) |
|---|
| 632 |
((eq type 2) |
|---|
| 633 |
(princ " (variant of ISO-2022)\n") |
|---|
| 634 |
(princ "Initial designations:\n") |
|---|
| 635 |
(print-designation flags) |
|---|
| 636 |
(princ "Other Form: \n ") |
|---|
| 637 |
(princ (if (aref flags 4) "short-form" "long-form")) |
|---|
| 638 |
(if (aref flags 5) (princ ", ASCII@EOL")) |
|---|
| 639 |
(if (aref flags 6) (princ ", ASCII@CNTL")) |
|---|
| 640 |
(princ (if (aref flags 7) ", 7-bit" ", 8-bit")) |
|---|
| 641 |
(if (aref flags 8) (princ ", use-locking-shift")) |
|---|
| 642 |
(if (aref flags 9) (princ ", use-single-shift")) |
|---|
| 643 |
(if (aref flags 10) (princ ", use-roman")) |
|---|
| 644 |
(if (aref flags 11) (princ ", use-old-jis")) |
|---|
| 645 |
(if (aref flags 12) (princ ", no-ISO6429")) |
|---|
| 646 |
(if (aref flags 13) (princ ", init-bol")) |
|---|
| 647 |
(if (aref flags 14) (princ ", designation-bol")) |
|---|
| 648 |
(if (aref flags 15) (princ ", convert-unsafe")) |
|---|
| 649 |
(if (aref flags 16) (princ ", accept-latin-extra-code")) |
|---|
| 650 |
(princ ".")) |
|---|
| 651 |
((eq type 3) |
|---|
| 652 |
(princ " (Big5)")) |
|---|
| 653 |
((eq type 4) |
|---|
| 654 |
(princ " (do conversion by CCL program)")) |
|---|
| 655 |
((eq type 5) |
|---|
| 656 |
(princ " (text with random binary characters)")) |
|---|
| 657 |
(t (princ ": invalid coding-system.")))) |
|---|
| 658 |
(princ "\nEOL type: ") |
|---|
| 659 |
(let ((eol-type (coding-system-eol-type coding-system))) |
|---|
| 660 |
(cond ((vectorp eol-type) |
|---|
| 661 |
(princ "Automatic selection from:\n\t") |
|---|
| 662 |
(princ eol-type) |
|---|
| 663 |
(princ "\n")) |
|---|
| 664 |
((or (null eol-type) (eq eol-type 0)) (princ "LF\n")) |
|---|
| 665 |
((eq eol-type 1) (princ "CRLF\n")) |
|---|
| 666 |
((eq eol-type 2) (princ "CR\n")) |
|---|
| 667 |
(t (princ "invalid\n")))) |
|---|
| 668 |
(let ((postread (coding-system-get coding-system 'post-read-conversion))) |
|---|
| 669 |
(when postread |
|---|
| 670 |
(princ "After decoding text normally,") |
|---|
| 671 |
(princ " perform post-conversion using the function: ") |
|---|
| 672 |
(princ "\n ") |
|---|
| 673 |
(princ postread) |
|---|
| 674 |
(princ "\n"))) |
|---|
| 675 |
(let ((prewrite (coding-system-get coding-system 'pre-write-conversion))) |
|---|
| 676 |
(when prewrite |
|---|
| 677 |
(princ "Before encoding text normally,") |
|---|
| 678 |
(princ " perform pre-conversion using the function: ") |
|---|
| 679 |
(princ "\n ") |
|---|
| 680 |
(princ prewrite) |
|---|
| 681 |
(princ "\n"))) |
|---|
| 682 |
(with-current-buffer standard-output |
|---|
| 683 |
(let ((charsets (coding-system-get coding-system 'safe-charsets))) |
|---|
| 684 |
(when (and (not (memq (coding-system-base coding-system) |
|---|
| 685 |
'(raw-text emacs-mule))) |
|---|
| 686 |
charsets) |
|---|
| 687 |
(if (eq charsets t) |
|---|
| 688 |
(insert "This coding system can encode all charsets except for |
|---|
| 689 |
eight-bit-control and eight-bit-graphic.\n") |
|---|
| 690 |
(insert "This coding system encodes the following charsets:\n ") |
|---|
| 691 |
(while charsets |
|---|
| 692 |
(insert " " (symbol-name (car charsets))) |
|---|
| 693 |
(search-backward (symbol-name (car charsets))) |
|---|
| 694 |
(help-xref-button 0 'help-character-set (car charsets)) |
|---|
| 695 |
(goto-char (point-max)) |
|---|
| 696 |
(setq charsets (cdr charsets)))))))))) |
|---|
| 697 |
|
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
(defun describe-current-coding-system-briefly () |
|---|
| 701 |
"Display coding systems currently used in a brief format in echo area. |
|---|
| 702 |
|
|---|
| 703 |
The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\", |
|---|
| 704 |
where mnemonics of the following coding systems come in this order |
|---|
| 705 |
in place of `..': |
|---|
| 706 |
`buffer-file-coding-system' (of the current buffer) |
|---|
| 707 |
eol-type of `buffer-file-coding-system' (of the current buffer) |
|---|
| 708 |
Value returned by `keyboard-coding-system' |
|---|
| 709 |
eol-type of `keyboard-coding-system' |
|---|
| 710 |
Value returned by `terminal-coding-system'. |
|---|
| 711 |
eol-type of `terminal-coding-system' |
|---|
| 712 |
`process-coding-system' for read (of the current buffer, if any) |
|---|
| 713 |
eol-type of `process-coding-system' for read (of the current buffer, if any) |
|---|
| 714 |
`process-coding-system' for write (of the current buffer, if any) |
|---|
| 715 |
eol-type of `process-coding-system' for write (of the current buffer, if any) |
|---|
| 716 |
`default-buffer-file-coding-system' |
|---|
| 717 |
eol-type of `default-buffer-file-coding-system' |
|---|
| 718 |
`default-process-coding-system' for read |
|---|
| 719 |
eol-type of `default-process-coding-system' for read |
|---|
| 720 |
`default-process-coding-system' for write |
|---|
| 721 |
eol-type of `default-process-coding-system'" |
|---|
| 722 |
(interactive) |
|---|
| 723 |
(let* ((proc (get-buffer-process (current-buffer))) |
|---|
| 724 |
(process-coding-systems (if proc (process-coding-system proc)))) |
|---|
| 725 |
(message |
|---|
| 726 |
"F[%c%s],K[%c%s],T[%c%s],P>[%c%s],P<[%c%s], default F[%c%s],P>[%c%s],P<[%c%s]" |
|---|
| 727 |
(coding-system-mnemonic buffer-file-coding-system) |
|---|
| 728 |
(coding-system-eol-type-mnemonic buffer-file-coding-system) |
|---|
| 729 |
(coding-system-mnemonic (keyboard-coding-system)) |
|---|
| 730 |
(coding-system-eol-type-mnemonic (keyboard-coding-system)) |
|---|
| 731 |
(coding-system-mnemonic (terminal-coding-system)) |
|---|
| 732 |
(coding-system-eol-type-mnemonic (terminal-coding-system)) |
|---|
| 733 |
(coding-system-mnemonic (car process-coding-systems)) |
|---|
| 734 |
(coding-system-eol-type-mnemonic (car process-coding-systems)) |
|---|
| 735 |
(coding-system-mnemonic (cdr process-coding-systems)) |
|---|
| 736 |
(coding-system-eol-type-mnemonic (cdr process-coding-systems)) |
|---|
| 737 |
(coding-system-mnemonic default-buffer-file-coding-system) |
|---|
| 738 |
(coding-system-eol-type-mnemonic default-buffer-file-coding-system) |
|---|
| 739 |
(coding-system-mnemonic (car default-process-coding-system)) |
|---|
| 740 |
(coding-system-eol-type-mnemonic (car default-process-coding-system)) |
|---|
| 741 |
(coding-system-mnemonic (cdr default-process-coding-system)) |
|---|
| 742 |
(coding-system-eol-type-mnemonic (cdr default-process-coding-system)) |
|---|
| 743 |
))) |
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
|
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
(defun print-coding-system-briefly (coding-system &optional doc-string) |
|---|
| 751 |
(if (not coding-system) |
|---|
| 752 |
(princ "nil\n") |
|---|
| 753 |
(princ (format "%c -- %s" |
|---|
| 754 |
(coding-system-mnemonic coding-system) |
|---|
| 755 |
coding-system)) |
|---|
| 756 |
(let ((aliases (coding-system-get coding-system 'alias-coding-systems))) |
|---|
| 757 |
(cond ((eq coding-system (car aliases)) |
|---|
| 758 |
(if (cdr aliases) |
|---|
| 759 |
(princ (format " %S" (cons 'alias: (cdr aliases)))))) |
|---|
| 760 |
((memq coding-system aliases) |
|---|
| 761 |
(princ (format " (alias of %s)" (car aliases)))) |
|---|
| 762 |
(t |
|---|
| 763 |
(let ((eol-type (coding-system-eol-type coding-system)) |
|---|
| 764 |
(base-eol-type (coding-system-eol-type (car aliases)))) |
|---|
| 765 |
(if (and (integerp eol-type) |
|---|
| 766 |
(vectorp base-eol-type) |
|---|
| 767 |
(not (eq coding-system (aref base-eol-type eol-type)))) |
|---|
| 768 |
(princ (format " (alias of %s)" |
|---|
| 769 |
(aref base-eol-type eol-type)))))))) |
|---|
| 770 |
(princ "\n") |
|---|
| 771 |
(or (eq doc-string 'tightly) |
|---|
| 772 |
(princ "\n")) |
|---|
| 773 |
(if doc-string |
|---|
| 774 |
(let ((doc (or (coding-system-doc-string coding-system) ""))) |
|---|
| 775 |
(when (eq doc-string 'tightly) |
|---|
| 776 |
(if (string-match "\n" doc) |
|---|
| 777 |
(setq doc (substring doc 0 (match-beginning 0)))) |
|---|
| 778 |
(setq doc (concat " " doc))) |
|---|
| 779 |
(princ (format "%s\n" doc)))))) |
|---|
| 780 |
|
|---|
| 781 |
|
|---|
| 782 |
(defun describe-current-coding-system () |
|---|
| 783 |
"Display coding systems currently used, in detail." |
|---|
| 784 |
(interactive) |
|---|
| 785 |
(with-output-to-temp-buffer "*Help*" |
|---|
| 786 |
(let* ((proc (get-buffer-process (current-buffer))) |
|---|
| 787 |
(process-coding-systems (if proc (process-coding-system proc)))) |
|---|
| 788 |
(princ "Coding system for saving this buffer:\n ") |
|---|
| 789 |
(if (local-variable-p 'buffer-file-coding-system) |
|---|
| 790 |
(print-coding-system-briefly buffer-file-coding-system) |
|---|
| 791 |
(princ "Not set locally, use the default.\n")) |
|---|
| 792 |
(princ "Default coding system (for new files):\n ") |
|---|
| 793 |
&nb |
|---|