1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H14PRO021
10 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 3, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
33 ;; Make sure the help-xref button type is defined.
36 ;;; General utility function
38 ;; Print all arguments with single space separator in one line.
39 (defun print-list (&rest args
)
44 (setq args
(cdr args
)))
48 ;; Re-order the elements of charset-list.
49 (defun sort-charset-list ()
52 (lambda (x y
) (< (charset-id x
) (charset-id y
))))))
56 (define-button-type 'sort-listed-character-sets
57 'help-echo
(purecopy "mouse-2, RET: sort on this column")
59 'action
#'(lambda (button)
60 (sort-listed-character-sets (button-get button
'sort-key
))))
62 (define-button-type 'list-charset-chars
64 'help-function
#'list-charset-chars
65 'help-echo
"mouse-2, RET: show table of characters for this character set")
68 (defvar non-iso-charset-alist
70 (ascii latin-iso8859-1 mule-unicode-2500-33ff
71 mule-unicode-0100-24ff mule-unicode-e000-ffff
)
75 (ascii vietnamese-viscii-lower vietnamese-viscii-upper
)
76 viet-viscii-nonascii-translation-table
79 (ascii vietnamese-viscii-lower vietnamese-viscii-upper
)
80 viet-tcvn-nonascii-translation-table
83 (ascii cyrillic-iso8859-5
)
84 cyrillic-koi8-r-nonascii-translation-table
87 (ascii cyrillic-iso8859-5
)
88 cyrillic-alternativnyj-nonascii-translation-table
91 (ascii cyrillic-iso8859-5 mule-unicode-0100-24ff
)
92 cyrillic-koi8-u-nonascii-translation-table
95 (ascii chinese-big5-1 chinese-big5-2
)
98 ((?
\xA1 ?
\xFE) .
(?
\x40 ?
\x7E ?
\xA1 ?
\xFE))))
100 (ascii katakana-jisx0201 japanese-jisx0208
)
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
111 Each element has the following format:
112 (CHARSET CHARSET-LIST TRANSLATION-METHOD [ CODE-RANGE ])
114 CHARSET is the name (symbol) of the charset.
116 CHARSET-LIST is a list of Emacs charsets into which characters of
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.
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 ...)
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
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.")
135 (defun list-character-sets (arg)
136 "Display a list of all character sets.
138 The ID-NUM column contains a charset identification number for
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
144 `xx' stands for any byte in the range 0..127.
145 `XX' stands for any byte in the range 160..255.
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.
152 With prefix arg, the output format gets more cryptic,
153 but still shows the full information."
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
159 (list-character-sets-2)
161 (insert "Indirectly supported character sets are shown below.\n")
163 (substitute-command-keys
165 (if (display-mouse-p) "\\[help-follow-mouse] or ")
166 "\\[help-follow]:\n")))
167 (insert " on a column title to sort by that title,")
169 (insert "+----DIMENSION\n")
170 (insert " on a charset name to list characters.")
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
)))
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
)))
187 (insert "------\t------------\t\t\t--------------\t- -- ----------\n")
189 ;; Insert body sorted by charset IDs.
190 (list-character-sets-1 'id
)
192 ;; Insert non-directly-supported charsets.
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
)))
202 (dolist (e (nth 1 elt
))
203 (when (>= (+ (current-column) 1 (string-width (symbol-name e
)))
204 ;; This is an approximate value. We don't know
205 ;; the correct window width of this buffer yet.
210 (insert (format "%s " e
)))
213 (defun sort-listed-character-sets (sort-key)
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]")
222 (search-forward "----------")
225 (narrow-to-region pos
(point))
226 (delete-region (point-min) (point-max))
227 (list-character-sets-1 sort-key
)))))))
229 (defun charset-multibyte-form-string (charset)
230 (let ((info (charset-info charset
)))
231 (cond ((eq charset
'ascii
)
233 ((eq charset
'eight-bit-control
)
234 (format "%2X Xx" (aref info
6)))
235 ((eq charset
'eight-bit-graphic
)
238 (let ((str (format "%2X" (aref info
6))))
239 (if (> (aref info
7) 0)
240 (setq str
(format "%s %2X"
242 (setq str
(concat str
" XX"))
243 (if (> (aref info
2) 1)
244 (setq str
(concat str
" XX")))
247 ;; Insert a list of character sets sorted by SORT-KEY. SORT-KEY
248 ;; should be one of `id', `name', and `iso-spec'. If SORT-KEY is nil,
249 ;; it defaults to `id'.
251 (defun list-character-sets-1 (sort-key)
254 (let ((tail (charset-list))
255 charset-info-list elt charset info sort-func
)
257 (setq charset
(car tail
) tail
(cdr tail
)
258 info
(charset-info charset
))
260 ;; Generate a list that contains all information to display.
261 (setq charset-info-list
262 (cons (list (charset-id charset
) ; ID-NUM
263 charset
; CHARSET-NAME
264 (charset-multibyte-form-string charset
); MULTIBYTE-FORM
265 (aref info
2) ; DIMENSION
266 (aref info
3) ; CHARS
267 (aref info
8) ; FINAL-CHAR
271 ;; Determine a predicate for `sort' by SORT-KEY.
273 (cond ((eq sort-key
'id
)
274 (lambda (x y
) (< (car x
) (car y
))))
277 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
))))
279 ((eq sort-key
'iso-spec
)
280 ;; Sort by DIMENSION CHARS FINAL-CHAR
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
))))))))
288 (error "Invalid charset sort key: %s" sort-key
))))
290 (setq charset-info-list
(sort charset-info-list sort-func
))
292 ;; Insert information of character sets.
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
))) ; ID-NUM
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))
304 (insert (nth 2 elt
)) ; MULTIBYTE-FORM
306 (insert (format "%d %2d " (nth 3 elt
) (nth 4 elt
)) ; DIMENSION and CHARS
307 (if (< (nth 5 elt
) 0) "none" (nth 5 elt
))) ; FINAL-CHAR
311 ;; List all character sets in a form that a program can easily parse.
313 (defun list-character-sets-2 ()
314 (insert "#########################
316 ## Each line corresponds to one charset.
317 ## The following attributes are listed in this order
318 ## separated by a colon `:' in one line.
320 ## CHARSET-SYMBOL-NAME,
321 ## DIMENSION (1 or 2)
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)
330 (let ((l charset-list
)
333 (setq charset
(car l
) l
(cdr l
))
334 (princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n"
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
))))))
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
))
354 (decode-coding-string (char-to-string code
) coding-system
))))
356 ;; A variable to hold charset input history.
357 (defvar charset-history nil
)
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'.
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
)))
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
379 (if (> (length charset
) 0)
383 ;; List characters of the range MIN and MAX of CHARSET. If dimension
384 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
385 ;; (block index) of the characters, and MIN and MAX are the second
386 ;; bytes of the characters. If the dimension is one, ROW should be 0.
387 ;; For a non-ISO charset, CHARSET is a translation table (symbol) or a
388 ;; function to get Emacs' character codes that corresponds to the
389 ;; characters to list.
391 (defun list-block-of-chars (charset row min max
)
393 (insert-char ?-
(+ 4 (* 3 16)))
397 (insert (format "%3X" i
))
399 (setq i
(* (/ min
16) 16))
402 (insert (format "\n%3Xx" (/ (+ (* row
256) i
) 16))))
403 (setq ch
(cond ((< i min
)
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 ;; Don't insert a control code.
416 (unless ch
(setq ch
32))
419 (setq ch
(propertize "\t" 'display
"^I")))
420 ;; This doesn't DTRT. Maybe it's better to insert "^J" and not
421 ;; worry about the buffer contents not being correct.
423 ;;; (setq ch (propertize "\n" 'display "^J")))
424 (indent-to (+ (* (% i
16) 3) 6))
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
))
434 (insert (format "Characters in the coded character set %s.\n" charset
))
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))
442 (setq min
33 max
126)
443 (setq min
32 max
127))
445 (setq min
(+ min
128) max
(+ max
128)))))
448 (list-block-of-chars charset
0 min max
)
451 (list-block-of-chars charset i min max
)
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
))
462 (error "Unknown character set: %s" charset
))
463 (insert (format "Characters in the coded character set %s.\n" charset
))
465 (insert "They are mapped to: "
466 (mapconcat #'symbol-name charsets
", ")
469 (setq range
(pop ranges
))
470 (if (integerp (car range
))
471 ;; The form of RANGES is (FROM1 TO1 FROM2 TO2 ...).
472 (if (and (not (functionp translate-method
))
473 (< (car (last range
)) 256))
474 ;; Do it all in one block to avoid the listing being
475 ;; broken up at gaps in the range. Don't do that for
476 ;; function translate-method, since not all codes in
477 ;; that range may be valid.
478 (list-block-of-chars translate-method
479 0 (car range
) (car (last range
)))
481 (list-block-of-chars translate-method
482 0 (car range
) (nth 1 range
))
483 (setq range
(nthcdr 2 range
))))
484 ;; The form of RANGES is ((FROM1-1 TO1-1 ...) . (FROM2-1 TO2-1 ...)).
485 (let ((row-range (car range
))
487 col-range col col-max
)
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
))
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
)))))))))
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
)))
513 (cons (format " (%s)" charset
)
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
))
522 (error "Invalid character set %s" charset
))))))
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") ; description
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"
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
)))
553 (insert (format "Preferred coding system: %s\n" coding
))
554 (search-backward (symbol-name coding
))
555 (help-xref-button 0 'help-coding-system coding
)))))))
559 ;; Print information of designation of each graphic register in FLAGS
560 ;; in human readable format. See the documentation of
561 ;; `make-coding-system' for the meaning of FLAGS.
562 (defun print-designation (flags)
563 (let ((graphic-register 0)
565 (while (< graphic-register
4)
566 (setq charset
(aref flags graphic-register
))
570 (cond ((null charset
)
573 "no initial designation, and used by any charsets")
576 charset
(charset-description charset
)))
578 (if (charsetp (car charset
))
579 (format "%s:%s, and also used by the following:"
581 (charset-description (car charset
)))
582 "no initial designation, and used by the following:"))
584 "invalid designation information"))))
585 (when (listp charset
)
586 (setq charset
(cdr charset
))
588 (cond ((eq (car charset
) t
)
589 (princ "\tany other charsets\n"))
590 ((charsetp (car charset
))
591 (princ (format "\t%s:%s\n"
593 (charset-description (car charset
)))))
595 "invalid designation information"))
596 (setq charset
(cdr charset
))))
597 (setq graphic-register
(1+ graphic-register
)))))
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
)
607 (with-output-to-temp-buffer (help-buffer)
608 (print-coding-system-briefly coding-system
'doc-string
)
610 (let ((vars (coding-system-get coding-system
'dependency
)))
612 (princ "See also the documentation of these customizable variables
613 which alter the behavior of this coding system.\n")
621 (let ((type (coding-system-type coding-system
))
622 (flags (coding-system-flags coding-system
)))
625 (princ " (do no conversion)"))
627 (princ " (do automatic conversion)"))
629 (princ " (Emacs internal multibyte form)"))
631 (princ " (Shift-JIS, MS-KANJI)"))
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"))
654 (princ " (do conversion by CCL program)"))
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")
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
)))
670 (princ "After decoding text normally,")
671 (princ " perform post-conversion using the function: ")
675 (let ((prewrite (coding-system-get coding-system
'pre-write-conversion
)))
677 (princ "Before encoding text normally,")
678 (princ " perform pre-conversion using the function: ")
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
)))
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 ")
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
))))))))))
700 (defun describe-current-coding-system-briefly ()
701 "Display coding systems currently used in a brief format in echo area.
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
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'"
723 (let* ((proc (get-buffer-process (current-buffer)))
724 (process-coding-systems (if proc
(process-coding-system proc
))))
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
))
745 ;; Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
746 ;; If DOC-STRING is non-nil, print also the docstring of CODING-SYSTEM.
747 ;; If DOC-STRING is `tightly', don't print an empty line before the
748 ;; docstring, and print only the first line of the docstring.
750 (defun print-coding-system-briefly (coding-system &optional doc-string
)
751 (if (not coding-system
)
753 (princ (format "%c -- %s"
754 (coding-system-mnemonic coding-system
)
756 (let ((aliases (coding-system-get coding-system
'alias-coding-systems
)))
757 (cond ((eq coding-system
(car aliases
))
759 (princ (format " %S" (cons 'alias
: (cdr aliases
))))))
760 ((memq coding-system aliases
)
761 (princ (format " (alias of %s)" (car aliases
))))
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
))))))))
771 (or (eq doc-string
'tightly
)
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
))))))
782 (defun describe-current-coding-system ()
783 "Display coding systems currently used, in detail."
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 (print-coding-system-briefly default-buffer-file-coding-system
)
794 (princ "Coding system for keyboard input:\n ")
795 (print-coding-system-briefly (keyboard-coding-system))
796 (princ "Coding system for terminal output:\n ")
797 (print-coding-system-briefly (terminal-coding-system))
798 (when (get-buffer-process (current-buffer))
799 (princ "Coding systems for process I/O:\n")
800 (princ " encoding input to the process: ")
801 (print-coding-system-briefly (cdr process-coding-systems
))
802 (princ " decoding output from the process: ")
803 (print-coding-system-briefly (car process-coding-systems
)))
804 (princ "Defaults for subprocess I/O:\n")
805 (princ " decoding: ")
806 (print-coding-system-briefly (car default-process-coding-system
))
807 (princ " encoding: ")
808 (print-coding-system-briefly (cdr default-process-coding-system
)))
810 (with-current-buffer standard-output
813 Priority order for recognizing coding systems when reading files:\n")
814 (let ((l coding-category-list
)
819 (setq coding
(symbol-value (car l
)))
820 ;; Do not list up the same coding system twice.
821 (when (and coding
(not (memq coding coding-list
)))
822 (setq coding-list
(cons coding coding-list
))
823 (princ (format " %d. %s " i coding
))
824 (setq aliases
(coding-system-get coding
'alias-coding-systems
))
825 (if (eq coding
(car aliases
))
827 (princ (cons 'alias
: (cdr aliases
))))
828 (if (memq coding aliases
)
829 (princ (list 'alias
'of
(car aliases
)))))
834 (princ "\n Other coding systems cannot be distinguished automatically
835 from these, and therefore cannot be recognized automatically
836 with the present coding system priorities.\n\n")
838 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
839 coding-system codings
)
841 (setq coding-system
(symbol-value (car categories
)))
844 (if (and (not (eq x coding-system
))
845 (coding-system-get x
'no-initial-designation
)
846 (let ((flags (coding-system-flags x
)))
847 (not (or (aref flags
10) (aref flags
11)))))
848 (setq codings
(cons x codings
))))
849 (get (car categories
) 'coding-systems
))
851 (let ((max-col (window-width))
854 The following are decoded correctly but recognized as %s:\n "
858 (insert (format " %s" (car codings
)))
859 (when (> (current-column) max-col
)
862 (goto-char (point-max)))
863 (setq codings
(cdr codings
)))
865 (setq categories
(cdr categories
))))
867 (princ "Particular coding systems specified for certain file names:\n")
869 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
870 (princ " ---------\t--------------\t\t----------------\n")
871 (let ((func (lambda (operation alist
)
875 (princ "\tnothing specified\n")
878 (prin1 (car (car alist
)))
879 (if (>= (current-column) 40)
882 (princ (cdr (car alist
)))
884 (setq alist
(cdr alist
)))))))
885 (funcall func
"File I/O" file-coding-system-alist
)
886 (funcall func
"Process I/O" process-coding-system-alist
)
887 (funcall func
"Network I/O" network-coding-system-alist
))
890 ;; Print detailed information on CODING-SYSTEM.
891 (defun print-coding-system (coding-system)
892 (let ((type (coding-system-type coding-system
))
893 (eol-type (coding-system-eol-type coding-system
))
894 (flags (coding-system-flags coding-system
))
895 (aliases (coding-system-get coding-system
'alias-coding-systems
)))
896 (if (not (eq (car aliases
) coding-system
))
897 (princ (format "%s (alias of %s)\n" coding-system
(car aliases
)))
898 (princ coding-system
)
899 (setq aliases
(cdr aliases
))
902 (princ (car aliases
))
903 (setq aliases
(cdr aliases
)))
904 (princ (format ":%s:%c:%d:"
906 (coding-system-mnemonic coding-system
)
907 (if (integerp eol-type
) eol-type
3)))
908 (cond ((eq type
2) ; ISO-2022
912 (setq charset
(aref flags idx
))
913 (cond ((null charset
)
921 (princ (car charset
))
922 (setq charset
(cdr charset
))
925 (princ (car charset
))
926 (setq charset
(cdr charset
)))
931 (princ (if (aref flags idx
) 1 0))
934 (princ (if (aref flags idx
) 1 0))))
937 (if (symbolp (car flags
))
938 (princ (format " %s" (car flags
)))
939 (setq i
0 len
(length (car flags
)))
941 (princ (format " %x" (aref (car flags
) i
)))
944 (if (symbolp (cdr flags
))
945 (princ (format "%s" (cdr flags
)))
946 (setq i
0 len
(length (cdr flags
)))
948 (princ (format " %x" (aref (cdr flags
) i
)))
952 (princ (coding-system-doc-string coding-system
))
956 (defun list-coding-systems (&optional arg
)
957 "Display a list of all coding systems.
958 This shows the mnemonic letter, name, and description of each coding system.
960 With prefix arg, the output format gets more cryptic,
961 but still contains full information about each coding system."
963 (with-output-to-temp-buffer "*Help*"
964 (list-coding-systems-1 arg
)))
966 (defun list-coding-systems-1 (arg)
969 ###############################################
970 # List of coding systems in the following format:
971 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
975 #########################
976 ## LIST OF CODING SYSTEMS
977 ## Each line corresponds to one coding system
978 ## Format of a line is:
979 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
980 ## :PRE-WRITE-CONVERSION:DOC-STRING,
982 ## NAME = coding system name
983 ## ALIAS = alias of the coding system
984 ## TYPE = nil (no conversion), t (undecided or automatic detection),
985 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
986 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
989 ## comma (`,') separated data of the following:
990 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
991 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
992 ## else if TYPE = 4 then
993 ## comma (`,') separated CCL programs for read and write
996 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
999 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only
)))
1001 (print-coding-system-briefly coding-system
'tightly
)
1002 (print-coding-system coding-system
)))
1004 (dolist (elt coding-system-alist
)
1005 (unless (memq (intern (car elt
)) coding-system-list
)
1008 ####################################################
1009 # The following coding systems are not yet loaded. #
1010 ####################################################
1013 (princ-list (car elt
))))))
1016 (defun list-coding-categories ()
1017 "Display a list of all coding categories."
1018 (with-output-to-temp-buffer "*Help*"
1020 ############################
1021 ## LIST OF CODING CATEGORIES (ordered by priority)
1022 ## CATEGORY:CODING-SYSTEM
1025 (let ((l coding-category-list
))
1027 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
1028 (setq l
(cdr l
))))))
1032 ;; Print information of a font in FONTINFO.
1033 (defun describe-font-internal (font-info &optional verbose
)
1034 (print-list "name (opened by):" (aref font-info
0))
1035 (print-list " full name:" (aref font-info
1))
1036 (print-list " size:" (format "%2d" (aref font-info
2)))
1037 (print-list " height:" (format "%2d" (aref font-info
3)))
1038 (print-list " baseline-offset:" (format "%2d" (aref font-info
4)))
1039 (print-list "relative-compose:" (format "%2d" (aref font-info
5))))
1042 (defun describe-font (fontname)
1043 "Display information about a font whose name is FONTNAME.
1044 The font must be already used by Emacs."
1045 (interactive "sFont name (default current choice for ASCII chars): ")
1046 (or (and window-system
(fboundp 'fontset-list
))
1047 (error "No fonts being used"))
1048 (let (fontset font-info
)
1049 (when (or (not fontname
) (= (length fontname
) 0))
1050 (setq fontname
(frame-parameter nil
'font
))
1051 ;; Check if FONTNAME is a fontset.
1052 (if (query-fontset fontname
)
1053 (setq fontset fontname
1054 fontname
(nth 1 (assq 'ascii
1055 (aref (fontset-info fontname
) 2))))))
1056 (setq font-info
(font-info fontname
))
1057 (if (null font-info
)
1059 ;; The font should be surely used. So, there's some
1060 ;; problem about getting information about it. It is
1061 ;; better to print the fontname to show which font has
1063 (message "No information about \"%s\"" fontname
)
1064 (message "No matching font being used"))
1065 (with-output-to-temp-buffer "*Help*"
1066 (describe-font-internal font-info
'verbose
)))))
1068 (defun print-fontset (fontset &optional print-fonts
)
1069 "Print information about FONTSET.
1070 If FONTSET is nil, print information about the default fontset.
1071 If optional arg PRINT-FONTS is non-nil, also print names of all opened
1072 fonts for FONTSET. This function actually inserts the information in
1073 the current buffer."
1075 (setq fontset
(query-fontset "fontset-default")))
1076 (let ((tail (aref (fontset-info fontset
) 2))
1077 elt chars font-spec opened prev-charset charset from to
)
1079 (insert "Fontset: " fontset
"\n")
1080 (insert "CHARSET or CHAR RANGE")
1082 (insert "FONT NAME\n")
1083 (insert "---------------------")
1085 (insert "---------")
1088 (setq elt
(car tail
) tail
(cdr tail
))
1089 (setq chars
(car elt
) font-spec
(car (cdr elt
)) opened
(cdr (cdr elt
)))
1091 (setq charset chars from nil to nil
)
1092 (if (integerp chars
)
1093 (setq charset
(char-charset chars
) from chars to chars
)
1094 (setq charset
(char-charset (car chars
))
1095 from
(car chars
) to
(cdr chars
))))
1096 (unless (eq charset prev-charset
)
1097 (insert (symbol-name charset
))
1101 (let ((split (split-char from
)))
1102 (if (and (= (charset-dimension charset
) 2)
1103 (= (nth 2 split
) 0))
1105 (make-char charset
(nth 1 split
)
1106 (if (= (charset-chars charset
) 94) 33 32))))
1110 (let ((split (split-char to
)))
1111 (if (and (= (charset-dimension charset
) 2)
1112 (= (nth 2 split
) 0))
1114 (make-char charset
(nth 1 split
)
1115 (if (= (charset-chars charset
) 94) 126 127))))
1118 (if (stringp font-spec
)
1121 (if (string-match "-" (car font-spec
))
1122 (insert "-" (car font-spec
) "-*-")
1123 (insert "-*-" (car font-spec
) "-*-"))
1126 (if (string-match "-" (cdr font-spec
))
1127 (insert (cdr font-spec
))
1128 (insert (cdr font-spec
) "-*"))
1134 (insert "[" (car opened
) "]\n")
1135 (setq opened
(cdr opened
))))
1136 (setq prev-charset charset
)
1140 (defun describe-fontset (fontset)
1141 "Display information about FONTSET.
1142 This shows which font is used for which character(s)."
1144 (if (not (and window-system
(fboundp 'fontset-list
)))
1145 (error "No fontsets being used")
1146 (let ((fontset-list (nconc
1148 (mapcar 'cdr fontset-alias-alist
)))
1149 (completion-ignore-case t
))
1150 (list (completing-read
1151 "Fontset (default used by the current frame): "
1152 fontset-list nil t
)))))
1153 (if (= (length fontset
) 0)
1154 (setq fontset
(frame-parameter nil
'font
)))
1155 (setq fontset
(query-fontset fontset
))
1156 (help-setup-xref (list #'describe-fontset fontset
) (interactive-p))
1157 (with-output-to-temp-buffer (help-buffer)
1158 (with-current-buffer standard-output
1159 (print-fontset fontset t
))))
1162 (defun list-fontsets (arg)
1163 "Display a list of all fontsets.
1164 This shows the name, size, and style of each fontset.
1165 With prefix arg, also list the fonts contained in each fontset;
1166 see the function `describe-fontset' for the format of the list."
1168 (if (not (and window-system
(fboundp 'fontset-list
)))
1169 (error "No fontsets being used")
1170 (help-setup-xref (list #'list-fontsets arg
) (interactive-p))
1171 (with-output-to-temp-buffer (help-buffer)
1172 (with-current-buffer standard-output
1173 ;; This code is duplicated near the end of mule-diag.
1175 (sort (fontset-list)
1177 (string< (fontset-plain-name x
)
1178 (fontset-plain-name y
))))))
1181 (print-fontset (car fontsets
) nil
)
1182 (insert "Fontset: " (car fontsets
) "\n"))
1183 (setq fontsets
(cdr fontsets
))))))))
1186 (defun list-input-methods ()
1187 "Display information about all input methods."
1189 (help-setup-xref '(list-input-methods) (interactive-p))
1190 (with-output-to-temp-buffer (help-buffer)
1191 (list-input-methods-1)
1192 (with-current-buffer standard-output
1194 (goto-char (point-min))
1195 (while (re-search-forward
1196 "^ \\([^ ]+\\) (`.*' in mode line)$" nil t
)
1197 (help-xref-button 1 'help-input-method
(match-string 1)))))))
1199 (defun list-input-methods-1 ()
1200 (if (not input-method-alist
)
1203 No input method is available, perhaps because you have not
1204 installed LEIM (Libraries of Emacs Input Methods)."))
1205 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1206 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1207 (setq input-method-alist
1208 (sort input-method-alist
1209 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
1210 (let ((l input-method-alist
)
1213 (setq elt
(car l
) l
(cdr l
))
1214 (when (not (equal language
(nth 1 elt
)))
1215 (setq language
(nth 1 elt
))
1218 (princ (format " %s (`%s' in mode line)\n %s\n"
1220 (let ((title (nth 3 elt
)))
1221 (if (and (consp title
) (stringp (car title
)))
1224 (let ((description (nth 4 elt
)))
1225 (string-match ".*" description
)
1226 (match-string 0 description
))))))))
1230 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1231 (defun insert-section (section-number title
)
1232 (insert "########################################\n"
1233 "# Section " (format "%d" section-number
) ". " title
"\n"
1234 "########################################\n\n"))
1238 "Display diagnosis of the multilingual environment (Mule).
1240 This shows various information related to the current multilingual
1241 environment, including lists of input methods, coding systems,
1242 character sets, and fontsets (if Emacs is running under a window
1243 system which uses fontsets)."
1245 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1246 (with-current-buffer standard-output
1247 (insert "###############################################\n"
1248 "### Current Status of Multilingual Features ###\n"
1249 "###############################################\n\n"
1250 "CONTENTS: Section 1. General Information\n"
1251 " Section 2. Display\n"
1252 " Section 3. Input methods\n"
1253 " Section 4. Coding systems\n"
1254 " Section 5. Character sets\n")
1255 (if (and window-system
(fboundp 'fontset-list
))
1256 (insert " Section 6. Fontsets\n"))
1259 (insert-section 1 "General Information")
1260 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1261 (insert "Configuration options:\n " system-configuration-options
"\n\n")
1262 (insert "Multibyte characters awareness:\n"
1263 (format " default: %S\n" default-enable-multibyte-characters
)
1264 (format " current-buffer: %S\n\n" enable-multibyte-characters
))
1265 (insert "Current language environment: " current-language-environment
1268 (insert-section 2 "Display")
1270 (insert "Window-system: "
1271 (symbol-name window-system
)
1272 (format "%s" window-system-version
))
1273 (insert "Terminal: " (getenv "TERM")))
1276 (if (eq window-system
'x
)
1277 (let ((font (cdr (assq 'font
(frame-parameters)))))
1278 (insert "The selected frame is using the "
1279 (if (query-fontset font
) "fontset" "font")
1281 (insert "Coding system of the terminal: "
1282 (symbol-name (terminal-coding-system))))
1285 (insert-section 3 "Input methods")
1286 (list-input-methods-1)
1288 (if default-input-method
1289 (insert (format "Default input method: %s\n" default-input-method
))
1290 (insert "No default input method is specified\n"))
1292 (insert-section 4 "Coding systems")
1293 (list-coding-systems-1 t
)
1295 ############################
1296 ## LIST OF CODING CATEGORIES (ordered by priority)
1297 ## CATEGORY:CODING-SYSTEM
1300 (let ((l coding-category-list
))
1302 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
1306 (insert-section 5 "Character sets")
1307 (list-character-sets-2)
1310 (when (and window-system
(fboundp 'fontset-list
))
1311 ;; This code duplicates most of list-fontsets.
1312 (insert-section 6 "Fontsets")
1313 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1314 (insert "------------\t\t\t\t\t\t ----- -----\n")
1315 (let ((fontsets (fontset-list)))
1317 (print-fontset (car fontsets
) t
)
1318 (setq fontsets
(cdr fontsets
)))))
1319 (print-help-return-message))))
1321 (provide 'mule-diag
)
1323 ;;; arch-tag: cd3b607c-2893-45a0-a4fa-a6535754dbee
1324 ;;; mule-diag.el ends here