1 ;;; mule-diag.el --- Show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
6 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
25 ;;; General utility function
27 ;; Print all arguments with single space separator in one line.
28 (defun print-list (&rest args
)
33 (setq args
(cdr args
)))
37 ;; Re-order the elements of charset-list.
38 (defun sort-charset-list ()
41 (function (lambda (x y
) (< (charset-id x
) (charset-id y
)))))))
46 (defun list-character-sets (arg)
47 "Display a list of all character sets.
49 The ID-NUM column contains a charset identification number
50 for internal Emacs use.
52 The MULTIBYTE-FORM column contains a format of multibyte sequence
53 of characters in the charset for buffer and string
54 by one to four hexadecimal digits.
55 `xx' stands for any byte in the range 0..127.
56 `XX' stands for any byte in the range 160..255.
58 The D column contains a dimension of this character set.
59 The CH column contains a number of characters in a block of this character set.
60 The FINAL-CHAR column contains an ISO-2022's <final-char> to use for
61 designating this character set in ISO-2022-based coding systems.
63 With prefix arg, the output format gets more cryptic,
64 but still shows the full information."
66 (with-output-to-temp-buffer "*Help*"
67 (with-current-buffer standard-output
69 (list-character-sets-2)
72 (substitute-command-keys
74 (if (display-mouse-p) "\\[help-follow-mouse] or ")
75 "\\[help-follow]:\n")))
76 (insert " on a column title to sort by that title,")
78 (insert "+----DIMENSION\n")
79 (insert " on a charset name to list characters.")
81 (insert "| +--CHARS\n")
82 (let ((columns '(("ID-NUM" . id
) "\t"
83 ("CHARSET-NAME" . name
) "\t\t\t"
84 ("MULTIBYTE-FORM" . id
) "\t"
85 ("D CH FINAL-CHAR" . iso-spec
)))
86 (help-highlight-face 'region
)
88 (substitute-command-keys
89 (concat (if (display-mouse-p) "\\[help-follow-mouse], ")
90 "\\[help-follow]: sort on this column")))
93 (if (stringp (car columns
))
94 (insert (car columns
))
95 (insert (car (car columns
)))
96 (search-backward (car (car columns
)))
97 (help-xref-button 0 'sort-listed-character-sets
100 (goto-char (point-max)))
101 (setq columns
(cdr columns
)))
103 (insert "------\t------------\t\t\t--------------\t- -- ----------\n")
105 ;; Insert body sorted by charset IDs.
106 (list-character-sets-1 'id
)
107 (help-setup-xref (list #'list-character-sets arg
) (interactive-p))))))
110 ;; Sort character set list by SORT-KEY.
112 (defun sort-listed-character-sets (sort-key)
115 (let ((buffer-read-only nil
))
116 (goto-char (point-min))
117 (re-search-forward "[0-9][0-9][0-9]")
119 (delete-region (point) (point-max))
120 (list-character-sets-1 sort-key
)
121 (help-setup-xref (list #'list-character-sets nil
) t
)))))
123 ;; Insert a list of character sets sorted by SORT-KEY. SORT-KEY
124 ;; should be one of `id', `name', and `iso-spec'. If SORT-KEY is nil,
125 ;; it defaults to `id'.
127 (defun list-character-sets-1 (sort-key)
130 (let ((tail (charset-list))
132 (substitute-command-keys
133 (concat (if (display-mouse-p) "\\[help-follow-mouse], ")
134 "\\[help-follow]: show table of this character set")))
135 charset-info-list elt charset info sort-func
)
137 (setq charset
(car tail
) tail
(cdr tail
)
138 info
(charset-info charset
))
140 ;; Generate a list that contains all information to display.
141 (setq charset-info-list
142 (cons (list (charset-id charset
) ; ID-NUM
143 charset
; CHARSET-NAME
144 (if (eq charset
'ascii
) ; MULTIBYTE-FORM
146 (let ((str (format "%2X" (aref info
6))))
147 (if (> (aref info
7) 0)
148 (setq str
(format "%s %2X" str
(aref info
7))))
149 (setq str
(concat str
" XX"))
150 (if (> (aref info
2) 1)
151 (setq str
(concat str
" XX")))
153 (aref info
2) ; DIMENSION
154 (aref info
3) ; CHARS
155 (aref info
8) ; FINAL-CHAR
159 ;; Determine a predicate for `sort' by SORT-KEY.
161 (cond ((eq sort-key
'id
)
162 (function (lambda (x y
) (< (car x
) (car y
)))))
165 (function (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
167 ((eq sort-key
'iso-spec
)
168 ;; Sort by DIMENSION CHARS FINAL-CHAR
171 (or (< (nth 3 x
) (nth 3 y
))
172 (and (= (nth 3 x
) (nth 3 y
))
173 (or (< (nth 4 x
) (nth 4 y
))
174 (and (= (nth 4 x
) (nth 4 y
))
175 (< (nth 5 x
) (nth 5 y
)))))))))
177 (error "Invalid charset sort key: %s" sort-key
))))
179 (setq charset-info-list
(sort charset-info-list sort-func
))
181 ;; Insert information of character sets.
182 (while charset-info-list
183 (setq elt
(car charset-info-list
)
184 charset-info-list
(cdr charset-info-list
))
185 (insert (format "%03d(%02X)" (car elt
) (car elt
))) ; ID-NUM
187 (insert (symbol-name (nth 1 elt
))) ; CHARSET-NAME
188 (search-backward (symbol-name (nth 1 elt
)))
189 (help-xref-button 0 'list-charset-chars
(nth 1 elt
) help-echo
)
190 (goto-char (point-max))
193 (insert (nth 2 elt
)) ; MULTIBYTE-FORM
195 (insert (format "%d %2d %c" ; ISO specs
196 (nth 3 elt
) (nth 4 elt
) (nth 5 elt
)))
200 ;; List all character sets in a form that a program can easily parse.
202 (defun list-character-sets-2 ()
203 (insert "#########################
205 ## Each line corresponds to one charset.
206 ## The following attributes are listed in this order
207 ## separated by a colon `:' in one line.
209 ## CHARSET-SYMBOL-NAME,
210 ## DIMENSION (1 or 2)
212 ## BYTES (of multibyte form: 1, 2, 3, or 4),
213 ## WIDTH (occupied column numbers: 1 or 2),
214 ## DIRECTION (0:left-to-right, 1:right-to-left),
215 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
216 ## ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR)
217 ## DESCRIPTION (describing string of the charset)
219 (let ((l charset-list
)
222 (setq charset
(car l
) l
(cdr l
))
223 (princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n"
226 (charset-dimension charset
)
227 (charset-chars charset
)
228 (charset-bytes charset
)
229 (charset-width charset
)
230 (charset-direction charset
)
231 (charset-iso-final-char charset
)
232 (charset-iso-graphic-plane charset
)
233 (charset-description charset
))))))
235 (defvar non-iso-charset-alist
237 (ascii vietnamese-viscii-lower vietnamese-viscii-upper
)
238 ,viet-viscii-nonascii-translation-table
241 (ascii cyrillic-iso8859-5
)
242 ,cyrillic-koi8-r-nonascii-translation-table
245 (ascii cyrillic-iso8859-5
)
246 ,cyrillic-alternativnyj-nonascii-translation-table
249 (ascii chinese-big5-1 chinese-big5-2
)
252 ((?
\xA1 ?
\xFE) .
(?
\x40 ?
\x7E ?
\xA1 ?
\xFE))))
254 (ascii katakana-jisx0201 japanese-jisx0208
)
256 ((32 127 ?
\xA1 ?
\xDF)
257 ((?
\x81 ?
\x9F ?
\xE0 ?
\xEF) .
(?
\x40 ?
\x7E ?
\x80 ?
\xFC)))))
258 "Alist of non-ISO charset names vs the corresponding information.
260 Non-ISO charsets are what Emacs can read (or write) by mapping to (or
261 from) some Emacs' charsets that correspond to ISO charsets.
263 Each element has the following format:
264 (NON-ISO-CHARSET CHARSET-LIST TRANSLATION-METHOD [ CODE-RANGE ])
266 NON-ISO-CHARSET is a name (symbol) of the non-ISO charset.
268 CHARSET-LIST is a list of Emacs' charsets into which characters of
269 NON-ISO-CHARSET are mapped.
271 TRANSLATION-METHOD is a char-table to translate a character code of
272 NON-ISO-CHARSET to the corresponding Emacs character code. It can
273 also be a function to call with one argument, a character code in
276 CODE-RANGE specifies the valid code ranges of NON-ISO-CHARSET.
277 It is a list of RANGEs, where each RANGE is of the form:
278 (FROM1 TO1 FROM2 TO2 ...)
280 ((FROM1-1 TO1-1 FROM1-2 TO1-2 ...) . (FROM2-1 TO2-1 FROM2-2 TO2-2 ...))
281 In the first form, valid codes are between FROM1 and TO1, or FROM2 and
283 The second form is used for 2-byte codes. The car part is the ranges
284 of the first byte, and the cdr part is the ranges of the second byte.")
287 ;; Decode a character that has code CODE in CODEPAGE. Value is a
288 ;; string of decoded character.
290 (defun decode-codepage-char (codepage code
)
291 ;; Each CODEPAGE corresponds to a coding system cpCODEPAGE.
292 (let ((coding-system (intern (format "cp%d" codepage
))))
293 (or (coding-system-p coding-system
)
294 (codepage-setup codepage
))
296 (decode-coding-string (char-to-string code
) coding-system
))))
299 ;; Add DOS codepages to `non-iso-charset-alist'.
301 (let ((tail (cp-supported-codepages))
304 (setq elt
(car tail
) tail
(cdr tail
))
305 ;; Now ELT is (CODEPAGE . CHARSET), where CODEPAGE is a string
306 ;; (e.g. "850"), CHARSET is a charset that characters in CODEPAGE
308 (setq non-iso-charset-alist
309 (cons (list (intern (concat "cp" (car elt
)))
310 (list 'ascii
(cdr elt
))
312 (decode-codepage-char ,(string-to-int (car elt
))
315 non-iso-charset-alist
))))
318 ;; A variable to hold charset input history.
319 (defvar charset-history nil
)
323 (defun read-charset (prompt &optional default-value initial-input
)
324 "Read a character set from the minibuffer, prompting with string PROMPT.
325 It reads an Emacs' character set listed in the variable `charset-list'
326 or a non-ISO character set listed in the variable
327 `non-iso-charset-alist'.
329 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
330 DEFAULT-VALUE, if non-nil, is the default value.
331 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
332 See the documentation of the function `completing-read' for the
333 detailed meanings of these arguments."
334 (let* ((table (append (mapcar (function (lambda (x) (list (symbol-name x
))))
336 (mapcar (function (lambda (x)
337 (list (symbol-name (car x
)))))
338 non-iso-charset-alist
)))
339 (charset (completing-read prompt table
340 nil t initial-input
'charset-history
342 (if (> (length charset
) 0)
346 ;; List characters of the range MIN and MAX of CHARSET. If dimension
347 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
348 ;; (block index) of the characters, and MIN and MAX are the second
349 ;; bytes of the characters. If the dimension is one, ROW should be 0.
350 ;; For a non-ISO charset, CHARSET is a char-table or a function to get
351 ;; Emacs' character codes that corresponds to the characters to list.
353 (defun list-block-of-chars (charset row min max
)
355 (insert-char ?-
(+ 4 (* 3 16)))
359 (insert (format "%3X" i
))
361 (setq i
(* (/ min
16) 16))
364 (insert (format "\n%3Xx" (/ (+ (* row
256) i
) 16))))
365 (setq ch
(cond ((< i min
)
369 (make-char charset i
)
370 (make-char charset row i
)))
371 ((char-table-p charset
)
373 (t (funcall charset
(+ (* row
256) i
)))))
374 (if (or (< ch
32) (and (>= ch
127) (<= ch
255)))
375 ;; Don't insert a control code.
377 (insert (format "%3c" ch
))
382 ;; List all characters in ISO charset CHARSET.
384 (defun list-iso-charset-chars (charset)
385 (let ((dim (charset-dimension charset
))
386 (chars (charset-chars charset
))
387 (plane (charset-iso-graphic-plane charset
))
389 (insert (format "Characters in the charset %s.\n" charset
))
392 (setq min
33 max
126)
393 (setq min
32 max
127))
395 (setq min
(+ min
128) max
(+ max
128)))
398 (list-block-of-chars charset
0 min max
)
401 (list-block-of-chars charset i min max
)
405 ;; List all characters in non-ISO charset CHARSET.
407 (defun list-non-iso-charset-chars (charset)
408 (let* ((slot (assq charset non-iso-charset-alist
))
409 (charsets (nth 1 slot
))
410 (translate-method (nth 2 slot
))
411 (ranges (nth 3 slot
))
414 (error "Unknown external charset: %s" charset
))
415 (insert (format "Characters in non-ISO charset %s.\n" charset
))
416 (insert "They are mapped to: "
417 (mapconcat (lambda (x) (symbol-name x
)) charsets
", ")
420 (setq range
(car ranges
) ranges
(cdr ranges
))
421 (if (integerp (car range
))
422 ;; The form of RANGES is (FROM1 TO1 FROM2 TO2 ...).
424 (list-block-of-chars translate-method
425 0 (car range
) (nth 1 range
))
426 (setq range
(nthcdr 2 range
)))
427 ;; The form of RANGES is ((FROM1-1 TO1-1 ...) . (FROM2-1 TO2-1 ...)).
428 (let ((row-range (car range
))
430 col-range col col-max
)
432 (setq row
(car row-range
) row-max
(nth 1 row-range
)
433 row-range
(nthcdr 2 row-range
))
434 (while (< row row-max
)
435 (setq col-range
(cdr range
))
437 (setq col
(car col-range
) col-max
(nth 1 col-range
)
438 col-range
(nthcdr 2 col-range
))
439 (list-block-of-chars translate-method row col col-max
))
440 (setq row
(1+ row
)))))))))
444 (defun list-charset-chars (charset)
445 "Display a list of characters in the specified character set."
446 (interactive (list (read-charset "Character set: ")))
447 (with-output-to-temp-buffer "*Help*"
448 (with-current-buffer standard-output
449 (set-buffer-multibyte t
)
450 (cond ((charsetp charset
)
451 (list-iso-charset-chars charset
))
452 ((assq charset non-iso-charset-alist
)
453 (list-non-iso-charset-chars charset
))
455 (error "Invalid charset %s" charset
))))))
459 (defun describe-char-after (&optional pos
)
460 "Display information of in current buffer at position POS.
461 The information includes character code, charset and code points in it,
462 syntax, category, how the character is encoded in a file,
463 which font is being used for displaying the character."
467 (if (>= pos
(point-max))
468 (error "No character at point"))
469 (let* ((char (char-after pos
))
470 (charset (char-charset char
))
471 (composition (find-composition (point) nil nil t
))
472 (composed (if composition
(buffer-substring (car composition
)
473 (nth 1 composition
))))
475 (if (eq charset
'unknown
)
478 ,(format "%s (0%o, %d, 0x%x) -- invalid character code"
480 (single-key-description char
)
481 (char-to-string char
))
485 ,(format "%s (0%o, %d, 0x%x)" (if (< char
256)
486 (single-key-description char
)
487 (char-to-string char
))
490 ,(symbol-name charset
)
491 ,(format "(%s)" (charset-description charset
)))
493 ,(let ((split (split-char char
)))
494 (if (= (charset-dimension charset
) 1)
495 (format "%d" (nth 1 split
))
496 (format "%d %d" (nth 1 split
) (nth 2 split
)))))
498 ,(nth 2 (assq (char-syntax char
) syntax-code-table
)))
500 ,@(let ((category-set (char-category-set char
)))
501 (if (not category-set
)
503 (mapcar #'(lambda (x) (format "%c:%s "
504 x
(category-docstring x
)))
505 (category-set-mnemonics category-set
)))))
507 ,(encoded-string-description
508 (string-as-unibyte (char-to-string char
)) nil
))
510 ,@(let* ((coding buffer-file-coding-system
)
511 (encoded (encode-coding-char char coding
)))
513 (list (encoded-string-description encoded coding
)
514 (format "(encoded by coding system %S)" coding
))
515 (list "not encodable by coding system"
516 (symbol-name coding
)))))
518 (list "font" (or (internal-char-font (point))
520 (list "terminal code"
521 (let* ((coding (terminal-coding-system))
522 (encoded (encode-coding-char char coding
)))
524 (encoded-string-description encoded coding
)
525 "not encodable")))))))
526 (setq max-width
(apply #'max
(mapcar #'(lambda (x) (length (car x
)))
528 (with-output-to-temp-buffer "*Help*"
530 (set-buffer standard-output
)
531 (let ((formatter (format "%%%ds:" max-width
)))
532 (dolist (elt item-list
)
533 (insert (format formatter
(car elt
)))
534 (dolist (clm (cdr elt
))
535 (when (>= (+ (current-column) (string-width clm
) 1)
538 (indent-to (1+ max-width
)))
542 (insert "\nComposed with the following characerter(s) "
543 (mapconcat (lambda (x) (format "`%c'" x
))
544 (substring composed
1)
546 " to form `" composed
"'")
547 (if (nth 3 composition
)
549 (insert "\nby the rule ("
550 (mapconcat (lambda (x)
551 (format (if (consp x
) "%S" "?%c") x
))
555 "See the variable `reference-point-alist' for the meaning of the rule.\n")))
561 ;; Print information of designation of each graphic register in FLAGS
562 ;; in human readable format. See the documentation of
563 ;; `make-coding-system' for the meaning of FLAGS.
564 (defun print-designation (flags)
565 (let ((graphic-register 0)
567 (while (< graphic-register
4)
568 (setq charset
(aref flags graphic-register
))
572 (cond ((null charset
)
575 "no initial designation, and used by any charsets")
578 charset
(charset-description charset
)))
580 (if (charsetp (car charset
))
581 (format "%s:%s, and also used by the followings:"
583 (charset-description (car charset
)))
584 "no initial designation, and used by the followings:"))
586 "invalid designation information"))))
587 (when (listp charset
)
588 (setq charset
(cdr charset
))
590 (cond ((eq (car charset
) t
)
591 (princ "\tany other charsets\n"))
592 ((charsetp (car charset
))
593 (princ (format "\t%s:%s\n"
595 (charset-description (car charset
)))))
597 "invalid designation information"))
598 (setq charset
(cdr charset
))))
599 (setq graphic-register
(1+ graphic-register
)))))
602 (defun describe-coding-system (coding-system)
603 "Display information about CODING-SYSTEM."
604 (interactive "zDescribe coding system (default, current choices): ")
605 (if (null coding-system
)
606 (describe-current-coding-system)
607 (with-output-to-temp-buffer "*Help*"
608 (print-coding-system-briefly coding-system
'doc-string
)
609 (let ((coding-spec (coding-system-spec coding-system
)))
611 (let ((type (coding-system-type coding-system
))
612 (flags (coding-system-flags coding-system
)))
615 (princ " (do no conversion)"))
617 (princ " (do automatic conversion)"))
619 (princ " (Emacs internal multibyte form)"))
621 (princ " (Shift-JIS, MS-KANJI)"))
623 (princ " (variant of ISO-2022)\n")
624 (princ "Initial designations:\n")
625 (print-designation flags
)
626 (princ "Other Form: \n ")
627 (princ (if (aref flags
4) "short-form" "long-form"))
628 (if (aref flags
5) (princ ", ASCII@EOL"))
629 (if (aref flags
6) (princ ", ASCII@CNTL"))
630 (princ (if (aref flags
7) ", 7-bit" ", 8-bit"))
631 (if (aref flags
8) (princ ", use-locking-shift"))
632 (if (aref flags
9) (princ ", use-single-shift"))
633 (if (aref flags
10) (princ ", use-roman"))
634 (if (aref flags
11) (princ ", use-old-jis"))
635 (if (aref flags
12) (princ ", no-ISO6429"))
636 (if (aref flags
13) (princ ", init-bol"))
637 (if (aref flags
14) (princ ", designation-bol"))
638 (if (aref flags
15) (princ ", convert-unsafe"))
639 (if (aref flags
16) (princ ", accept-latin-extra-code"))
644 (princ " (do conversion by CCL program)"))
646 (princ " (text with random binary characters)"))
647 (t (princ ": invalid coding-system."))))
648 (princ "\nEOL type: ")
649 (let ((eol-type (coding-system-eol-type coding-system
)))
650 (cond ((vectorp eol-type
)
651 (princ "Automatic selection from:\n\t")
654 ((or (null eol-type
) (eq eol-type
0)) (princ "LF\n"))
655 ((eq eol-type
1) (princ "CRLF\n"))
656 ((eq eol-type
2) (princ "CR\n"))
657 (t (princ "invalid\n")))))
658 (let ((postread (coding-system-get coding-system
'post-read-conversion
)))
660 (princ "After decoding a text normally,")
661 (princ " perform post-conversion by the function: ")
665 (let ((prewrite (coding-system-get coding-system
'pre-write-conversion
)))
667 (princ "Before encoding a text normally,")
668 (princ " perform pre-conversion by the function: ")
672 (let ((charsets (coding-system-get coding-system
'safe-charsets
)))
675 (princ "This coding system can encode all charsets.\n")
676 (princ "This coding system encode the following charsets:\n")
680 (princ (car charsets
))
681 (setq charsets
(cdr charsets
))))))
683 (set-buffer standard-output
)
687 (defun describe-current-coding-system-briefly ()
688 "Display coding systems currently used in a brief format in echo area.
690 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
691 where mnemonics of the following coding systems come in this order
692 at the place of `..':
693 `buffer-file-coding-system` (of the current buffer)
694 eol-type of buffer-file-coding-system (of the current buffer)
695 Value returned by `keyboard-coding-system'
696 eol-type of (keyboard-coding-system)
697 Value returned by `terminal-coding-system.
698 eol-type of (terminal-coding-system)
699 `process-coding-system' for read (of the current buffer, if any)
700 eol-type of process-coding-system for read (of the current buffer, if any)
701 `process-coding-system' for write (of the current buffer, if any)
702 eol-type of process-coding-system for write (of the current buffer, if any)
703 `default-buffer-file-coding-system'
704 eol-type of default-buffer-file-coding-system
705 `default-process-coding-system' for read
706 eol-type of default-process-coding-system for read
707 `default-process-coding-system' for write
708 eol-type of default-process-coding-system"
710 (let* ((proc (get-buffer-process (current-buffer)))
711 (process-coding-systems (if proc
(process-coding-system proc
))))
713 "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]"
714 (coding-system-mnemonic buffer-file-coding-system
)
715 (coding-system-eol-type-mnemonic buffer-file-coding-system
)
716 (coding-system-mnemonic (keyboard-coding-system))
717 (coding-system-eol-type-mnemonic (keyboard-coding-system))
718 (coding-system-mnemonic (terminal-coding-system))
719 (coding-system-eol-type-mnemonic (terminal-coding-system))
720 (coding-system-mnemonic (car process-coding-systems
))
721 (coding-system-eol-type-mnemonic (car process-coding-systems
))
722 (coding-system-mnemonic (cdr process-coding-systems
))
723 (coding-system-eol-type-mnemonic (cdr process-coding-systems
))
724 (coding-system-mnemonic default-buffer-file-coding-system
)
725 (coding-system-eol-type-mnemonic default-buffer-file-coding-system
)
726 (coding-system-mnemonic (car default-process-coding-system
))
727 (coding-system-eol-type-mnemonic (car default-process-coding-system
))
728 (coding-system-mnemonic (cdr default-process-coding-system
))
729 (coding-system-eol-type-mnemonic (cdr default-process-coding-system
))
732 ;; Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
733 (defun print-coding-system-briefly (coding-system &optional doc-string
)
734 (if (not coding-system
)
736 (princ (format "%c -- %s"
737 (coding-system-mnemonic coding-system
)
739 (let ((aliases (coding-system-get coding-system
'alias-coding-systems
)))
740 (if (eq coding-system
(car aliases
))
742 (princ (format " %S" (cons 'alias
: (cdr aliases
)))))
743 (if (memq coding-system aliases
)
744 (princ (format " (alias of %s)" (car aliases
))))))
747 (setq doc-string
(coding-system-doc-string coding-system
)))
748 (princ (format " %s\n" doc-string
)))))
751 (defun describe-current-coding-system ()
752 "Display coding systems currently used, in detail."
754 (with-output-to-temp-buffer "*Help*"
755 (let* ((proc (get-buffer-process (current-buffer)))
756 (process-coding-systems (if proc
(process-coding-system proc
))))
757 (princ "Coding system for saving this buffer:\n ")
758 (if (local-variable-p 'buffer-file-coding-system
)
759 (print-coding-system-briefly buffer-file-coding-system
)
760 (princ "Not set locally, use the default.\n"))
761 (princ "Default coding system (for new files):\n ")
762 (print-coding-system-briefly default-buffer-file-coding-system
)
763 (princ "Coding system for keyboard input:\n ")
764 (print-coding-system-briefly (keyboard-coding-system))
765 (princ "Coding system for terminal output:\n ")
766 (print-coding-system-briefly (terminal-coding-system))
767 (when (get-buffer-process (current-buffer))
768 (princ "Coding systems for process I/O:\n")
769 (princ " encoding input to the process: ")
770 (print-coding-system-briefly (cdr process-coding-systems
))
771 (princ " decoding output from the process: ")
772 (print-coding-system-briefly (car process-coding-systems
)))
773 (princ "Defaults for subprocess I/O:\n")
774 (princ " decoding: ")
775 (print-coding-system-briefly (car default-process-coding-system
))
776 (princ " encoding: ")
777 (print-coding-system-briefly (cdr default-process-coding-system
)))
780 (set-buffer standard-output
)
782 (princ "\nPriority order for recognizing coding systems when reading files:\n")
783 (let ((l coding-category-list
)
788 (setq coding
(symbol-value (car l
)))
789 ;; Do not list up the same coding system twice.
790 (when (and coding
(not (memq coding coding-list
)))
791 (setq coding-list
(cons coding coding-list
))
792 (princ (format " %d. %s " i coding
))
793 (setq aliases
(coding-system-get coding
'alias-coding-systems
))
794 (if (eq coding
(car aliases
))
796 (princ (cons 'alias
: (cdr aliases
))))
797 (if (memq coding aliases
)
798 (princ (list 'alias
'of
(car aliases
)))))
803 (princ "\n Other coding systems cannot be distinguished automatically
804 from these, and therefore cannot be recognized automatically
805 with the present coding system priorities.\n\n")
807 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
808 coding-system codings
)
810 (setq coding-system
(symbol-value (car categories
)))
814 (if (and (not (eq x coding-system
))
815 (coding-system-get x
'no-initial-designation
)
816 (let ((flags (coding-system-flags x
)))
817 (not (or (aref flags
10) (aref flags
11)))))
818 (setq codings
(cons x codings
)))))
819 (get (car categories
) 'coding-systems
))
821 (let ((max-col (frame-width))
823 (princ (format " The followings are decoded correctly but recognized as %s:\n " coding-system
))
826 (insert (format " %s" (car codings
)))
827 (when (> (current-column) max-col
)
830 (goto-char (point-max)))
831 (setq codings
(cdr codings
)))
833 (setq categories
(cdr categories
))))
835 (princ "Particular coding systems specified for certain file names:\n")
837 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
838 (princ " ---------\t--------------\t\t----------------\n")
839 (let ((func (lambda (operation alist
)
843 (princ "\tnothing specified\n")
846 (prin1 (car (car alist
)))
847 (if (>= (current-column) 40)
850 (princ (cdr (car alist
)))
852 (setq alist
(cdr alist
)))))))
853 (funcall func
"File I/O" file-coding-system-alist
)
854 (funcall func
"Process I/O" process-coding-system-alist
)
855 (funcall func
"Network I/O" network-coding-system-alist
))
858 ;; Print detailed information on CODING-SYSTEM.
859 (defun print-coding-system (coding-system)
860 (let ((type (coding-system-type coding-system
))
861 (eol-type (coding-system-eol-type coding-system
))
862 (flags (coding-system-flags coding-system
))
863 (aliases (coding-system-get coding-system
'alias-coding-systems
)))
864 (if (not (eq (car aliases
) coding-system
))
865 (princ (format "%s (alias of %s)\n" coding-system
(car aliases
)))
866 (princ coding-system
)
867 (setq aliases
(cdr aliases
))
870 (princ (car aliases
))
871 (setq aliases
(cdr aliases
)))
872 (princ (format ":%s:%c:%d:"
874 (coding-system-mnemonic coding-system
)
875 (if (integerp eol-type
) eol-type
3)))
876 (cond ((eq type
2) ; ISO-2022
880 (setq charset
(aref flags idx
))
881 (cond ((null charset
)
889 (princ (car charset
))
890 (setq charset
(cdr charset
))
893 (princ (car charset
))
894 (setq charset
(cdr charset
)))
899 (princ (if (aref flags idx
) 1 0))
902 (princ (if (aref flags idx
) 1 0))))
905 (if (symbolp (car flags
))
906 (princ (format " %s" (car flags
)))
907 (setq i
0 len
(length (car flags
)))
909 (princ (format " %x" (aref (car flags
) i
)))
912 (if (symbolp (cdr flags
))
913 (princ (format "%s" (cdr flags
)))
914 (setq i
0 len
(length (cdr flags
)))
916 (princ (format " %x" (aref (cdr flags
) i
)))
920 (princ (coding-system-doc-string coding-system
))
924 (defun list-coding-systems (&optional arg
)
925 "Display a list of all coding systems.
926 This shows the mnemonic letter, name, and description of each coding system.
928 With prefix arg, the output format gets more cryptic,
929 but still contains full information about each coding system."
931 (with-output-to-temp-buffer "*Help*"
932 (list-coding-systems-1 arg
)))
934 (defun list-coding-systems-1 (arg)
937 ###############################################
938 # List of coding systems in the following format:
939 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
943 #########################
944 ## LIST OF CODING SYSTEMS
945 ## Each line corresponds to one coding system
946 ## Format of a line is:
947 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
948 ## :PRE-WRITE-CONVERSION:DOC-STRING,
950 ## NAME = coding system name
951 ## ALIAS = alias of the coding system
952 ## TYPE = nil (no conversion), t (undecided or automatic detection),
953 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
954 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
957 ## comma (`,') separated data of the followings:
958 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
959 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
960 ## else if TYPE = 4 then
961 ## comma (`,') separated CCL programs for read and write
964 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
967 (let ((bases (coding-system-list 'base-only
))
970 (setq coding-system
(car bases
))
972 (print-coding-system-briefly coding-system
'doc-string
)
973 (print-coding-system coding-system
))
974 (setq bases
(cdr bases
)))))
977 (defun list-coding-categories ()
978 "Display a list of all coding categories."
979 (with-output-to-temp-buffer "*Help*"
981 ############################
982 ## LIST OF CODING CATEGORIES (ordered by priority)
983 ## CATEGORY:CODING-SYSTEM
986 (let ((l coding-category-list
))
988 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
993 ;; Print information of a font in FONTINFO.
994 (defun describe-font-internal (font-info &optional verbose
)
995 (print-list "name (opened by):" (aref font-info
0))
996 (print-list " full name:" (aref font-info
1))
997 (print-list " size:" (format "%2d" (aref font-info
2)))
998 (print-list " height:" (format "%2d" (aref font-info
3)))
999 (print-list " baseline-offset:" (format "%2d" (aref font-info
4)))
1000 (print-list "relative-compose:" (format "%2d" (aref font-info
5))))
1003 (defun describe-font (fontname)
1004 "Display information about fonts which partially match FONTNAME."
1005 (interactive "sFontname (default, current choice for ASCII chars): ")
1006 (or (and window-system
(fboundp 'fontset-list
))
1007 (error "No fontsets being used"))
1008 (when (or (not fontname
) (= (length fontname
) 0))
1009 (setq fontname
(cdr (assq 'font
(frame-parameters))))
1010 (if (query-fontset fontname
)
1012 (nth 1 (assq 'ascii
(fontset-info fontname
))))))
1013 (let ((font-info (font-info fontname
)))
1014 (if (null font-info
)
1015 (message "No matching font")
1016 (with-output-to-temp-buffer "*Help*"
1017 (describe-font-internal font-info
'verbose
)))))
1019 ;; Print information of FONTSET. If optional arg PRINT-FONTS is
1020 ;; non-nil, print also names of all opened fonts for FONTSET. This
1021 ;; function actually INSERT such information in the current buffer.
1022 (defun print-fontset (fontset &optional print-fonts
)
1023 (let ((tail (cdr (fontset-info fontset
)))
1024 elt chars font-spec opened prev-charset charset from to
)
1026 (insert "Fontset: " fontset
"\n")
1027 (insert "CHARSET or CHAR RANGE")
1029 (insert "FONT NAME\n")
1030 (insert "---------------------")
1032 (insert "---------")
1035 (setq elt
(car tail
) tail
(cdr tail
))
1036 (setq chars
(car elt
) font-spec
(car (cdr elt
)) opened
(cdr (cdr elt
)))
1038 (setq charset chars from nil to nil
)
1039 (if (integerp chars
)
1040 (setq charset
(char-charset chars
) from chars to chars
)
1041 (setq charset
(char-charset (car chars
))
1042 from
(car chars
) to
(cdr chars
))))
1043 (unless (eq charset prev-charset
)
1044 (insert (symbol-name charset
))
1048 (let ((split (split-char from
)))
1049 (if (and (= (charset-dimension charset
) 2)
1050 (= (nth 2 split
) 0))
1052 (make-char charset
(nth 1 split
)
1053 (if (= (charset-chars charset
) 94) 33 32))))
1057 (let ((split (split-char to
)))
1058 (if (and (= (charset-dimension charset
) 2)
1059 (= (nth 2 split
) 0))
1061 (make-char charset
(nth 1 split
)
1062 (if (= (charset-chars charset
) 94) 126 127))))
1065 (if (stringp font-spec
)
1068 (if (string-match "-" (car font-spec
))
1069 (insert "-" (car font-spec
) "-")
1070 (insert "-*-" (car font-spec
) "-"))
1073 (if (string-match "-" (cdr font-spec
))
1074 (insert (cdr font-spec
))
1075 (insert (cdr font-spec
) "-*"))
1081 (insert "[" (car opened
) "]\n")
1082 (setq opened
(cdr opened
))))
1083 (setq prev-charset charset
)
1087 (defun describe-fontset (fontset)
1088 "Display information of FONTSET.
1089 This shows which font is used for which character(s)."
1091 (if (not (and window-system
(fboundp 'fontset-list
)))
1092 (error "No fontsets being used")
1093 (let ((fontset-list (append
1094 (mapcar '(lambda (x) (list x
)) (fontset-list))
1095 (mapcar '(lambda (x) (list (cdr x
)))
1096 fontset-alias-alist
)))
1097 (completion-ignore-case t
))
1098 (list (completing-read
1099 "Fontset (default, used by the current frame): "
1100 fontset-list nil t
)))))
1101 (if (= (length fontset
) 0)
1102 (setq fontset
(cdr (assq 'font
(frame-parameters)))))
1103 (if (not (setq fontset
(query-fontset fontset
)))
1104 (error "Current frame is using font, not fontset"))
1105 (with-output-to-temp-buffer "*Help*"
1107 (set-buffer standard-output
)
1108 (print-fontset fontset t
))))
1111 (defun list-fontsets (arg)
1112 "Display a list of all fontsets.
1113 This shows the name, size, and style of each fontset.
1114 With prefix arg, it also list the fonts contained in each fontset;
1115 see the function `describe-fontset' for the format of the list."
1117 (if (not (and window-system
(fboundp 'fontset-list
)))
1118 (error "No fontsets being used")
1119 (with-output-to-temp-buffer "*Help*"
1121 ;; This code is duplicated near the end of mule-diag.
1122 (set-buffer standard-output
)
1124 (sort (fontset-list)
1125 (function (lambda (x y
)
1126 (string< (fontset-plain-name x
)
1127 (fontset-plain-name y
)))))))
1130 (print-fontset (car fontsets
) nil
)
1131 (insert "Fontset: " (car fontsets
) "\n"))
1132 (setq fontsets
(cdr fontsets
))))))))
1135 (defun list-input-methods ()
1136 "Display information about all input methods."
1138 (with-output-to-temp-buffer "*Help*"
1139 (list-input-methods-1)))
1141 (defun list-input-methods-1 ()
1142 (if (not input-method-alist
)
1145 No input method is available, perhaps because you have not yet
1146 installed LEIM (Libraries of Emacs Input Method).
1148 LEIM is available from the same ftp directory as Emacs. For instance,
1149 if there exists an archive file `emacs-20.N.tar.gz', there should also
1150 be a file `leim-20.N.tar.gz'. When you extract this file, LEIM files
1151 are put under the subdirectory `emacs-20.N/leim'. When you install
1152 Emacs again, you should be able to use various input methods."))
1153 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1154 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1155 (setq input-method-alist
1156 (sort input-method-alist
1157 (function (lambda (x y
) (string< (nth 1 x
) (nth 1 y
))))))
1158 (let ((l input-method-alist
)
1161 (setq elt
(car l
) l
(cdr l
))
1162 (when (not (equal language
(nth 1 elt
)))
1163 (setq language
(nth 1 elt
))
1166 (princ (format " %s (`%s' in mode line)\n %s\n"
1168 (let ((title (nth 3 elt
)))
1169 (if (and (consp title
) (stringp (car title
)))
1172 (let ((description (nth 4 elt
)))
1173 (string-match ".*" description
)
1174 (match-string 0 description
))))))))
1178 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1179 (defun insert-section (section-number title
)
1180 (insert "########################################\n"
1181 "# Section " (format "%d" section-number
) ". " title
"\n"
1182 "########################################\n\n"))
1186 "Display diagnosis of the multilingual environment (Mule).
1188 This shows various information related to the current multilingual
1189 environment, including lists of input methods, coding systems,
1190 character sets, and fontsets (if Emacs is running under a window
1191 system which uses fontsets)."
1193 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1195 (set-buffer standard-output
)
1196 (insert "###############################################\n"
1197 "### Current Status of Multilingual Features ###\n"
1198 "###############################################\n\n"
1199 "CONTENTS: Section 1. General Information\n"
1200 " Section 2. Display\n"
1201 " Section 3. Input methods\n"
1202 " Section 4. Coding systems\n"
1203 " Section 5. Character sets\n")
1204 (if (and window-system
(fboundp 'fontset-list
))
1205 (insert " Section 6. Fontsets\n"))
1208 (insert-section 1 "General Information")
1209 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1211 (insert-section 2 "Display")
1213 (insert "Window-system: "
1214 (symbol-name window-system
)
1215 (format "%s" window-system-version
))
1216 (insert "Terminal: " (getenv "TERM")))
1219 (if (eq window-system
'x
)
1220 (let ((font (cdr (assq 'font
(frame-parameters)))))
1221 (insert "The selected frame is using the "
1222 (if (query-fontset font
) "fontset" "font")
1224 (insert "Coding system of the terminal: "
1225 (symbol-name (terminal-coding-system))))
1228 (insert-section 3 "Input methods")
1229 (list-input-methods-1)
1231 (if default-input-method
1232 (insert (format "Default input method: %s\n" default-input-method
))
1233 (insert "No default input method is specified\n"))
1235 (insert-section 4 "Coding systems")
1236 (list-coding-systems-1 t
)
1238 ############################
1239 ## LIST OF CODING CATEGORIES (ordered by priority)
1240 ## CATEGORY:CODING-SYSTEM
1243 (let ((l coding-category-list
))
1245 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
1249 (insert-section 5 "Character sets")
1250 (list-character-sets-2)
1253 (when (and window-system
(fboundp 'fontset-list
))
1254 ;; This code duplicates most of list-fontsets.
1255 (insert-section 6 "Fontsets")
1256 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1257 (insert "------------\t\t\t\t\t\t ----- -----\n")
1258 (let ((fontsets (fontset-list)))
1260 (print-fontset (car fontsets
) t
)
1261 (setq fontsets
(cdr fontsets
)))))
1262 (print-help-return-message))))
1268 (defun dump-charsets ()
1269 "Dump information about all charsets into the file `CHARSETS'.
1270 The file is saved in the directory `data-directory'."
1271 (let ((file (expand-file-name "CHARSETS" data-directory
))
1273 (or (file-writable-p file
)
1274 (error "Can't write to file %s" file
))
1275 (setq buf
(find-file-noselect file
))
1276 (save-window-excursion
1279 (setq buffer-read-only nil
)
1281 (list-character-sets-2)
1282 (insert-buffer-substring "*Help*")
1283 (let (make-backup-files
1284 coding-system-for-write
)
1291 (defun dump-codings ()
1292 "Dump information about all coding systems into the file `CODINGS'.
1293 The file is saved in the directory `data-directory'."
1294 (let ((file (expand-file-name "CODINGS" data-directory
))
1296 (or (file-writable-p file
)
1297 (error "Can't write to file %s" file
))
1298 (setq buf
(find-file-noselect file
))
1299 (save-window-excursion
1302 (setq buffer-read-only nil
)
1304 (list-coding-systems t
)
1305 (insert-buffer-substring "*Help*")
1306 (list-coding-categories)
1307 (insert-buffer-substring "*Help*")
1308 (let (make-backup-files
1309 coding-system-for-write
)
1315 ;;; mule-diag.el ends here