1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1997-1998, 2000-2019 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
9 ;; National Institute of Advanced Industrial Science and Technology (AIST)
10 ;; Registration Number H13PRO009
12 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
33 ;; Make sure the help-xref button type is defined.
36 ;;; General utility function
38 (defun print-list (&rest args
)
39 "Print all arguments with single space separator in one line."
40 (princ (mapconcat (lambda (arg) (prin1-to-string arg t
)) args
" "))
45 (define-button-type 'sort-listed-character-sets
46 'help-echo
(purecopy "mouse-2, RET: sort on this column")
48 'action
#'(lambda (button)
49 (sort-listed-character-sets (button-get button
'sort-key
))))
51 (define-button-type 'list-charset-chars
53 'help-function
#'list-charset-chars
54 'help-echo
"mouse-2, RET: show table of characters for this character set")
57 (defun list-character-sets (arg)
58 "Display a list of all character sets.
60 The D column contains the dimension of this character set. The CH
61 column contains the number of characters in a block of this character
62 set. The FINAL-BYTE column contains an ISO-2022 <final-byte> to use
63 in the designation escape sequence for this character set in
64 ISO-2022-based coding systems.
66 With prefix ARG, the output format gets more cryptic,
67 but still shows the full information."
69 (help-setup-xref (list #'list-character-sets arg
)
70 (called-interactively-p 'interactive
))
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 other charsets, or for backward compatibility
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 ;; A variable to hold charset input history.
208 (defvar charset-history nil
)
212 (defun read-charset (prompt &optional default-value initial-input
)
213 "Read a character set from the minibuffer, prompting with string PROMPT.
214 It must be an Emacs character set listed in the variable `charset-list'.
216 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
217 DEFAULT-VALUE, if non-nil, is the default value.
218 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
219 See the documentation of the function `completing-read' for the detailed
220 meanings of these arguments."
221 (let* ((table (mapcar (lambda (x) (list (symbol-name x
))) charset-list
))
222 (charset (completing-read prompt table
223 nil t initial-input
'charset-history
225 (if (> (length charset
) 0)
228 ;; List characters of the range MIN and MAX of CHARSET. If dimension
229 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
230 ;; (block index) of the characters, and MIN and MAX are the second
231 ;; bytes of the characters. If the dimension is one, ROW should be 0.
233 (defun list-block-of-chars (charset row min max
)
235 (insert-char ?-
(+ 7 (* 4 16)))
239 (insert (format "%4X" i
))
241 (setq i
(* (/ min
16) 16))
244 (insert (format "\n%6Xx" (/ (+ (* row
256) i
) 16))))
245 (setq ch
(if (< i min
)
247 (or (decode-char charset
(+ (* row
256) i
))
248 32))) ; gap in mapping
249 ;; Don't insert control codes, non-Unicode characters.
250 (if (or (< ch
32) (= ch
127))
251 (setq ch
(single-key-description ch
))
252 (if (and (>= ch
128) (< ch
160))
253 (setq ch
(format "%02Xh" ch
))
261 (defun list-charset-chars (charset)
262 "Display a list of characters in character set CHARSET."
263 (interactive (list (read-charset "Character set: ")))
264 (or (charsetp charset
)
265 (error "Invalid character set: %s" charset
))
266 (with-output-to-temp-buffer "*Character List*"
267 (with-current-buffer standard-output
268 (if (coding-system-p charset
)
269 ;; Useful to be able to do C-u C-x = to find file code, for
271 (set-buffer-file-coding-system charset
))
272 (setq mode-line-format
(copy-sequence mode-line-format
))
273 (let ((slot (memq 'mode-line-buffer-identification mode-line-format
)))
276 (cons (format " (%s)" charset
)
279 (set-buffer-multibyte t
)
280 (let ((dim (charset-dimension charset
))
281 (chars (charset-chars charset
))
282 ;; (plane (charset-iso-graphic-plane charset))
284 (range (plist-get (charset-plist charset
) :code-space
))
287 (error "Can only list 1- and 2-dimensional charsets"))
288 (insert (format "Characters in the coded character set %s.\n" charset
))
289 (narrow-to-region (point) (point))
290 (setq min
(aref range
0)
293 (list-block-of-chars charset
0 min max
)
294 (setq min2
(aref range
2)
298 (list-block-of-chars charset i min max
)
300 (put-text-property (point-min) (point-max) 'charset charset
)
305 (defun describe-character-set (charset)
306 "Display information about built-in character set CHARSET."
307 (interactive (list (read-charset "Charset: ")))
308 (or (charsetp charset
)
309 (error "Invalid charset: %S" charset
))
310 (help-setup-xref (list #'describe-character-set charset
)
311 (called-interactively-p 'interactive
))
312 (with-output-to-temp-buffer (help-buffer)
313 (with-current-buffer standard-output
314 (insert "Character set: " (symbol-name charset
))
315 (let ((name (get-charset-property charset
:name
)))
316 (if (not (eq name charset
))
317 (insert " (alias of " (symbol-name name
) ?\
))))
318 (insert "\n\n" (charset-description charset
) "\n\n")
319 (insert "Number of contained characters: ")
320 (dotimes (i (charset-dimension charset
))
323 (insert (format "%d" (charset-chars charset
(1+ i
)))))
325 (let ((char (charset-iso-final-char charset
)))
327 (insert "Final char of ISO2022 designation sequence: ")
328 (insert (format-message "`%c'\n" char
))))
330 (dolist (c charset-list
)
331 (if (and (not (eq c charset
))
332 (eq charset
(get-charset-property c
:name
)))
335 (insert "Aliases: " (mapconcat #'symbol-name aliases
", ") ?
\n)))
337 (dolist (elt `((:ascii-compatible-p
"ASCII compatible." nil
)
338 (:map
"Map file: " identity
)
339 (:unify-map
"Unification map file: " identity
)
343 (format "Invalid character: %c (code %d)" c c
)))
344 (:emacs-mule-id
"Id in emacs-mule coding system: "
346 (:parents
"Parents: "
348 (mapconcat ,(lambda (elt)
352 (:code-space
"Code space: " ,(lambda (c)
354 (:code-offset
"Code offset: " number-to-string
)
355 (:iso-revision-number
"ISO revision number: "
358 "Used only as a parent or a subset of some other charset,
359 or provided just for backward compatibility." nil
)))
360 (let ((val (get-charset-property charset
(car elt
))))
362 (if (cadr elt
) (insert (cadr elt
)))
364 (let ((print-length 10) (print-level 2))
365 (princ (funcall (nth 2 elt
) val
) (current-buffer))))
370 (defvar graphic-register
) ; dynamic bondage
372 ;; Print information about designation of each graphic register in
373 ;; DESIGNATIONS in human readable format. See the documentation of
374 ;; `define-coding-system' for the meaning of DESIGNATIONS
375 ;; (`:designation' property).
376 (defun print-designation (designations)
378 (dotimes (graphic-register 4)
379 (setq charset
(aref designations graphic-register
))
383 (cond ((null charset
)
386 "no initial designation, and used by any charsets")
389 charset
(charset-description charset
)))
391 (if (charsetp (car charset
))
392 (format "%s:%s, and also used by the following:"
394 (charset-description (car charset
)))
395 "no initial designation, and used by the following:"))
397 "invalid designation information"))))
398 (when (listp charset
)
399 (setq charset
(cdr charset
))
401 (cond ((eq (car charset
) t
)
402 (princ "\tany other charsets\n"))
403 ((charsetp (car charset
))
404 (princ (format "\t%s:%s\n"
406 (charset-description (car charset
)))))
408 "invalid designation information"))
409 (setq charset
(cdr charset
)))))))
412 (defun describe-coding-system (coding-system)
413 "Display information about CODING-SYSTEM."
414 (interactive "zDescribe coding system (default current choices): ")
415 (if (null coding-system
)
416 (describe-current-coding-system)
417 (help-setup-xref (list #'describe-coding-system coding-system
)
418 (called-interactively-p 'interactive
))
419 (with-output-to-temp-buffer (help-buffer)
420 (print-coding-system-briefly coding-system
'doc-string
)
421 (let ((type (coding-system-type coding-system
))
423 (extra-spec (coding-system-plist coding-system
)))
426 (cond ((eq type
'undecided
)
427 (princ " (do automatic conversion)"))
429 (princ " (UTF-8: Emacs internal multibyte form)"))
431 ;; (princ " (UTF-16)")
433 ((eq type
'shift-jis
)
434 (princ " (Shift-JIS, MS-KANJI)"))
436 (princ " (variant of ISO-2022)\n")
437 (princ "Initial designations:\n")
438 (print-designation (coding-system-get coding-system
441 (when (coding-system-get coding-system
:flags
)
442 (princ "Other specifications: \n ")
444 (coding-system-get coding-system
:flags
))))
446 (princ " (charset)"))
448 (princ " (do conversion by CCL program)"))
450 (princ " (text with random binary characters)"))
451 ((eq type
'emacs-mule
)
452 (princ " (Emacs 21 internal encoding)"))
454 (t (princ ": invalid coding-system.")))
455 (princ "\nEOL type: ")
456 (let ((eol-type (coding-system-eol-type coding-system
)))
457 (cond ((vectorp eol-type
)
458 (princ "Automatic selection from:\n\t")
461 ((or (null eol-type
) (eq eol-type
0)) (princ "LF\n"))
462 ((eq eol-type
1) (princ "CRLF\n"))
463 ((eq eol-type
2) (princ "CR\n"))
464 (t (princ "invalid\n")))))
465 (let ((postread (coding-system-get coding-system
:post-read-conversion
)))
467 (princ "After decoding text normally,")
468 (princ " perform post-conversion using the function: ")
472 (let ((prewrite (coding-system-get coding-system
:pre-write-conversion
)))
474 (princ "Before encoding text normally,")
475 (princ " perform pre-conversion using the function: ")
479 (with-current-buffer standard-output
480 (let ((charsets (coding-system-charset-list coding-system
)))
481 (when (and (not (eq (coding-system-base coding-system
) 'raw-text
))
484 ((eq charsets
'iso-2022
)
485 (insert "This coding system can encode all ISO 2022 charsets."))
486 ((eq charsets
'emacs-mule
)
487 (insert "This coding system can encode all emacs-mule charsets\
490 (insert "This coding system encodes the following charsets:\n ")
492 (insert " " (symbol-name (car charsets
)))
493 (search-backward (symbol-name (car charsets
)))
494 (help-xref-button 0 'help-character-set
(car charsets
))
495 (goto-char (point-max))
496 (setq charsets
(cdr charsets
)))))))))))
499 (defun describe-current-coding-system-briefly ()
500 "Display coding systems currently used in a brief format in echo area.
502 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
503 where mnemonics of the following coding systems come in this order
505 `buffer-file-coding-system' (of the current buffer)
506 eol-type of `buffer-file-coding-system' (of the current buffer)
507 Value returned by `keyboard-coding-system'
508 eol-type of `keyboard-coding-system'
509 Value returned by `terminal-coding-system'.
510 eol-type of `terminal-coding-system'
511 `process-coding-system' for read (of the current buffer, if any)
512 eol-type of `process-coding-system' for read (of the current buffer, if any)
513 `process-coding-system' for write (of the current buffer, if any)
514 eol-type of `process-coding-system' for write (of the current buffer, if any)
515 default `buffer-file-coding-system'
516 eol-type of default `buffer-file-coding-system'
517 `default-process-coding-system' for read
518 eol-type of `default-process-coding-system' for read
519 `default-process-coding-system' for write
520 eol-type of `default-process-coding-system'"
522 (let* ((proc (get-buffer-process (current-buffer)))
523 (process-coding-systems (if proc
(process-coding-system proc
))))
525 "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]"
526 (coding-system-mnemonic buffer-file-coding-system
)
527 (coding-system-eol-type-mnemonic buffer-file-coding-system
)
528 (coding-system-mnemonic (keyboard-coding-system))
529 (coding-system-eol-type-mnemonic (keyboard-coding-system))
530 (coding-system-mnemonic (terminal-coding-system))
531 (coding-system-eol-type-mnemonic (terminal-coding-system))
532 (coding-system-mnemonic (car process-coding-systems
))
533 (coding-system-eol-type-mnemonic (car process-coding-systems
))
534 (coding-system-mnemonic (cdr process-coding-systems
))
535 (coding-system-eol-type-mnemonic (cdr process-coding-systems
))
536 (coding-system-mnemonic (default-value 'buffer-file-coding-system
))
537 (coding-system-eol-type-mnemonic
538 (default-value 'buffer-file-coding-system
))
539 (coding-system-mnemonic (car default-process-coding-system
))
540 (coding-system-eol-type-mnemonic (car default-process-coding-system
))
541 (coding-system-mnemonic (cdr default-process-coding-system
))
542 (coding-system-eol-type-mnemonic (cdr default-process-coding-system
))
545 (defun print-coding-system-briefly (coding-system &optional doc-string
)
546 "Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
547 If DOC-STRING is non-nil, print also the docstring of CODING-SYSTEM.
548 If DOC-STRING is `tightly', don't print an empty line before the
549 docstring, and print only the first line of the docstring."
550 (if (not coding-system
)
552 (princ (format "%c -- %s"
553 (coding-system-mnemonic coding-system
)
555 (let ((aliases (coding-system-aliases coding-system
)))
556 (cond ((eq coding-system
(car aliases
))
558 (princ (format " %S" (cons 'alias
: (cdr aliases
))))))
559 ((memq coding-system aliases
)
560 (princ (format " (alias of %s)" (car aliases
))))
562 (let ((eol-type (coding-system-eol-type coding-system
))
563 (base-eol-type (coding-system-eol-type (car aliases
))))
564 (if (and (integerp eol-type
)
565 (vectorp base-eol-type
)
566 (not (eq coding-system
(aref base-eol-type eol-type
))))
567 (princ (format " (alias of %s)"
568 (aref base-eol-type eol-type
))))))))
570 (or (eq doc-string
'tightly
)
573 (let ((doc (or (coding-system-doc-string coding-system
) "")))
574 (when (eq doc-string
'tightly
)
575 (if (string-match "\n" doc
)
576 (setq doc
(substring doc
0 (match-beginning 0))))
577 (setq doc
(concat " " doc
)))
578 (princ (format "%s\n" (substitute-command-keys doc
)))))))
581 (defun describe-current-coding-system ()
582 "Display coding systems currently used, in detail."
584 (with-output-to-temp-buffer "*Help*"
585 (let* ((proc (get-buffer-process (current-buffer)))
586 (process-coding-systems (if proc
(process-coding-system proc
))))
587 (princ "Coding system for saving this buffer:\n ")
588 (if (local-variable-p 'buffer-file-coding-system
)
589 (print-coding-system-briefly buffer-file-coding-system
)
590 (princ "Not set locally, use the default.\n"))
591 (princ "Default coding system (for new files):\n ")
592 (print-coding-system-briefly (default-value 'buffer-file-coding-system
))
593 (princ "Coding system for keyboard input:\n ")
594 (print-coding-system-briefly (keyboard-coding-system))
595 (princ "Coding system for terminal output:\n ")
596 (print-coding-system-briefly (terminal-coding-system))
597 (when (boundp 'selection-coding-system
)
598 (princ "Coding system for inter-client cut and paste:\n ")
599 (print-coding-system-briefly selection-coding-system
))
600 (when (get-buffer-process (current-buffer))
601 (princ "Coding systems for process I/O:\n")
602 (princ " encoding input to the process: ")
603 (print-coding-system-briefly (cdr process-coding-systems
))
604 (princ " decoding output from the process: ")
605 (print-coding-system-briefly (car process-coding-systems
)))
606 (princ "Defaults for subprocess I/O:\n")
607 (princ " decoding: ")
608 (print-coding-system-briefly (car default-process-coding-system
))
609 (princ " encoding: ")
610 (print-coding-system-briefly (cdr default-process-coding-system
)))
612 (with-current-buffer standard-output
615 Priority order for recognizing coding systems when reading files:\n")
617 (dolist (elt (coding-system-priority-list))
618 (princ (format " %d. %s " i elt
))
619 (let ((aliases (coding-system-aliases elt
)))
620 (if (eq elt
(car aliases
))
622 (princ (cons 'alias
: (cdr aliases
))))
623 (princ (list 'alias
'of
(car aliases
))))
627 (princ "\n Other coding systems cannot be distinguished automatically
628 from these, and therefore cannot be recognized automatically
629 with the present coding system priorities.\n\n")
631 ;; Fixme: should this be replaced or junked?
633 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
634 coding-system codings
)
636 (setq coding-system
(symbol-value (car categories
)))
639 (if (and (not (eq x coding-system
))
640 (let ((flags (coding-system-get :flags
)))
641 (not (or (memq 'use-roman flags
)
642 (memq 'use-oldjis flags
)))))
643 (setq codings
(cons x codings
))))
644 (get (car categories
) 'coding-systems
))
646 (let ((max-col (window-width))
649 The following are decoded correctly but recognized as %s:\n "
653 (insert (format " %s" (car codings
)))
654 (when (> (current-column) max-col
)
657 (goto-char (point-max)))
658 (setq codings
(cdr codings
)))
660 (setq categories
(cdr categories
)))))
662 (princ "Particular coding systems specified for certain file names:\n")
664 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
665 (princ " ---------\t--------------\t\t----------------\n")
666 (let ((func (lambda (operation alist
)
670 (princ "\tnothing specified\n")
673 (prin1 (car (car alist
)))
674 (if (>= (current-column) 40)
677 (princ (cdr (car alist
)))
679 (setq alist
(cdr alist
)))))))
680 (funcall func
"File I/O" file-coding-system-alist
)
681 (funcall func
"Process I/O" process-coding-system-alist
)
682 (funcall func
"Network I/O" network-coding-system-alist
))
685 (defun print-coding-system (coding-system)
686 "Print detailed information on CODING-SYSTEM."
687 (let ((type (coding-system-type coding-system
))
688 (eol-type (coding-system-eol-type coding-system
))
689 (flags (coding-system-get coding-system
:flags
))
690 (aliases (coding-system-aliases coding-system
)))
691 (if (not (eq (car aliases
) coding-system
))
692 (princ (format "%s (alias of %s)\n" coding-system
(car aliases
)))
693 (princ coding-system
)
694 (dolist (alias (cdr aliases
))
697 (princ (format ":%s:%c:%d:"
699 (coding-system-mnemonic coding-system
)
700 (if (integerp eol-type
) eol-type
3)))
701 (cond ((eq type
'iso2022
)
705 (setq charset
(aref flags idx
))
706 (cond ((null charset
)
714 (princ (car charset
))
715 (setq charset
(cdr charset
))
718 (princ (car charset
))
719 (setq charset
(cdr charset
)))
724 (princ (if (aref flags idx
) 1 0))
727 (princ (if (aref flags idx
) 1 0))))
730 (if (symbolp (car flags
))
731 (princ (format " %s" (car flags
)))
732 (setq i
0 len
(length (car flags
)))
734 (princ (format " %x" (aref (car flags
) i
)))
737 (if (symbolp (cdr flags
))
738 (princ (format "%s" (cdr flags
)))
739 (setq i
0 len
(length (cdr flags
)))
741 (princ (format " %x" (aref (cdr flags
) i
)))
745 (princ (coding-system-doc-string coding-system
))
749 (defun list-coding-systems (&optional arg
)
750 "Display a list of all coding systems.
751 This shows the mnemonic letter, name, and description of each coding system.
753 With prefix ARG, the output format gets more cryptic,
754 but still contains full information about each coding system."
756 (with-output-to-temp-buffer "*Help*"
757 (list-coding-systems-1 arg
)))
759 (defun list-coding-systems-1 (arg)
762 ###############################################
763 # List of coding systems in the following format:
764 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
767 (princ (substitute-command-keys "\
768 #########################
769 ## LIST OF CODING SYSTEMS
770 ## Each line corresponds to one coding system
771 ## Format of a line is:
772 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
773 ## :PRE-WRITE-CONVERSION:DOC-STRING,
775 ## NAME = coding system name
776 ## ALIAS = alias of the coding system
777 ## TYPE = nil (no conversion), t (undecided or automatic detection),
778 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
779 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
782 ## comma (`,') separated data of the following:
783 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
784 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
785 ## else if TYPE = 4 then
786 ## comma (`,') separated CCL programs for read and write
789 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
792 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only
)))
794 (print-coding-system-briefly coding-system
'tightly
)
795 (print-coding-system coding-system
))))
799 (defun list-coding-categories ()
800 "Display a list of all coding categories."
801 (with-output-to-temp-buffer "*Help*"
803 ############################
804 ## LIST OF CODING CATEGORIES (ordered by priority)
805 ## CATEGORY:CODING-SYSTEM
808 (let ((l coding-category-list
))
810 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
815 (declare-function font-info
"font.c" (name &optional frame
))
817 (defun describe-font-internal (font-info &optional ignored
)
818 "Print information about a font in FONT-INFO.
819 The IGNORED argument is ignored."
820 (print-list "name (opened by):" (aref font-info
0))
821 (print-list " full name:" (aref font-info
1))
822 (and (aref font-info
12)
823 (print-list " file name:" (aref font-info
12)))
824 (print-list " size:" (format "%2d" (aref font-info
2)))
825 (print-list " height:" (format "%2d" (aref font-info
3)))
826 (print-list " baseline-offset:" (format "%2d" (aref font-info
4)))
827 (print-list "relative-compose:" (format "%2d" (aref font-info
5)))
828 (print-list " default-ascent:" (format "%2d" (aref font-info
6)))
829 (print-list " ascent:" (format "%2d" (aref font-info
8)))
830 (print-list " descent:" (format "%2d" (aref font-info
9)))
831 (print-list " average-width:" (format "%2d" (aref font-info
11)))
832 (print-list " space-width:" (format "%2d" (aref font-info
10)))
833 (print-list " max-width:" (format "%2d" (aref font-info
7))))
836 (defun describe-font (fontname)
837 "Display information about a font whose name is FONTNAME.
838 The font must be already used by Emacs."
839 (interactive "sFont name (default current choice for ASCII chars): ")
840 (or (and window-system
(fboundp 'fontset-list
))
841 (error "No fonts being used"))
842 (let ((xref-item (list #'describe-font fontname
))
844 (if (or (not fontname
) (= (length fontname
) 0))
845 (setq fontname
(face-attribute 'default
:font
)))
846 (setq font-info
(font-info fontname
))
848 (if (fontp fontname
'font-object
)
849 ;; The font should be surely used. So, there's some
850 ;; problem about getting information about it. It is
851 ;; better to print the fontname to show which font has
853 (message "No information about \"%s\"" (font-xlfd-name fontname
))
854 (message "No matching font found"))
855 (help-setup-xref xref-item
(called-interactively-p 'interactive
))
856 (with-output-to-temp-buffer "*Help*"
857 (describe-font-internal font-info
)))))
859 (defun print-fontset-element (val)
860 ;; VAL has this format:
861 ;; ((REQUESTED-FONT-NAME OPENED-FONT-NAME ...) ...)
862 ;; CHAR RANGE is already inserted. Get character codes from
865 (let ((from (following-char))
866 (to (if (looking-at "[^.]*[.]* ")
867 (char-after (match-end 0)))))
868 (if (re-search-forward "[ \t]*$" nil t
)
869 (delete-region (match-beginning 0) (match-end 0)))
871 ;; For non-ASCII characters, insert also CODE RANGE.
872 (if (or (>= from
128) (and to
(>= to
128)))
874 (insert (format " (#x%02X .. #x%02X)" from to
))
875 (insert (format " (#x%02X)" from
))))
877 ;; Insert a requested font name.
880 (insert "\n -- inhibit fallback fonts --")
881 (let ((requested (car elt
)))
882 (if (stringp requested
)
883 (insert "\n " requested
)
884 (let (family registry weight slant width adstyle
)
885 (if (and (fboundp 'fontp
) (fontp requested
))
886 (setq family
(font-get requested
:family
)
887 registry
(font-get requested
:registry
)
888 weight
(font-get requested
:weight
)
889 slant
(font-get requested
:slant
)
890 width
(font-get requested
:width
)
891 adstyle
(font-get requested
:adstyle
))
892 (setq family
(aref requested
0)
893 registry
(aref requested
5)
894 weight
(aref requested
1)
895 slant
(aref requested
2)
896 width
(aref requested
3)
897 adstyle
(aref requested
4)))
901 (setq family
(symbol-name family
)))
902 (or (string-match "-" family
)
903 (setq family
(concat "*-" family
))))
905 (setq registry
"*-*")
906 (if (symbolp registry
)
907 (setq registry
(symbol-name registry
)))
908 (or (string-match "-" registry
)
909 (= (aref registry
(1- (length registry
))) ?
*)
910 (setq registry
(concat registry
"*"))))
911 (insert (format"\n -%s-%s-%s-%s-%s-*-*-*-*-*-*-%s"
912 family
(or weight
"*") (or slant
"*") (or width
"*")
913 (or adstyle
"*") registry
)))))
915 ;; Insert opened font names (if any).
916 (if (and (boundp 'print-opened
) (symbol-value 'print-opened
))
917 (dolist (opened (cdr elt
))
918 (insert "\n\t[" opened
"]")))))))
920 (declare-function query-fontset
"fontset.c" (pattern &optional regexpp
))
921 (declare-function fontset-info
"fontset.c" (fontset &optional frame
))
923 (defun print-fontset (fontset &optional print-opened
)
924 "Print information about FONTSET.
925 FONTSET nil means the fontset of the selected frame, t means the
927 If optional arg PRINT-OPENED is non-nil, also print names of all opened
928 fonts for FONTSET. This function actually inserts the information in
931 (setq fontset
(query-fontset "fontset-default"))
933 (setq fontset
(face-attribute 'default
:fontset
))))
935 (narrow-to-region (point) (point))
936 (insert "Fontset: " fontset
"\n")
937 (insert (propertize "CHAR RANGE" 'face
'underline
)
938 " (" (propertize "CODE RANGE" 'face
'underline
) ")\n")
939 (insert " " (propertize "FONT NAME" 'face
'underline
)
940 " (" (propertize "REQUESTED" 'face
'underline
)
941 " and [" (propertize "OPENED" 'face
'underline
) "])")
942 (let* ((info (fontset-info fontset
))
943 (default-info (char-table-extra-slot info
0))
944 start1 end1 start2 end2
)
945 (describe-vector info
'print-fontset-element
)
946 (when (char-table-range info nil
)
947 ;; The default of FONTSET is described.
948 (setq start1
(re-search-backward "^default"))
949 (delete-region (point) (line-end-position))
950 (insert "\n ---<fallback to the default of the specified fontset>---")
951 (put-text-property (line-beginning-position) (point) 'face
'highlight
)
952 (goto-char (point-max))
953 (setq end1
(setq start2
(point))))
955 (insert "\n ---<fallback to the default fontset>---")
956 (put-text-property (line-beginning-position) (point) 'face
'highlight
)
957 (describe-vector default-info
'print-fontset-element
)
958 (when (char-table-range default-info nil
)
959 ;; The default of the default fontset is described.
960 (setq end2
(re-search-backward "^default"))
961 (delete-region (point) (line-end-position))
962 (insert "\n ---<fallback to the default of the default fontset>---")
963 (put-text-property (line-beginning-position) (point) 'face
'highlight
)))
964 (if (and start1 end2
)
965 ;; Reorder the printed information to match with the font
966 ;; searching strategy; i.e. FONTSET, the default fontset,
967 ;; default of FONTSET, default of the default fontset.
968 (transpose-regions start1 end1 start2 end2
))
969 (goto-char (point-max)))
972 (defvar fontset-alias-alist
)
973 (declare-function fontset-list
"fontset.c" ())
976 (defun describe-fontset (fontset)
977 "Display information about FONTSET.
978 This shows which font is used for which character(s)."
980 (if (not (and window-system
(fboundp 'fontset-list
)))
981 (error "No fontsets being used")
982 (let ((fontset-list (nconc
984 (mapcar 'cdr fontset-alias-alist
)))
985 (completion-ignore-case t
))
986 (list (completing-read
987 "Fontset (default used by the current frame): "
988 fontset-list nil t
)))))
989 (if (= (length fontset
) 0)
990 (setq fontset
(face-attribute 'default
:fontset
))
991 (setq fontset
(query-fontset fontset
)))
992 (help-setup-xref (list #'describe-fontset fontset
)
993 (called-interactively-p 'interactive
))
994 (with-output-to-temp-buffer (help-buffer)
995 (with-current-buffer standard-output
996 (print-fontset fontset t
))))
998 (declare-function fontset-plain-name
"fontset" (fontset))
1001 (defun list-fontsets (arg)
1002 "Display a list of all fontsets.
1003 This shows the name, size, and style of each fontset.
1004 With prefix arg, also list the fonts contained in each fontset;
1005 see the function `describe-fontset' for the format of the list."
1007 (if (not (and window-system
(fboundp 'fontset-list
)))
1008 (error "No fontsets being used")
1009 (help-setup-xref (list #'list-fontsets arg
)
1010 (called-interactively-p 'interactive
))
1011 (with-output-to-temp-buffer (help-buffer)
1012 (with-current-buffer standard-output
1013 ;; This code is duplicated near the end of mule-diag.
1015 (sort (fontset-list)
1017 (string< (fontset-plain-name x
)
1018 (fontset-plain-name y
))))))
1021 (print-fontset (car fontsets
) nil
)
1022 (insert "Fontset: " (car fontsets
) "\n"))
1023 (setq fontsets
(cdr fontsets
))))))))
1026 (defun list-input-methods ()
1027 "Display information about all input methods."
1029 (help-setup-xref '(list-input-methods)
1030 (called-interactively-p 'interactive
))
1031 (with-output-to-temp-buffer (help-buffer)
1032 (list-input-methods-1)
1033 (with-current-buffer standard-output
1035 (goto-char (point-min))
1036 (while (re-search-forward
1037 (substitute-command-keys "^ \\([^ ]+\\) (`.*' in mode line)$")
1039 (help-xref-button 1 'help-input-method
(match-string 1)))))))
1041 (defun list-input-methods-1 ()
1042 (if (not input-method-alist
)
1044 No input method is available, perhaps because you have not
1045 installed LEIM (Libraries of Emacs Input Methods).")
1046 (princ (substitute-command-keys
1047 "LANGUAGE\n NAME (`TITLE' in mode line)\n"))
1048 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1049 (setq input-method-alist
1050 (sort input-method-alist
1051 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
1054 (dolist (elt input-method-alist
)
1055 (when (not (equal language
(nth 1 elt
)))
1056 (setq language
(nth 1 elt
))
1059 (princ (format-message
1060 " %s (`%s' in mode line)\n %s\n"
1062 (let ((title (nth 3 elt
)))
1063 (if (and (consp title
) (stringp (car title
)))
1066 ;; If the doc is multi-line, indent all
1067 ;; non-blank lines. (Bug#8066)
1068 (replace-regexp-in-string
1069 "\n\\(.\\)" "\n \\1"
1070 (substitute-command-keys (or (nth 4 elt
) "")))))))))
1074 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1075 (defun insert-section (section-number title
)
1076 (insert "########################################\n"
1077 "# Section " (format "%d" section-number
) ". " title
"\n"
1078 "########################################\n\n"))
1082 "Display diagnosis of the multilingual environment (Mule).
1084 This shows various information related to the current multilingual
1085 environment, including lists of input methods, coding systems,
1086 character sets, and fontsets (if Emacs is running under a window
1087 system which uses fontsets)."
1089 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1090 (with-current-buffer standard-output
1091 (insert "###############################################\n"
1092 "### Current Status of Multilingual Features ###\n"
1093 "###############################################\n\n"
1094 "CONTENTS: Section 1. General Information\n"
1095 " Section 2. Display\n"
1096 " Section 3. Input methods\n"
1097 " Section 4. Coding systems\n"
1098 " Section 5. Character sets\n")
1099 (if (and window-system
(fboundp 'fontset-list
))
1100 (insert " Section 6. Fontsets\n"))
1103 (insert-section 1 "General Information")
1104 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1105 (insert "Configuration options:\n " system-configuration-options
"\n\n")
1106 (insert "Multibyte characters awareness:\n"
1107 (format " current-buffer: %S\n\n" enable-multibyte-characters
))
1108 (insert "Current language environment: " current-language-environment
1111 (insert-section 2 "Display")
1113 (insert (format "Window-system: %s" window-system
))
1114 (insert "Terminal: " (getenv "TERM")))
1118 (let ((font (frame-parameter nil
'font
)))
1119 (insert "The font and fontset of the selected frame are:\n"
1121 " fontset: " (face-attribute 'default
:fontset
) "\n"))
1122 (insert "Coding system of the terminal: "
1123 (symbol-name (terminal-coding-system))))
1126 (insert-section 3 "Input methods")
1127 (list-input-methods-1)
1129 (if default-input-method
1130 (insert (format "Default input method: %s\n" default-input-method
))
1131 (insert "No default input method is specified\n"))
1133 (insert-section 4 "Coding systems")
1134 (list-coding-systems-1 t
)
1137 (insert-section 5 "Character sets")
1138 (list-character-sets-2)
1141 (when (and window-system
(fboundp 'fontset-list
))
1142 ;; This code duplicates most of list-fontsets.
1143 (insert-section 6 "Fontsets")
1144 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1145 (insert "------------\t\t\t\t\t\t ----- -----\n")
1146 (dolist (fontset (fontset-list))
1147 (print-fontset fontset t
)
1149 (help-print-return-message))))
1152 (defun font-show-log (&optional limit
)
1153 "Show log of font listing and opening.
1154 Prefix arg LIMIT says how many fonts to show for each listing.
1155 The default is 20. If LIMIT is negative, do not limit the listing."
1157 (setq limit
(if limit
(prefix-numeric-value limit
) 20))
1159 (message "Font logging is currently suppressed")
1160 (with-output-to-temp-buffer "*Help*"
1161 (set-buffer standard-output
)
1162 (dolist (elt (reverse font-log
))
1163 (insert (format "%s: %s\n" (car elt
) (cadr elt
)))
1164 (setq elt
(nth 2 elt
))
1165 (if (or (vectorp elt
) (listp elt
))
1173 (insert (format " %s\n" x
)))
1175 (insert (format " %s\n" elt
)))))))
1178 (provide 'mule-diag
)
1180 ;;; mule-diag.el ends here