1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009 Free Software Foundation, Inc.
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 ;; 2005, 2006, 2007, 2008, 2009
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H14PRO021
10 ;; National Institute of Advanced Industrial Science and Technology (AIST)
11 ;; Registration Number H13PRO009
13 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
15 ;; This file is part of GNU Emacs.
17 ;; GNU Emacs is free software: you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation, either version 3 of the License, or
20 ;; (at your option) any later version.
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
34 ;; Make sure the help-xref button type is defined.
37 ;;; General utility function
39 (defun print-list (&rest args
)
40 "Print all arguments with single space separator in one line."
41 (princ (mapconcat (lambda (arg) (prin1-to-string arg t
)) args
" "))
46 (define-button-type 'sort-listed-character-sets
47 'help-echo
(purecopy "mouse-2, RET: sort on this column")
49 'action
#'(lambda (button)
50 (sort-listed-character-sets (button-get button
'sort-key
))))
52 (define-button-type 'list-charset-chars
54 'help-function
#'list-charset-chars
55 'help-echo
"mouse-2, RET: show table of characters for this character set")
58 (defun list-character-sets (arg)
59 "Display a list of all character sets.
61 The D column contains the dimension of this character set. The CH
62 column contains the number of characters in a block of this character
63 set. The FINAL-BYTE column contains an ISO-2022 <final-byte> to use
64 in the designation escape sequence for this character set in
65 ISO-2022-based coding systems.
67 With prefix ARG, the output format gets more cryptic,
68 but still shows the full information."
70 (help-setup-xref (list #'list-character-sets arg
) (interactive-p))
71 (with-output-to-temp-buffer "*Character Set List*"
72 (with-current-buffer standard-output
74 (list-character-sets-2)
76 (insert "Supplementary character sets are shown below.\n")
78 (substitute-command-keys
80 (if (display-mouse-p) "\\[help-follow-mouse] or ")
81 "\\[help-follow]:\n")))
82 (insert " on a column title to sort by that title,")
84 (insert "+----DIMENSION\n")
85 (insert " on a charset name to list characters.")
87 (insert "| +--CHARS\n")
88 (let ((columns '(("CHARSET-NAME" . name
) "\t\t\t\t\t"
89 ("D CH FINAL-BYTE" . iso-spec
)))
92 (if (stringp (car columns
))
93 (insert (car columns
))
94 (insert-text-button (car (car columns
))
95 :type
'sort-listed-character-sets
96 'sort-key
(cdr (car columns
)))
97 (goto-char (point-max)))
98 (setq columns
(cdr columns
)))
100 (insert "------------\t\t\t\t\t- --- ----------\n")
102 ;; Insert body sorted by charset IDs.
103 (list-character-sets-1 'name
)))))
105 (defun sort-listed-character-sets (sort-key)
108 (let ((buffer-read-only nil
))
109 (goto-char (point-min))
110 (search-forward "\n-")
112 (delete-region (point) (point-max))
113 (list-character-sets-1 sort-key
)))))
115 (defun list-character-sets-1 (sort-key)
116 "Insert a list of character sets sorted by SORT-KEY.
117 SORT-KEY should be `name' or `iso-spec' (default `name')."
119 (setq sort-key
'name
))
120 (let ((tail charset-list
)
121 charset-info-list supplementary-list charset sort-func
)
122 (dolist (charset charset-list
)
123 ;; Generate a list that contains all information to display.
124 (let ((elt (list charset
125 (charset-dimension charset
)
126 (charset-chars charset
)
127 (charset-iso-final-char charset
))))
128 (if (plist-get (charset-plist charset
) :supplementary-p
)
129 (push elt supplementary-list
)
130 (push elt charset-info-list
))))
132 ;; Determine a predicate for `sort' by SORT-KEY.
134 (cond ((eq sort-key
'name
)
135 (lambda (x y
) (string< (car x
) (car y
))))
137 ((eq sort-key
'iso-spec
)
138 ;; Sort by DIMENSION CHARS FINAL-CHAR
141 (or (< (nth 1 x
) (nth 1 y
))
142 (and (= (nth 1 x
) (nth 1 y
))
143 (or (< (nth 2 x
) (nth 2 y
))
144 (and (= (nth 2 x
) (nth 2 y
))
145 (< (nth 3 x
) (nth 3 y
)))))))))
147 (error "Invalid charset sort key: %s" sort-key
))))
149 (setq charset-info-list
(sort charset-info-list sort-func
))
150 (setq supplementary-list
(sort supplementary-list sort-func
))
152 ;; Insert information of character sets.
153 (dolist (elt (append charset-info-list
(list t
) supplementary-list
))
156 (insert "\n-------------- ")
157 (insert-text-button "Supplementary Character Sets"
159 'help-args
'("(emacs)Charsets"))
160 (insert " --------------
161 Character sets for defining another charset or obsolete now
163 (insert-text-button (symbol-name (car elt
)) ; NAME
164 :type
'list-charset-chars
165 'help-args
(list (car elt
)))
166 (goto-char (point-max))
169 (insert (format "%d %3d "
170 (nth 1 elt
) (nth 2 elt
)) ; DIMENSION and CHARS
171 (if (< (nth 3 elt
) 0)
173 (nth 3 elt
)))) ; FINAL-CHAR
177 ;; List all character sets in a form that a program can easily parse.
179 (defun list-character-sets-2 ()
180 (insert "#########################
182 ## Each line corresponds to one charset.
183 ## The following attributes are listed in this order
184 ## separated by a colon `:' in one line.
185 ## CHARSET-SYMBOL-NAME,
187 ## CHARS (number of characters in first dimension of charset)
188 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
189 ## -1 means that no final character is assigned.
190 ## DESCRIPTION (describing string of the charset)
192 (dolist (charset charset-list
)
193 (princ (format "%s:%d:%d:%d:%s\n"
195 (charset-dimension charset
)
196 (charset-chars charset
)
197 ;;; (char-width (make-char charset))
198 ;;; (charset-direction charset)
199 (charset-iso-final-char charset
)
200 ;;; (charset-iso-graphic-plane charset)
201 (charset-description charset
)))))
203 (defvar non-iso-charset-alist nil
205 (make-obsolete-variable 'non-iso-charset-alist
"no longer relevant." "23.1")
207 (defun decode-codepage-char (codepage code
)
208 "Decode a character that has code CODE in CODEPAGE.
209 Return a decoded character string. Each CODEPAGE corresponds to a
210 coding system cpCODEPAGE."
211 (decode-char (intern (format "cp%d" codepage
)) code
))
212 (make-obsolete 'decode-codepage-char
'decode-char
"23.1")
214 ;; A variable to hold charset input history.
215 (defvar charset-history nil
)
219 (defun read-charset (prompt &optional default-value initial-input
)
220 "Read a character set from the minibuffer, prompting with string PROMPT.
221 It must be an Emacs character set listed in the variable `charset-list'.
223 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
224 DEFAULT-VALUE, if non-nil, is the default value.
225 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
226 See the documentation of the function `completing-read' for the detailed
227 meanings of these arguments."
228 (let* ((table (mapcar (lambda (x) (list (symbol-name x
))) charset-list
))
229 (charset (completing-read prompt table
230 nil t initial-input
'charset-history
232 (if (> (length charset
) 0)
235 ;; List characters of the range MIN and MAX of CHARSET. If dimension
236 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
237 ;; (block index) of the characters, and MIN and MAX are the second
238 ;; bytes of the characters. If the dimension is one, ROW should be 0.
240 (defun list-block-of-chars (charset row min max
)
242 (insert-char ?-
(+ 7 (* 4 16)))
246 (insert (format "%4X" i
))
248 (setq i
(* (/ min
16) 16))
251 (insert (format "\n%6Xx" (/ (+ (* row
256) i
) 16))))
252 (setq ch
(if (< i min
)
254 (or (decode-char charset
(+ (* row
256) i
))
255 32))) ; gap in mapping
256 ;; Don't insert control codes, non-Unicode characters.
257 (if (or (< ch
32) (= ch
127))
258 (setq ch
(single-key-description ch
))
259 (if (and (>= ch
128) (< ch
160))
260 (setq ch
(format "%02Xh" ch
))
268 (defun list-charset-chars (charset)
269 "Display a list of characters in character set CHARSET."
270 (interactive (list (read-charset "Character set: ")))
271 (or (charsetp charset
)
272 (error "Invalid character set: %s" charset
))
273 (with-output-to-temp-buffer "*Character List*"
274 (with-current-buffer standard-output
275 (if (coding-system-p charset
)
276 ;; Useful to be able to do C-u C-x = to find file code, for
278 (set-buffer-file-coding-system charset
))
279 (setq mode-line-format
(copy-sequence mode-line-format
))
280 (let ((slot (memq 'mode-line-buffer-identification mode-line-format
)))
283 (cons (format " (%s)" charset
)
286 (set-buffer-multibyte t
)
287 (let ((dim (charset-dimension charset
))
288 (chars (charset-chars charset
))
289 ;; (plane (charset-iso-graphic-plane charset))
291 (range (plist-get (charset-plist charset
) :code-space
))
294 (error "Can only list 1- and 2-dimensional charsets"))
295 (insert (format "Characters in the coded character set %s.\n" charset
))
296 (narrow-to-region (point) (point))
297 (setq min
(aref range
0)
300 (list-block-of-chars charset
0 min max
)
301 (setq min2
(aref range
2)
305 (list-block-of-chars charset i min max
)
307 (put-text-property (point-min) (point-max) 'charset charset
)
312 (defun describe-character-set (charset)
313 "Display information about built-in character set CHARSET."
314 (interactive (list (read-charset "Charset: ")))
315 (or (charsetp charset
)
316 (error "Invalid charset: %S" charset
))
317 (help-setup-xref (list #'describe-character-set charset
) (interactive-p))
318 (with-output-to-temp-buffer (help-buffer)
319 (with-current-buffer standard-output
320 (insert "Character set: " (symbol-name charset
))
321 (let ((name (get-charset-property charset
:name
)))
322 (if (not (eq name charset
))
323 (insert " (alias of " (symbol-name name
) ?\
))))
324 (insert "\n\n" (charset-description charset
) "\n\n")
325 (insert "Number of contained characters: ")
326 (dotimes (i (charset-dimension charset
))
329 (insert (format "%d" (charset-chars charset
(1+ i
)))))
331 (let ((char (charset-iso-final-char charset
)))
333 (insert "Final char of ISO2022 designation sequence: ")
334 (insert (format "`%c'\n" char
))))
336 (dolist (c charset-list
)
337 (if (and (not (eq c charset
))
338 (eq charset
(get-charset-property c
:name
)))
341 (insert "Aliases: " (mapconcat #'symbol-name aliases
", ") ?
\n)))
343 (dolist (elt `((:ascii-compatible-p
"ASCII compatible." nil
)
344 (:map
"Map file: " identity
)
345 (:unify-map
"Unification map file: " identity
)
349 (format "Invalid character: %c (code %d)" c c
)))
350 (:emacs-mule-id
"Id in emacs-mule coding system: "
352 (:parents
"Parents: "
354 (mapconcat ,(lambda (elt)
358 (:code-space
"Code space: " ,(lambda (c)
360 (:code-offset
"Code offset: " number-to-string
)
361 (:iso-revision-number
"ISO revision number: "
364 "Used only as a parent of some other charset." nil
)))
365 (let ((val (get-charset-property charset
(car elt
))))
367 (if (cadr elt
) (insert (cadr elt
)))
369 (insert (funcall (nth 2 elt
) val
)))
374 (defvar graphic-register
) ; dynamic bondage
376 ;; Print information about designation of each graphic register in
377 ;; DESIGNATIONS in human readable format. See the documentation of
378 ;; `define-coding-system' for the meaning of DESIGNATIONS
379 ;; (`:designation' property).
380 (defun print-designation (designations)
382 (dotimes (graphic-register 4)
383 (setq charset
(aref designations graphic-register
))
387 (cond ((null charset
)
390 "no initial designation, and used by any charsets")
393 charset
(charset-description charset
)))
395 (if (charsetp (car charset
))
396 (format "%s:%s, and also used by the following:"
398 (charset-description (car charset
)))
399 "no initial designation, and used by the following:"))
401 "invalid designation information"))))
402 (when (listp charset
)
403 (setq charset
(cdr charset
))
405 (cond ((eq (car charset
) t
)
406 (princ "\tany other charsets\n"))
407 ((charsetp (car charset
))
408 (princ (format "\t%s:%s\n"
410 (charset-description (car charset
)))))
412 "invalid designation information"))
413 (setq charset
(cdr charset
)))))))
416 (defun describe-coding-system (coding-system)
417 "Display information about CODING-SYSTEM."
418 (interactive "zDescribe coding system (default current choices): ")
419 (if (null coding-system
)
420 (describe-current-coding-system)
421 (help-setup-xref (list #'describe-coding-system coding-system
)
423 (with-output-to-temp-buffer (help-buffer)
424 (print-coding-system-briefly coding-system
'doc-string
)
425 (let ((type (coding-system-type coding-system
))
427 (extra-spec (coding-system-plist coding-system
)))
430 (cond ((eq type
'undecided
)
431 (princ " (do automatic conversion)"))
433 (princ " (UTF-8: Emacs internal multibyte form)"))
435 ;; (princ " (UTF-16)")
437 ((eq type
'shift-jis
)
438 (princ " (Shift-JIS, MS-KANJI)"))
440 (princ " (variant of ISO-2022)\n")
441 (princ "Initial designations:\n")
442 (print-designation (coding-system-get coding-system
445 (when (coding-system-get coding-system
:flags
)
446 (princ "Other specifications: \n ")
448 (coding-system-get coding-system
:flags
))))
450 (princ " (charset)"))
452 (princ " (do conversion by CCL program)"))
454 (princ " (text with random binary characters)"))
455 ((eq type
'emacs-mule
)
456 (princ " (Emacs 21 internal encoding)"))
458 (t (princ ": invalid coding-system.")))
459 (princ "\nEOL type: ")
460 (let ((eol-type (coding-system-eol-type coding-system
)))
461 (cond ((vectorp eol-type
)
462 (princ "Automatic selection from:\n\t")
465 ((or (null eol-type
) (eq eol-type
0)) (princ "LF\n"))
466 ((eq eol-type
1) (princ "CRLF\n"))
467 ((eq eol-type
2) (princ "CR\n"))
468 (t (princ "invalid\n")))))
469 (let ((postread (coding-system-get coding-system
:post-read-conversion
)))
471 (princ "After decoding text normally,")
472 (princ " perform post-conversion using the function: ")
476 (let ((prewrite (coding-system-get coding-system
:pre-write-conversion
)))
478 (princ "Before encoding text normally,")
479 (princ " perform pre-conversion using the function: ")
483 (with-current-buffer standard-output
484 (let ((charsets (coding-system-charset-list coding-system
)))
485 (when (and (not (eq (coding-system-base coding-system
) 'raw-text
))
488 ((eq charsets
'iso-2022
)
489 (insert "This coding system can encode all ISO 2022 charsets."))
490 ((eq charsets
'emacs-mule
)
491 (insert "This coding system can encode all emacs-mule charsets\
494 (insert "This coding system encodes the following charsets:\n ")
496 (insert " " (symbol-name (car charsets
)))
497 (search-backward (symbol-name (car charsets
)))
498 (help-xref-button 0 'help-character-set
(car charsets
))
499 (goto-char (point-max))
500 (setq charsets
(cdr charsets
)))))))))))
503 (defun describe-current-coding-system-briefly ()
504 "Display coding systems currently used in a brief format in echo area.
506 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
507 where mnemonics of the following coding systems come in this order
509 `buffer-file-coding-system' (of the current buffer)
510 eol-type of `buffer-file-coding-system' (of the current buffer)
511 Value returned by `keyboard-coding-system'
512 eol-type of `keyboard-coding-system'
513 Value returned by `terminal-coding-system'.
514 eol-type of `terminal-coding-system'
515 `process-coding-system' for read (of the current buffer, if any)
516 eol-type of `process-coding-system' for read (of the current buffer, if any)
517 `process-coding-system' for write (of the current buffer, if any)
518 eol-type of `process-coding-system' for write (of the current buffer, if any)
519 default `buffer-file-coding-system'
520 eol-type of default `buffer-file-coding-system'
521 `default-process-coding-system' for read
522 eol-type of `default-process-coding-system' for read
523 `default-process-coding-system' for write
524 eol-type of `default-process-coding-system'"
526 (let* ((proc (get-buffer-process (current-buffer)))
527 (process-coding-systems (if proc
(process-coding-system proc
))))
529 "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]"
530 (coding-system-mnemonic buffer-file-coding-system
)
531 (coding-system-eol-type-mnemonic buffer-file-coding-system
)
532 (coding-system-mnemonic (keyboard-coding-system))
533 (coding-system-eol-type-mnemonic (keyboard-coding-system))
534 (coding-system-mnemonic (terminal-coding-system))
535 (coding-system-eol-type-mnemonic (terminal-coding-system))
536 (coding-system-mnemonic (car process-coding-systems
))
537 (coding-system-eol-type-mnemonic (car process-coding-systems
))
538 (coding-system-mnemonic (cdr process-coding-systems
))
539 (coding-system-eol-type-mnemonic (cdr process-coding-systems
))
540 (coding-system-mnemonic (default-value 'buffer-file-coding-system
))
541 (coding-system-eol-type-mnemonic
542 (default-value 'buffer-file-coding-system
))
543 (coding-system-mnemonic (car default-process-coding-system
))
544 (coding-system-eol-type-mnemonic (car default-process-coding-system
))
545 (coding-system-mnemonic (cdr default-process-coding-system
))
546 (coding-system-eol-type-mnemonic (cdr default-process-coding-system
))
549 (defun print-coding-system-briefly (coding-system &optional doc-string
)
550 "Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
551 If DOC-STRING is non-nil, print also the docstring of CODING-SYSTEM.
552 If DOC-STRING is `tightly', don't print an empty line before the
553 docstring, and print only the first line of the docstring."
554 (if (not coding-system
)
556 (princ (format "%c -- %s"
557 (coding-system-mnemonic coding-system
)
559 (let ((aliases (coding-system-aliases coding-system
)))
560 (cond ((eq coding-system
(car aliases
))
562 (princ (format " %S" (cons 'alias
: (cdr aliases
))))))
563 ((memq coding-system aliases
)
564 (princ (format " (alias of %s)" (car aliases
))))
566 (let ((eol-type (coding-system-eol-type coding-system
))
567 (base-eol-type (coding-system-eol-type (car aliases
))))
568 (if (and (integerp eol-type
)
569 (vectorp base-eol-type
)
570 (not (eq coding-system
(aref base-eol-type eol-type
))))
571 (princ (format " (alias of %s)"
572 (aref base-eol-type eol-type
))))))))
574 (or (eq doc-string
'tightly
)
577 (let ((doc (or (coding-system-doc-string coding-system
) "")))
578 (when (eq doc-string
'tightly
)
579 (if (string-match "\n" doc
)
580 (setq doc
(substring doc
0 (match-beginning 0))))
581 (setq doc
(concat " " doc
)))
582 (princ (format "%s\n" doc
))))))
585 (defun describe-current-coding-system ()
586 "Display coding systems currently used, in detail."
588 (with-output-to-temp-buffer "*Help*"
589 (let* ((proc (get-buffer-process (current-buffer)))
590 (process-coding-systems (if proc
(process-coding-system proc
))))
591 (princ "Coding system for saving this buffer:\n ")
592 (if (local-variable-p 'buffer-file-coding-system
)
593 (print-coding-system-briefly buffer-file-coding-system
)
594 (princ "Not set locally, use the default.\n"))
595 (princ "Default coding system (for new files):\n ")
596 (print-coding-system-briefly (default-value 'buffer-file-coding-system
))
597 (princ "Coding system for keyboard input:\n ")
598 (print-coding-system-briefly (keyboard-coding-system))
599 (princ "Coding system for terminal output:\n ")
600 (print-coding-system-briefly (terminal-coding-system))
601 (when (boundp 'selection-coding-system
)
602 (princ "Coding system for inter-client cut and paste:\n ")
603 (print-coding-system-briefly selection-coding-system
))
604 (when (get-buffer-process (current-buffer))
605 (princ "Coding systems for process I/O:\n")
606 (princ " encoding input to the process: ")
607 (print-coding-system-briefly (cdr process-coding-systems
))
608 (princ " decoding output from the process: ")
609 (print-coding-system-briefly (car process-coding-systems
)))
610 (princ "Defaults for subprocess I/O:\n")
611 (princ " decoding: ")
612 (print-coding-system-briefly (car default-process-coding-system
))
613 (princ " encoding: ")
614 (print-coding-system-briefly (cdr default-process-coding-system
)))
616 (with-current-buffer standard-output
619 Priority order for recognizing coding systems when reading files:\n")
621 (dolist (elt (coding-system-priority-list))
622 (princ (format " %d. %s " i elt
))
623 (let ((aliases (coding-system-aliases elt
)))
624 (if (eq elt
(car aliases
))
626 (princ (cons 'alias
: (cdr aliases
))))
627 (princ (list 'alias
'of
(car aliases
))))
631 (princ "\n Other coding systems cannot be distinguished automatically
632 from these, and therefore cannot be recognized automatically
633 with the present coding system priorities.\n\n")
635 ;; Fixme: should this be replaced or junked?
637 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
638 coding-system codings
)
640 (setq coding-system
(symbol-value (car categories
)))
643 (if (and (not (eq x coding-system
))
644 (let ((flags (coding-system-get :flags
)))
645 (not (or (memq 'use-roman flags
)
646 (memq 'use-oldjis flags
)))))
647 (setq codings
(cons x codings
))))
648 (get (car categories
) 'coding-systems
))
650 (let ((max-col (window-width))
653 The following are decoded correctly but recognized as %s:\n "
657 (insert (format " %s" (car codings
)))
658 (when (> (current-column) max-col
)
661 (goto-char (point-max)))
662 (setq codings
(cdr codings
)))
664 (setq categories
(cdr categories
)))))
666 (princ "Particular coding systems specified for certain file names:\n")
668 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
669 (princ " ---------\t--------------\t\t----------------\n")
670 (let ((func (lambda (operation alist
)
674 (princ "\tnothing specified\n")
677 (prin1 (car (car alist
)))
678 (if (>= (current-column) 40)
681 (princ (cdr (car alist
)))
683 (setq alist
(cdr alist
)))))))
684 (funcall func
"File I/O" file-coding-system-alist
)
685 (funcall func
"Process I/O" process-coding-system-alist
)
686 (funcall func
"Network I/O" network-coding-system-alist
))
689 (defun print-coding-system (coding-system)
690 "Print detailed information on CODING-SYSTEM."
691 (let ((type (coding-system-type coding-system
))
692 (eol-type (coding-system-eol-type coding-system
))
693 (flags (coding-system-get coding-system
:flags
))
694 (aliases (coding-system-aliases coding-system
)))
695 (if (not (eq (car aliases
) coding-system
))
696 (princ (format "%s (alias of %s)\n" coding-system
(car aliases
)))
697 (princ coding-system
)
698 (dolist (alias (cdr aliases
))
701 (princ (format ":%s:%c:%d:"
703 (coding-system-mnemonic coding-system
)
704 (if (integerp eol-type
) eol-type
3)))
705 (cond ((eq type
'iso2022
)
709 (setq charset
(aref flags idx
))
710 (cond ((null charset
)
718 (princ (car charset
))
719 (setq charset
(cdr charset
))
722 (princ (car charset
))
723 (setq charset
(cdr charset
)))
728 (princ (if (aref flags idx
) 1 0))
731 (princ (if (aref flags idx
) 1 0))))
734 (if (symbolp (car flags
))
735 (princ (format " %s" (car flags
)))
736 (setq i
0 len
(length (car flags
)))
738 (princ (format " %x" (aref (car flags
) i
)))
741 (if (symbolp (cdr flags
))
742 (princ (format "%s" (cdr flags
)))
743 (setq i
0 len
(length (cdr flags
)))
745 (princ (format " %x" (aref (cdr flags
) i
)))
749 (princ (coding-system-doc-string coding-system
))
753 (defun list-coding-systems (&optional arg
)
754 "Display a list of all coding systems.
755 This shows the mnemonic letter, name, and description of each coding system.
757 With prefix ARG, the output format gets more cryptic,
758 but still contains full information about each coding system."
760 (with-output-to-temp-buffer "*Help*"
761 (list-coding-systems-1 arg
)))
763 (defun list-coding-systems-1 (arg)
766 ###############################################
767 # List of coding systems in the following format:
768 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
772 #########################
773 ## LIST OF CODING SYSTEMS
774 ## Each line corresponds to one coding system
775 ## Format of a line is:
776 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
777 ## :PRE-WRITE-CONVERSION:DOC-STRING,
779 ## NAME = coding system name
780 ## ALIAS = alias of the coding system
781 ## TYPE = nil (no conversion), t (undecided or automatic detection),
782 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
783 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
786 ## comma (`,') separated data of the following:
787 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
788 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
789 ## else if TYPE = 4 then
790 ## comma (`,') separated CCL programs for read and write
793 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
796 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only
)))
798 (print-coding-system-briefly coding-system
'tightly
)
799 (print-coding-system coding-system
))))
803 (defun list-coding-categories ()
804 "Display a list of all coding categories."
805 (with-output-to-temp-buffer "*Help*"
807 ############################
808 ## LIST OF CODING CATEGORIES (ordered by priority)
809 ## CATEGORY:CODING-SYSTEM
812 (let ((l coding-category-list
))
814 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
819 (declare-function font-info
"font.c" (name &optional frame
))
821 (defun describe-font-internal (font-info &optional ignored
)
822 "Print information about a font in FONT-INFO.
823 The IGNORED argument is ignored."
824 (print-list "name (opened by):" (aref font-info
0))
825 (print-list " full name:" (aref font-info
1))
826 (print-list " size:" (format "%2d" (aref font-info
2)))
827 (print-list " height:" (format "%2d" (aref font-info
3)))
828 (print-list " baseline-offset:" (format "%2d" (aref font-info
4)))
829 (print-list "relative-compose:" (format "%2d" (aref font-info
5))))
832 (defun describe-font (fontname)
833 "Display information about a font whose name is FONTNAME.
834 The font must be already used by Emacs."
835 (interactive "sFont name (default current choice for ASCII chars): ")
836 (or (and window-system
(fboundp 'fontset-list
))
837 (error "No fonts being used"))
839 (if (or (not fontname
) (= (length fontname
) 0))
840 (setq fontname
(face-attribute 'default
:font
)))
841 (setq font-info
(font-info fontname
))
843 (if (fontp fontname
'font-object
)
844 ;; The font should be surely used. So, there's some
845 ;; problem about getting information about it. It is
846 ;; better to print the fontname to show which font has
848 (message "No information about \"%s\"" (font-xlfd-name fontname
))
849 (message "No matching font found"))
850 (with-output-to-temp-buffer "*Help*"
851 (describe-font-internal font-info
)))))
853 (defun print-fontset-element (val)
854 ;; VAL has this format:
855 ;; ((REQUESTED-FONT-NAME OPENED-FONT-NAME ...) ...)
856 ;; CHAR RANGE is already inserted. Get character codes from
859 (let ((from (following-char))
860 (to (if (looking-at "[^.]*[.]* ")
861 (char-after (match-end 0)))))
862 (if (re-search-forward "[ \t]*$" nil t
)
863 (delete-region (match-beginning 0) (match-end 0)))
865 ;; For non-ASCII characters, insert also CODE RANGE.
866 (if (or (>= from
128) (and to
(>= to
128)))
868 (insert (format " (#x%02X .. #x%02X)" from to
))
869 (insert (format " (#x%02X)" from
))))
871 ;; Insert a requested font name.
874 (insert "\n -- inhibit fallback fonts --")
875 (let ((requested (car elt
)))
876 (if (stringp requested
)
877 (insert "\n " requested
)
878 (let (family registry weight slant width adstyle
)
879 (if (and (fboundp 'fontp
) (fontp requested
))
880 (setq family
(font-get requested
:family
)
881 registry
(font-get requested
:registry
)
882 weight
(font-get requested
:weight
)
883 slant
(font-get requested
:slant
)
884 width
(font-get requested
:width
)
885 adstyle
(font-get requested
:adstyle
))
886 (setq family
(aref requested
0)
887 registry
(aref requested
5)
888 weight
(aref requested
1)
889 slant
(aref requested
2)
890 width
(aref requested
3)
891 adstyle
(aref requested
4)))
895 (setq family
(symbol-name family
)))
896 (or (string-match "-" family
)
897 (setq family
(concat "*-" family
))))
899 (setq registry
"*-*")
900 (if (symbolp registry
)
901 (setq registry
(symbol-name registry
)))
902 (or (string-match "-" registry
)
903 (= (aref registry
(1- (length registry
))) ?
*)
904 (setq registry
(concat registry
"*"))))
905 (insert (format"\n -%s-%s-%s-%s-%s-*-*-*-*-*-*-%s"
906 family
(or weight
"*") (or slant
"*") (or width
"*")
907 (or adstyle
"*") registry
)))))
909 ;; Insert opened font names (if any).
910 (if (and (boundp 'print-opened
) (symbol-value 'print-opened
))
911 (dolist (opened (cdr elt
))
912 (insert "\n\t[" opened
"]")))))))
914 (declare-function query-fontset
"fontset.c" (pattern &optional regexpp
))
915 (declare-function fontset-info
"fontset.c" (fontset &optional frame
))
917 (defun print-fontset (fontset &optional print-opened
)
918 "Print information about FONTSET.
919 FONTSET nil means the fontset of the selected frame, t means the
921 If optional arg PRINT-OPENED is non-nil, also print names of all opened
922 fonts for FONTSET. This function actually inserts the information in
925 (setq fontset
(query-fontset "fontset-default"))
927 (setq fontset
(face-attribute 'default
:fontset
))))
929 (narrow-to-region (point) (point))
930 (insert "Fontset: " fontset
"\n")
931 (insert (propertize "CHAR RANGE" 'face
'underline
)
932 " (" (propertize "CODE RANGE" 'face
'underline
) ")\n")
933 (insert " " (propertize "FONT NAME" 'face
'underline
)
934 " (" (propertize "REQUESTED" 'face
'underline
)
935 " and [" (propertize "OPENED" 'face
'underline
) "])")
936 (let* ((info (fontset-info fontset
))
937 (default-info (char-table-extra-slot info
0))
938 start1 end1 start2 end2
)
939 (describe-vector info
'print-fontset-element
)
940 (when (char-table-range info nil
)
941 ;; The default of FONTSET is described.
942 (setq start1
(re-search-backward "^default"))
943 (delete-region (point) (line-end-position))
944 (insert "\n ---<fallback to the default of the specified fontset>---")
945 (put-text-property (line-beginning-position) (point) 'face
'highlight
)
946 (goto-char (point-max))
947 (setq end1
(setq start2
(point))))
949 (insert "\n ---<fallback to the default fontset>---")
950 (put-text-property (line-beginning-position) (point) 'face
'highlight
)
951 (describe-vector default-info
'print-fontset-element
)
952 (when (char-table-range default-info nil
)
953 ;; The default of the default fontset is described.
954 (setq end2
(re-search-backward "^default"))
955 (delete-region (point) (line-end-position))
956 (insert "\n ---<fallback to the default of the default fontset>---")
957 (put-text-property (line-beginning-position) (point) 'face
'highlight
)))
958 (if (and start1 end2
)
959 ;; Reoder the printed information to match with the font
960 ;; searching strategy; i.e. FONTSET, the default fontset,
961 ;; default of FONTSET, default of the default fontset.
962 (transpose-regions start1 end1 start2 end2
))
963 (goto-char (point-max)))
966 (defvar fontset-alias-alist
)
967 (declare-function fontset-list
"fontset.c" ())
970 (defun describe-fontset (fontset)
971 "Display information about FONTSET.
972 This shows which font is used for which character(s)."
974 (if (not (and window-system
(fboundp 'fontset-list
)))
975 (error "No fontsets being used")
976 (let ((fontset-list (nconc
978 (mapcar 'cdr fontset-alias-alist
)))
979 (completion-ignore-case t
))
980 (list (completing-read
981 "Fontset (default used by the current frame): "
982 fontset-list nil t
)))))
983 (if (= (length fontset
) 0)
984 (setq fontset
(face-attribute 'default
:fontset
))
985 (setq fontset
(query-fontset fontset
)))
986 (help-setup-xref (list #'describe-fontset fontset
) (interactive-p))
987 (with-output-to-temp-buffer (help-buffer)
988 (with-current-buffer standard-output
989 (print-fontset fontset t
))))
991 (declare-function fontset-plain-name
"fontset" (fontset))
994 (defun list-fontsets (arg)
995 "Display a list of all fontsets.
996 This shows the name, size, and style of each fontset.
997 With prefix arg, also list the fonts contained in each fontset;
998 see the function `describe-fontset' for the format of the list."
1000 (if (not (and window-system
(fboundp 'fontset-list
)))
1001 (error "No fontsets being used")
1002 (help-setup-xref (list #'list-fontsets arg
) (interactive-p))
1003 (with-output-to-temp-buffer (help-buffer)
1004 (with-current-buffer standard-output
1005 ;; This code is duplicated near the end of mule-diag.
1007 (sort (fontset-list)
1009 (string< (fontset-plain-name x
)
1010 (fontset-plain-name y
))))))
1013 (print-fontset (car fontsets
) nil
)
1014 (insert "Fontset: " (car fontsets
) "\n"))
1015 (setq fontsets
(cdr fontsets
))))))))
1018 (defun list-input-methods ()
1019 "Display information about all input methods."
1021 (help-setup-xref '(list-input-methods) (interactive-p))
1022 (with-output-to-temp-buffer (help-buffer)
1023 (list-input-methods-1)
1024 (with-current-buffer standard-output
1026 (goto-char (point-min))
1027 (while (re-search-forward
1028 "^ \\([^ ]+\\) (`.*' in mode line)$" nil t
)
1029 (help-xref-button 1 'help-input-method
(match-string 1)))))))
1031 (defun list-input-methods-1 ()
1032 (if (not input-method-alist
)
1034 No input method is available, perhaps because you have not
1035 installed LEIM (Libraries of Emacs Input Methods).")
1036 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1037 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1038 (setq input-method-alist
1039 (sort input-method-alist
1040 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
1043 (dolist (elt input-method-alist
)
1044 (when (not (equal language
(nth 1 elt
)))
1045 (setq language
(nth 1 elt
))
1048 (princ (format " %s (`%s' in mode line)\n %s\n"
1050 (let ((title (nth 3 elt
)))
1051 (if (and (consp title
) (stringp (car title
)))
1058 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1059 (defun insert-section (section-number title
)
1060 (insert "########################################\n"
1061 "# Section " (format "%d" section-number
) ". " title
"\n"
1062 "########################################\n\n"))
1066 "Display diagnosis of the multilingual environment (Mule).
1068 This shows various information related to the current multilingual
1069 environment, including lists of input methods, coding systems,
1070 character sets, and fontsets (if Emacs is running under a window
1071 system which uses fontsets)."
1073 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1074 (with-current-buffer standard-output
1075 (insert "###############################################\n"
1076 "### Current Status of Multilingual Features ###\n"
1077 "###############################################\n\n"
1078 "CONTENTS: Section 1. General Information\n"
1079 " Section 2. Display\n"
1080 " Section 3. Input methods\n"
1081 " Section 4. Coding systems\n"
1082 " Section 5. Character sets\n")
1083 (if (and window-system
(fboundp 'fontset-list
))
1084 (insert " Section 6. Fontsets\n"))
1087 (insert-section 1 "General Information")
1088 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1089 (insert "Configuration options:\n " system-configuration-options
"\n\n")
1090 (insert "Multibyte characters awareness:\n"
1091 (format " default: %S\n" (default-value
1092 'enable-multibyte-characters
))
1093 (format " current-buffer: %S\n\n" enable-multibyte-characters
))
1094 (insert "Current language environment: " current-language-environment
1097 (insert-section 2 "Display")
1099 (insert (format "Window-system: %s, version %s"
1100 window-system window-system-version
))
1101 (insert "Terminal: " (getenv "TERM")))
1105 (let ((font (cdr (assq 'font
(frame-parameters)))))
1106 (insert "The font and fontset of the selected frame are:\n"
1108 " fontset: " (face-attribute 'default
:fontset
) "\n"))
1109 (insert "Coding system of the terminal: "
1110 (symbol-name (terminal-coding-system))))
1113 (insert-section 3 "Input methods")
1114 (list-input-methods-1)
1116 (if default-input-method
1117 (insert (format "Default input method: %s\n" default-input-method
))
1118 (insert "No default input method is specified\n"))
1120 (insert-section 4 "Coding systems")
1121 (list-coding-systems-1 t
)
1124 (insert-section 5 "Character sets")
1125 (list-character-sets-2)
1128 (when (and window-system
(fboundp 'fontset-list
))
1129 ;; This code duplicates most of list-fontsets.
1130 (insert-section 6 "Fontsets")
1131 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1132 (insert "------------\t\t\t\t\t\t ----- -----\n")
1133 (dolist (fontset (fontset-list))
1134 (print-fontset fontset t
)))
1135 (help-print-return-message))))
1138 (defun font-show-log (&optional limit
)
1139 "Show log of font listing and opening.
1140 Prefix arg LIMIT says how many fonts to show for each listing.
1141 The default is 20. If LIMIT is negative, do not limit the listing."
1143 (setq limit
(if limit
(prefix-numeric-value limit
) 20))
1145 (message "Font logging is currently suppressed")
1146 (with-output-to-temp-buffer "*Help*"
1147 (set-buffer standard-output
)
1148 (dolist (elt (reverse font-log
))
1149 (insert (format "%s: %s\n" (car elt
) (cadr elt
)))
1150 (setq elt
(nth 2 elt
))
1151 (if (or (vectorp elt
) (listp elt
))
1159 (insert (format " %s\n" x
)))
1161 (insert (format " %s\n" elt
)))))))
1164 (provide 'mule-diag
)
1166 ;; arch-tag: cd3b607c-2893-45a0-a4fa-a6535754dbee
1167 ;;; mule-diag.el ends here