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-CHAR column contains an ISO-2022 <final-char> to use
64 for designating this character set in 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
) (interactive-p))
70 (with-output-to-temp-buffer "*Character Set List*"
71 (with-current-buffer standard-output
73 (list-character-sets-2)
75 (insert "Supplementary character sets are shown below.\n")
77 (substitute-command-keys
79 (if (display-mouse-p) "\\[help-follow-mouse] or ")
80 "\\[help-follow]:\n")))
81 (insert " on a column title to sort by that title,")
83 (insert "+----DIMENSION\n")
84 (insert " on a charset name to list characters.")
86 (insert "| +--CHARS\n")
87 (let ((columns '(("CHARSET-NAME" . name
) "\t\t\t\t\t"
88 ("D CH FINAL-CHAR" . iso-spec
)))
91 (if (stringp (car columns
))
92 (insert (car columns
))
93 (insert-text-button (car (car columns
))
94 :type
'sort-listed-character-sets
95 'sort-key
(cdr (car columns
)))
96 (goto-char (point-max)))
97 (setq columns
(cdr columns
)))
99 (insert "------------\t\t\t\t\t- --- ----------\n")
101 ;; Insert body sorted by charset IDs.
102 (list-character-sets-1 'name
)))))
104 (defun sort-listed-character-sets (sort-key)
107 (let ((buffer-read-only nil
))
108 (goto-char (point-min))
109 (search-forward "\n-")
111 (delete-region (point) (point-max))
112 (list-character-sets-1 sort-key
)))))
114 (defun list-character-sets-1 (sort-key)
115 "Insert a list of character sets sorted by SORT-KEY.
116 SORT-KEY should be `name' or `iso-spec' (default `name')."
118 (setq sort-key
'name
))
119 (let ((tail charset-list
)
120 charset-info-list supplementary-list charset sort-func
)
121 (dolist (charset charset-list
)
122 ;; Generate a list that contains all information to display.
123 (let ((elt (list charset
124 (charset-dimension charset
)
125 (charset-chars charset
)
126 (charset-iso-final-char charset
))))
127 (if (plist-get (charset-plist charset
) :supplementary-p
)
128 (push elt supplementary-list
)
129 (push elt charset-info-list
))))
131 ;; Determine a predicate for `sort' by SORT-KEY.
133 (cond ((eq sort-key
'name
)
134 (lambda (x y
) (string< (car x
) (car y
))))
136 ((eq sort-key
'iso-spec
)
137 ;; Sort by DIMENSION CHARS FINAL-CHAR
140 (or (< (nth 1 x
) (nth 1 y
))
141 (and (= (nth 1 x
) (nth 1 y
))
142 (or (< (nth 2 x
) (nth 2 y
))
143 (and (= (nth 2 x
) (nth 2 y
))
144 (< (nth 3 x
) (nth 3 y
)))))))))
146 (error "Invalid charset sort key: %s" sort-key
))))
148 (setq charset-info-list
(sort charset-info-list sort-func
))
149 (setq supplementary-list
(sort supplementary-list sort-func
))
151 ;; Insert information of character sets.
152 (dolist (elt (append charset-info-list
(list t
) supplementary-list
))
154 (insert "-------------- Supplementary Character Sets --------------")
155 (insert-text-button (symbol-name (car elt
)) ; NAME
156 :type
'list-charset-chars
157 'help-args
(list (car elt
)))
158 (goto-char (point-max))
161 (insert (format "%d %3d "
162 (nth 1 elt
) (nth 2 elt
)) ; DIMENSION and CHARS
163 (if (< (nth 3 elt
) 0)
165 (nth 3 elt
)))) ; FINAL-CHAR
169 ;; List all character sets in a form that a program can easily parse.
171 (defun list-character-sets-2 ()
172 (insert "#########################
174 ## Each line corresponds to one charset.
175 ## The following attributes are listed in this order
176 ## separated by a colon `:' in one line.
177 ## CHARSET-SYMBOL-NAME,
179 ## CHARS (number of characters in first dimension of charset)
180 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
181 ## -1 means that no final character is assigned.
182 ## DESCRIPTION (describing string of the charset)
184 (dolist (charset charset-list
)
185 (princ (format "%s:%d:%d:%d:%s\n"
187 (charset-dimension charset
)
188 (charset-chars charset
)
189 ;;; (char-width (make-char charset))
190 ;;; (charset-direction charset)
191 (charset-iso-final-char charset
)
192 ;;; (charset-iso-graphic-plane charset)
193 (charset-description charset
)))))
195 (defvar non-iso-charset-alist nil
197 (make-obsolete-variable 'non-iso-charset-alist
"no longer relevant." "23.1")
199 (defun decode-codepage-char (codepage code
)
200 "Decode a character that has code CODE in CODEPAGE.
201 Return a decoded character string. Each CODEPAGE corresponds to a
202 coding system cpCODEPAGE."
203 (decode-char (intern (format "cp%d" codepage
)) code
))
204 (make-obsolete 'decode-codepage-char
'decode-char
"23.1")
206 ;; A variable to hold charset input history.
207 (defvar charset-history nil
)
211 (defun read-charset (prompt &optional default-value initial-input
)
212 "Read a character set from the minibuffer, prompting with string PROMPT.
213 It must be an Emacs character set listed in the variable `charset-list'.
215 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
216 DEFAULT-VALUE, if non-nil, is the default value.
217 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
218 See the documentation of the function `completing-read' for the detailed
219 meanings of these arguments."
220 (let* ((table (mapcar (lambda (x) (list (symbol-name x
))) charset-list
))
221 (charset (completing-read prompt table
222 nil t initial-input
'charset-history
224 (if (> (length charset
) 0)
227 ;; List characters of the range MIN and MAX of CHARSET. If dimension
228 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
229 ;; (block index) of the characters, and MIN and MAX are the second
230 ;; bytes of the characters. If the dimension is one, ROW should be 0.
232 (defun list-block-of-chars (charset row min max
)
234 (insert-char ?-
(+ 7 (* 4 16)))
238 (insert (format "%4X" i
))
240 (setq i
(* (/ min
16) 16))
243 (insert (format "\n%6Xx" (/ (+ (* row
256) i
) 16))))
244 (setq ch
(if (< i min
)
246 (or (decode-char charset
(+ (* row
256) i
))
247 32))) ; gap in mapping
248 ;; Don't insert control codes, non-Unicode characters.
249 (if (or (< ch
32) (= ch
127))
250 (setq ch
(single-key-description ch
))
251 (if (and (>= ch
128) (< ch
160))
252 (setq ch
(format "%02Xh" ch
))
260 (defun list-charset-chars (charset)
261 "Display a list of characters in character set CHARSET."
262 (interactive (list (read-charset "Character set: ")))
263 (or (charsetp charset
)
264 (error "Invalid character set: %s" charset
))
265 (with-output-to-temp-buffer "*Character List*"
266 (with-current-buffer standard-output
267 (if (coding-system-p charset
)
268 ;; Useful to be able to do C-u C-x = to find file code, for
270 (set-buffer-file-coding-system charset
))
271 (setq mode-line-format
(copy-sequence mode-line-format
))
272 (let ((slot (memq 'mode-line-buffer-identification mode-line-format
)))
275 (cons (format " (%s)" charset
)
278 (set-buffer-multibyte t
)
279 (let ((dim (charset-dimension charset
))
280 (chars (charset-chars charset
))
281 ;; (plane (charset-iso-graphic-plane charset))
283 (range (plist-get (charset-plist charset
) :code-space
))
286 (error "Can only list 1- and 2-dimensional charsets"))
287 (insert (format "Characters in the coded character set %s.\n" charset
))
288 (narrow-to-region (point) (point))
289 (setq min
(aref range
0)
292 (list-block-of-chars charset
0 min max
)
293 (setq min2
(aref range
2)
297 (list-block-of-chars charset i min max
)
299 (put-text-property (point-min) (point-max) 'charset charset
)
304 (defun describe-character-set (charset)
305 "Display information about built-in character set CHARSET."
306 (interactive (list (read-charset "Charset: ")))
307 (or (charsetp charset
)
308 (error "Invalid charset: %S" charset
))
309 (help-setup-xref (list #'describe-character-set charset
) (interactive-p))
310 (with-output-to-temp-buffer (help-buffer)
311 (with-current-buffer standard-output
312 (insert "Character set: " (symbol-name charset
))
313 (let ((name (get-charset-property charset
:name
)))
314 (if (not (eq name charset
))
315 (insert " (alias of " (symbol-name name
) ?\
))))
316 (insert "\n\n" (charset-description charset
) "\n\n")
317 (insert "Number of contained characters: ")
318 (dotimes (i (charset-dimension charset
))
321 (insert (format "%d" (charset-chars charset
(1+ i
)))))
323 (let ((char (charset-iso-final-char charset
)))
325 (insert "Final char of ISO2022 designation sequence: ")
326 (insert (format "`%c'\n" char
))))
327 (insert (format "Width (how many columns on screen): %d\n"
328 (aref char-width-table
(make-char charset
))))
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 of some other charset." nil
)))
359 (let ((val (get-charset-property charset
(car elt
))))
361 (if (cadr elt
) (insert (cadr elt
)))
363 (insert (funcall (nth 2 elt
) val
)))
368 (defvar graphic-register
) ; dynamic bondage
370 ;; Print information about designation of each graphic register in
371 ;; DESIGNATIONS in human readable format. See the documentation of
372 ;; `define-coding-system' for the meaning of DESIGNATIONS
373 ;; (`:designation' property).
374 (defun print-designation (designations)
376 (dotimes (graphic-register 4)
377 (setq charset
(aref designations graphic-register
))
381 (cond ((null charset
)
384 "no initial designation, and used by any charsets")
387 charset
(charset-description charset
)))
389 (if (charsetp (car charset
))
390 (format "%s:%s, and also used by the following:"
392 (charset-description (car charset
)))
393 "no initial designation, and used by the following:"))
395 "invalid designation information"))))
396 (when (listp charset
)
397 (setq charset
(cdr charset
))
399 (cond ((eq (car charset
) t
)
400 (princ "\tany other charsets\n"))
401 ((charsetp (car charset
))
402 (princ (format "\t%s:%s\n"
404 (charset-description (car charset
)))))
406 "invalid designation information"))
407 (setq charset
(cdr charset
)))))))
410 (defun describe-coding-system (coding-system)
411 "Display information about CODING-SYSTEM."
412 (interactive "zDescribe coding system (default current choices): ")
413 (if (null coding-system
)
414 (describe-current-coding-system)
415 (help-setup-xref (list #'describe-coding-system coding-system
)
417 (with-output-to-temp-buffer (help-buffer)
418 (print-coding-system-briefly coding-system
'doc-string
)
419 (let ((type (coding-system-type coding-system
))
421 (extra-spec (coding-system-plist coding-system
)))
424 (cond ((eq type
'undecided
)
425 (princ " (do automatic conversion)"))
427 (princ " (UTF-8: Emacs internal multibyte form)"))
429 ;; (princ " (UTF-16)")
431 ((eq type
'shift-jis
)
432 (princ " (Shift-JIS, MS-KANJI)"))
434 (princ " (variant of ISO-2022)\n")
435 (princ "Initial designations:\n")
436 (print-designation (coding-system-get coding-system
439 (when (coding-system-get coding-system
:flags
)
440 (princ "Other specifications: \n ")
442 (coding-system-get coding-system
:flags
))))
444 (princ " (charset)"))
446 (princ " (do conversion by CCL program)"))
448 (princ " (text with random binary characters)"))
449 ((eq type
'emacs-mule
)
450 (princ " (Emacs 21 internal encoding)"))
451 (t (princ ": invalid coding-system.")))
452 (princ "\nEOL type: ")
453 (let ((eol-type (coding-system-eol-type coding-system
)))
454 (cond ((vectorp eol-type
)
455 (princ "Automatic selection from:\n\t")
458 ((or (null eol-type
) (eq eol-type
0)) (princ "LF\n"))
459 ((eq eol-type
1) (princ "CRLF\n"))
460 ((eq eol-type
2) (princ "CR\n"))
461 (t (princ "invalid\n")))))
462 (let ((postread (coding-system-get coding-system
:post-read-conversion
)))
464 (princ "After decoding text normally,")
465 (princ " perform post-conversion using the function: ")
469 (let ((prewrite (coding-system-get coding-system
:pre-write-conversion
)))
471 (princ "Before encoding text normally,")
472 (princ " perform pre-conversion using the function: ")
476 (with-current-buffer standard-output
477 (let ((charsets (coding-system-charset-list coding-system
)))
478 (when (and (not (eq (coding-system-base coding-system
) 'raw-text
))
481 ((eq charsets
'iso-2022
)
482 (insert "This coding system can encode all ISO 2022 charsets."))
483 ((eq charsets
'emacs-mule
)
484 (insert "This coding system can encode all emacs-mule charsets\
487 (insert "This coding system encodes the following charsets:\n ")
489 (insert " " (symbol-name (car charsets
)))
490 (search-backward (symbol-name (car charsets
)))
491 (help-xref-button 0 'help-character-set
(car charsets
))
492 (goto-char (point-max))
493 (setq charsets
(cdr charsets
)))))))))))
496 (defun describe-current-coding-system-briefly ()
497 "Display coding systems currently used in a brief format in echo area.
499 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
500 where mnemonics of the following coding systems come in this order
502 `buffer-file-coding-system' (of the current buffer)
503 eol-type of `buffer-file-coding-system' (of the current buffer)
504 Value returned by `keyboard-coding-system'
505 eol-type of `keyboard-coding-system'
506 Value returned by `terminal-coding-system'.
507 eol-type of `terminal-coding-system'
508 `process-coding-system' for read (of the current buffer, if any)
509 eol-type of `process-coding-system' for read (of the current buffer, if any)
510 `process-coding-system' for write (of the current buffer, if any)
511 eol-type of `process-coding-system' for write (of the current buffer, if any)
512 `default-buffer-file-coding-system'
513 eol-type of `default-buffer-file-coding-system'
514 `default-process-coding-system' for read
515 eol-type of `default-process-coding-system' for read
516 `default-process-coding-system' for write
517 eol-type of `default-process-coding-system'"
519 (let* ((proc (get-buffer-process (current-buffer)))
520 (process-coding-systems (if proc
(process-coding-system proc
))))
522 "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]"
523 (coding-system-mnemonic buffer-file-coding-system
)
524 (coding-system-eol-type-mnemonic buffer-file-coding-system
)
525 (coding-system-mnemonic (keyboard-coding-system))
526 (coding-system-eol-type-mnemonic (keyboard-coding-system))
527 (coding-system-mnemonic (terminal-coding-system))
528 (coding-system-eol-type-mnemonic (terminal-coding-system))
529 (coding-system-mnemonic (car process-coding-systems
))
530 (coding-system-eol-type-mnemonic (car process-coding-systems
))
531 (coding-system-mnemonic (cdr process-coding-systems
))
532 (coding-system-eol-type-mnemonic (cdr process-coding-systems
))
533 (coding-system-mnemonic default-buffer-file-coding-system
)
534 (coding-system-eol-type-mnemonic default-buffer-file-coding-system
)
535 (coding-system-mnemonic (car default-process-coding-system
))
536 (coding-system-eol-type-mnemonic (car default-process-coding-system
))
537 (coding-system-mnemonic (cdr default-process-coding-system
))
538 (coding-system-eol-type-mnemonic (cdr default-process-coding-system
))
541 (defun print-coding-system-briefly (coding-system &optional doc-string
)
542 "Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
543 If DOC-STRING is non-nil, print also the docstring of CODING-SYSTEM.
544 If DOC-STRING is `tightly', don't print an empty line before the
545 docstring, and print only the first line of the docstring."
546 (if (not coding-system
)
548 (princ (format "%c -- %s"
549 (coding-system-mnemonic coding-system
)
551 (let ((aliases (coding-system-aliases coding-system
)))
552 (cond ((eq coding-system
(car aliases
))
554 (princ (format " %S" (cons 'alias
: (cdr aliases
))))))
555 ((memq coding-system aliases
)
556 (princ (format " (alias of %s)" (car aliases
))))
558 (let ((eol-type (coding-system-eol-type coding-system
))
559 (base-eol-type (coding-system-eol-type (car aliases
))))
560 (if (and (integerp eol-type
)
561 (vectorp base-eol-type
)
562 (not (eq coding-system
(aref base-eol-type eol-type
))))
563 (princ (format " (alias of %s)"
564 (aref base-eol-type eol-type
))))))))
566 (or (eq doc-string
'tightly
)
569 (let ((doc (or (coding-system-doc-string coding-system
) "")))
570 (when (eq doc-string
'tightly
)
571 (if (string-match "\n" doc
)
572 (setq doc
(substring doc
0 (match-beginning 0))))
573 (setq doc
(concat " " doc
)))
574 (princ (format "%s\n" doc
))))))
577 (defun describe-current-coding-system ()
578 "Display coding systems currently used, in detail."
580 (with-output-to-temp-buffer "*Help*"
581 (let* ((proc (get-buffer-process (current-buffer)))
582 (process-coding-systems (if proc
(process-coding-system proc
))))
583 (princ "Coding system for saving this buffer:\n ")
584 (if (local-variable-p 'buffer-file-coding-system
)
585 (print-coding-system-briefly buffer-file-coding-system
)
586 (princ "Not set locally, use the default.\n"))
587 (princ "Default coding system (for new files):\n ")
588 (print-coding-system-briefly default-buffer-file-coding-system
)
589 (princ "Coding system for keyboard input:\n ")
590 (print-coding-system-briefly (keyboard-coding-system))
591 (princ "Coding system for terminal output:\n ")
592 (print-coding-system-briefly (terminal-coding-system))
593 (when (boundp 'selection-coding-system
)
594 (princ "Coding system for inter-client cut and paste:\n ")
595 (print-coding-system-briefly selection-coding-system
))
596 (when (get-buffer-process (current-buffer))
597 (princ "Coding systems for process I/O:\n")
598 (princ " encoding input to the process: ")
599 (print-coding-system-briefly (cdr process-coding-systems
))
600 (princ " decoding output from the process: ")
601 (print-coding-system-briefly (car process-coding-systems
)))
602 (princ "Defaults for subprocess I/O:\n")
603 (princ " decoding: ")
604 (print-coding-system-briefly (car default-process-coding-system
))
605 (princ " encoding: ")
606 (print-coding-system-briefly (cdr default-process-coding-system
)))
608 (with-current-buffer standard-output
611 Priority order for recognizing coding systems when reading files:\n")
613 (dolist (elt (coding-system-priority-list))
614 (princ (format " %d. %s " i elt
))
615 (let ((aliases (coding-system-aliases elt
)))
616 (if (eq elt
(car aliases
))
618 (princ (cons 'alias
: (cdr aliases
))))
619 (princ (list 'alias
'of
(car aliases
))))
623 (princ "\n Other coding systems cannot be distinguished automatically
624 from these, and therefore cannot be recognized automatically
625 with the present coding system priorities.\n\n")
627 ;; Fixme: should this be replaced or junked?
629 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
630 coding-system codings
)
632 (setq coding-system
(symbol-value (car categories
)))
635 (if (and (not (eq x coding-system
))
636 (let ((flags (coding-system-get :flags
)))
637 (not (or (memq 'use-roman flags
)
638 (memq 'use-oldjis flags
)))))
639 (setq codings
(cons x codings
))))
640 (get (car categories
) 'coding-systems
))
642 (let ((max-col (window-width))
645 The following are decoded correctly but recognized as %s:\n "
649 (insert (format " %s" (car codings
)))
650 (when (> (current-column) max-col
)
653 (goto-char (point-max)))
654 (setq codings
(cdr codings
)))
656 (setq categories
(cdr categories
)))))
658 (princ "Particular coding systems specified for certain file names:\n")
660 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
661 (princ " ---------\t--------------\t\t----------------\n")
662 (let ((func (lambda (operation alist
)
666 (princ "\tnothing specified\n")
669 (prin1 (car (car alist
)))
670 (if (>= (current-column) 40)
673 (princ (cdr (car alist
)))
675 (setq alist
(cdr alist
)))))))
676 (funcall func
"File I/O" file-coding-system-alist
)
677 (funcall func
"Process I/O" process-coding-system-alist
)
678 (funcall func
"Network I/O" network-coding-system-alist
))
681 (defun print-coding-system (coding-system)
682 "Print detailed information on CODING-SYSTEM."
683 (let ((type (coding-system-type coding-system
))
684 (eol-type (coding-system-eol-type coding-system
))
685 (flags (coding-system-get coding-system
:flags
))
686 (aliases (coding-system-aliases coding-system
)))
687 (if (not (eq (car aliases
) coding-system
))
688 (princ (format "%s (alias of %s)\n" coding-system
(car aliases
)))
689 (princ coding-system
)
690 (dolist (alias (cdr aliases
))
693 (princ (format ":%s:%c:%d:"
695 (coding-system-mnemonic coding-system
)
696 (if (integerp eol-type
) eol-type
3)))
697 (cond ((eq type
'iso2022
)
701 (setq charset
(aref flags idx
))
702 (cond ((null charset
)
710 (princ (car charset
))
711 (setq charset
(cdr charset
))
714 (princ (car charset
))
715 (setq charset
(cdr charset
)))
720 (princ (if (aref flags idx
) 1 0))
723 (princ (if (aref flags idx
) 1 0))))
726 (if (symbolp (car flags
))
727 (princ (format " %s" (car flags
)))
728 (setq i
0 len
(length (car flags
)))
730 (princ (format " %x" (aref (car flags
) i
)))
733 (if (symbolp (cdr flags
))
734 (princ (format "%s" (cdr flags
)))
735 (setq i
0 len
(length (cdr flags
)))
737 (princ (format " %x" (aref (cdr flags
) i
)))
741 (princ (coding-system-doc-string coding-system
))
745 (defun list-coding-systems (&optional arg
)
746 "Display a list of all coding systems.
747 This shows the mnemonic letter, name, and description of each coding system.
749 With prefix ARG, the output format gets more cryptic,
750 but still contains full information about each coding system."
752 (with-output-to-temp-buffer "*Help*"
753 (list-coding-systems-1 arg
)))
755 (defun list-coding-systems-1 (arg)
758 ###############################################
759 # List of coding systems in the following format:
760 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
764 #########################
765 ## LIST OF CODING SYSTEMS
766 ## Each line corresponds to one coding system
767 ## Format of a line is:
768 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
769 ## :PRE-WRITE-CONVERSION:DOC-STRING,
771 ## NAME = coding system name
772 ## ALIAS = alias of the coding system
773 ## TYPE = nil (no conversion), t (undecided or automatic detection),
774 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
775 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
778 ## comma (`,') separated data of the following:
779 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
780 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
781 ## else if TYPE = 4 then
782 ## comma (`,') separated CCL programs for read and write
785 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
788 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only
)))
790 (print-coding-system-briefly coding-system
'tightly
)
791 (print-coding-system coding-system
))))
795 (defun list-coding-categories ()
796 "Display a list of all coding categories."
797 (with-output-to-temp-buffer "*Help*"
799 ############################
800 ## LIST OF CODING CATEGORIES (ordered by priority)
801 ## CATEGORY:CODING-SYSTEM
804 (let ((l coding-category-list
))
806 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
811 (declare-function font-info
"font.c" (name &optional frame
))
813 (defun describe-font-internal (font-info &optional ignored
)
814 "Print information about a font in FONT-INFO.
815 The IGNORED argument is ignored."
816 (print-list "name (opened by):" (aref font-info
0))
817 (print-list " full name:" (aref font-info
1))
818 (print-list " size:" (format "%2d" (aref font-info
2)))
819 (print-list " height:" (format "%2d" (aref font-info
3)))
820 (print-list " baseline-offset:" (format "%2d" (aref font-info
4)))
821 (print-list "relative-compose:" (format "%2d" (aref font-info
5))))
824 (defun describe-font (fontname)
825 "Display information about a font whose name is FONTNAME.
826 The font must be already used by Emacs."
827 (interactive "sFont name (default current choice for ASCII chars): ")
828 (or (and window-system
(fboundp 'fontset-list
))
829 (error "No fonts being used"))
831 (if (or (not fontname
) (= (length fontname
) 0))
832 (setq fontname
(face-attribute 'default
:font
)))
833 (setq font-info
(font-info fontname
))
835 (if (fontp fontname
'font-object
)
836 ;; The font should be surely used. So, there's some
837 ;; problem about getting information about it. It is
838 ;; better to print the fontname to show which font has
840 (message "No information about \"%s\"" (font-xlfd-name fontname
))
841 (message "No matching font found"))
842 (with-output-to-temp-buffer "*Help*"
843 (describe-font-internal font-info
)))))
845 (defun print-fontset-element (val)
846 ;; VAL has this format:
847 ;; ((REQUESTED-FONT-NAME OPENED-FONT-NAME ...) ...)
848 ;; CHAR RANGE is already inserted. Get character codes from
851 (let ((from (following-char))
852 (to (if (looking-at "[^.]*[.]* ")
853 (char-after (match-end 0)))))
854 (if (re-search-forward "[ \t]*$" nil t
)
855 (delete-region (match-beginning 0) (match-end 0)))
857 ;; For non-ASCII characters, insert also CODE RANGE.
858 (if (or (>= from
128) (and to
(>= to
128)))
860 (insert (format " (#x%02X .. #x%02X)" from to
))
861 (insert (format " (#x%02X)" from
))))
863 ;; Insert a requested font name.
866 (insert "\n -- inhibit fallback fonts --")
867 (let ((requested (car elt
)))
868 (if (stringp requested
)
869 (insert "\n " requested
)
870 (let (family registry weight slant width adstyle
)
871 (if (and (fboundp 'fontp
) (fontp requested
))
872 (setq family
(font-get requested
:family
)
873 registry
(font-get requested
:registry
)
874 weight
(font-get requested
:weight
)
875 slant
(font-get requested
:slant
)
876 width
(font-get requested
:width
)
877 adstyle
(font-get requested
:adstyle
))
878 (setq family
(aref requested
0)
879 registry
(aref requested
5)
880 weight
(aref requested
1)
881 slant
(aref requested
2)
882 width
(aref requested
3)
883 adstyle
(aref requested
4)))
887 (setq family
(symbol-name family
)))
888 (or (string-match "-" family
)
889 (setq family
(concat "*-" family
))))
891 (setq registry
"*-*")
892 (if (symbolp registry
)
893 (setq registry
(symbol-name registry
)))
894 (or (string-match "-" registry
)
895 (= (aref registry
(1- (length registry
))) ?
*)
896 (setq registry
(concat registry
"*"))))
897 (insert (format"\n -%s-%s-%s-%s-%s-*-*-*-*-*-*-%s"
898 family
(or weight
"*") (or slant
"*") (or width
"*")
899 (or adstyle
"*") registry
)))))
901 ;; Insert opened font names (if any).
902 (if (and (boundp 'print-opened
) (symbol-value 'print-opened
))
903 (dolist (opened (cdr elt
))
904 (insert "\n\t[" opened
"]")))))))
906 (declare-function query-fontset
"fontset.c" (pattern &optional regexpp
))
907 (declare-function fontset-info
"fontset.c" (fontset &optional frame
))
909 (defun print-fontset (fontset &optional print-opened
)
910 "Print information about FONTSET.
911 FONTSET nil means the fontset of the selected frame, t means the
913 If optional arg PRINT-OPENED is non-nil, also print names of all opened
914 fonts for FONTSET. This function actually inserts the information in
917 (setq fontset
(query-fontset "fontset-default"))
919 (setq fontset
(face-attribute 'default
:fontset
))))
921 (narrow-to-region (point) (point))
922 (insert "Fontset: " fontset
"\n")
923 (insert (propertize "CHAR RANGE" 'face
'underline
)
924 " (" (propertize "CODE RANGE" 'face
'underline
) ")\n")
925 (insert " " (propertize "FONT NAME" 'face
'underline
)
926 " (" (propertize "REQUESTED" 'face
'underline
)
927 " and [" (propertize "OPENED" 'face
'underline
) "])")
928 (let* ((info (fontset-info fontset
))
929 (default-info (char-table-extra-slot info
0))
930 start1 end1 start2 end2
)
931 (describe-vector info
'print-fontset-element
)
932 (when (char-table-range info nil
)
933 ;; The default of FONTSET is described.
934 (setq start1
(re-search-backward "^default"))
935 (delete-region (point) (line-end-position))
936 (insert "\n ---<fallback to the default of the specified fontset>---")
937 (put-text-property (line-beginning-position) (point) 'face
'highlight
)
938 (goto-char (point-max))
939 (setq end1
(setq start2
(point))))
941 (insert "\n ---<fallback to the default fontset>---")
942 (put-text-property (line-beginning-position) (point) 'face
'highlight
)
943 (describe-vector default-info
'print-fontset-element
)
944 (when (char-table-range default-info nil
)
945 ;; The default of the default fontset is described.
946 (setq end2
(re-search-backward "^default"))
947 (delete-region (point) (line-end-position))
948 (insert "\n ---<fallback to the default of the default fontset>---")
949 (put-text-property (line-beginning-position) (point) 'face
'highlight
)))
950 (if (and start1 end2
)
951 ;; Reoder the printed information to match with the font
952 ;; searching strategy; i.e. FONTSET, the default fontset,
953 ;; default of FONTSET, default of the default fontset.
954 (transpose-regions start1 end1 start2 end2
))
955 (goto-char (point-max)))
958 (defvar fontset-alias-alist
)
959 (declare-function fontset-list
"fontset.c" ())
962 (defun describe-fontset (fontset)
963 "Display information about FONTSET.
964 This shows which font is used for which character(s)."
966 (if (not (and window-system
(fboundp 'fontset-list
)))
967 (error "No fontsets being used")
968 (let ((fontset-list (nconc
970 (mapcar 'cdr fontset-alias-alist
)))
971 (completion-ignore-case t
))
972 (list (completing-read
973 "Fontset (default used by the current frame): "
974 fontset-list nil t
)))))
975 (if (= (length fontset
) 0)
976 (setq fontset
(face-attribute 'default
:fontset
))
977 (setq fontset
(query-fontset fontset
)))
978 (help-setup-xref (list #'describe-fontset fontset
) (interactive-p))
979 (with-output-to-temp-buffer (help-buffer)
980 (with-current-buffer standard-output
981 (print-fontset fontset t
))))
983 (declare-function fontset-plain-name
"fontset" (fontset))
986 (defun list-fontsets (arg)
987 "Display a list of all fontsets.
988 This shows the name, size, and style of each fontset.
989 With prefix arg, also list the fonts contained in each fontset;
990 see the function `describe-fontset' for the format of the list."
992 (if (not (and window-system
(fboundp 'fontset-list
)))
993 (error "No fontsets being used")
994 (help-setup-xref (list #'list-fontsets arg
) (interactive-p))
995 (with-output-to-temp-buffer (help-buffer)
996 (with-current-buffer standard-output
997 ;; This code is duplicated near the end of mule-diag.
1001 (string< (fontset-plain-name x
)
1002 (fontset-plain-name y
))))))
1005 (print-fontset (car fontsets
) nil
)
1006 (insert "Fontset: " (car fontsets
) "\n"))
1007 (setq fontsets
(cdr fontsets
))))))))
1010 (defun list-input-methods ()
1011 "Display information about all input methods."
1013 (help-setup-xref '(list-input-methods) (interactive-p))
1014 (with-output-to-temp-buffer (help-buffer)
1015 (list-input-methods-1)
1016 (with-current-buffer standard-output
1018 (goto-char (point-min))
1019 (while (re-search-forward
1020 "^ \\([^ ]+\\) (`.*' in mode line)$" nil t
)
1021 (help-xref-button 1 'help-input-method
(match-string 1)))))))
1023 (defun list-input-methods-1 ()
1024 (if (not input-method-alist
)
1026 No input method is available, perhaps because you have not
1027 installed LEIM (Libraries of Emacs Input Methods).")
1028 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1029 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1030 (setq input-method-alist
1031 (sort input-method-alist
1032 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
1035 (dolist (elt input-method-alist
)
1036 (when (not (equal language
(nth 1 elt
)))
1037 (setq language
(nth 1 elt
))
1040 (princ (format " %s (`%s' in mode line)\n %s\n"
1042 (let ((title (nth 3 elt
)))
1043 (if (and (consp title
) (stringp (car title
)))
1050 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1051 (defun insert-section (section-number title
)
1052 (insert "########################################\n"
1053 "# Section " (format "%d" section-number
) ". " title
"\n"
1054 "########################################\n\n"))
1058 "Display diagnosis of the multilingual environment (Mule).
1060 This shows various information related to the current multilingual
1061 environment, including lists of input methods, coding systems,
1062 character sets, and fontsets (if Emacs is running under a window
1063 system which uses fontsets)."
1065 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1066 (with-current-buffer standard-output
1067 (insert "###############################################\n"
1068 "### Current Status of Multilingual Features ###\n"
1069 "###############################################\n\n"
1070 "CONTENTS: Section 1. General Information\n"
1071 " Section 2. Display\n"
1072 " Section 3. Input methods\n"
1073 " Section 4. Coding systems\n"
1074 " Section 5. Character sets\n")
1075 (if (and window-system
(fboundp 'fontset-list
))
1076 (insert " Section 6. Fontsets\n"))
1079 (insert-section 1 "General Information")
1080 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1081 (insert "Configuration options:\n " system-configuration-options
"\n\n")
1082 (insert "Multibyte characters awareness:\n"
1083 (format " default: %S\n" default-enable-multibyte-characters
)
1084 (format " current-buffer: %S\n\n" enable-multibyte-characters
))
1085 (insert "Current language environment: " current-language-environment
1088 (insert-section 2 "Display")
1090 (insert (format "Window-system: %s, version %s"
1091 window-system window-system-version
))
1092 (insert "Terminal: " (getenv "TERM")))
1096 (let ((font (cdr (assq 'font
(frame-parameters)))))
1097 (insert "The font and fontset of the selected frame are:\n"
1099 " fontset: " (face-attribute 'default
:fontset
) "\n"))
1100 (insert "Coding system of the terminal: "
1101 (symbol-name (terminal-coding-system))))
1104 (insert-section 3 "Input methods")
1105 (list-input-methods-1)
1107 (if default-input-method
1108 (insert (format "Default input method: %s\n" default-input-method
))
1109 (insert "No default input method is specified\n"))
1111 (insert-section 4 "Coding systems")
1112 (list-coding-systems-1 t
)
1115 (insert-section 5 "Character sets")
1116 (list-character-sets-2)
1119 (when (and window-system
(fboundp 'fontset-list
))
1120 ;; This code duplicates most of list-fontsets.
1121 (insert-section 6 "Fontsets")
1122 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1123 (insert "------------\t\t\t\t\t\t ----- -----\n")
1124 (dolist (fontset (fontset-list))
1125 (print-fontset fontset t
)))
1126 (print-help-return-message))))
1129 (defun font-show-log (&optional limit
)
1130 "Show log of font listing and opening.
1131 Prefix arg LIMIT says how many fonts to show for each listing.
1132 The default is 20. If LIMIT is negative, do not limit the listing."
1134 (setq limit
(if limit
(prefix-numeric-value limit
) 20))
1136 (message "Font logging is currently suppressed")
1137 (with-output-to-temp-buffer "*Help*"
1138 (set-buffer standard-output
)
1139 (dolist (elt (reverse font-log
))
1140 (insert (format "%s: %s\n" (car elt
) (cadr elt
)))
1141 (setq elt
(nth 2 elt
))
1142 (if (or (vectorp elt
) (listp elt
))
1150 (insert (format " %s\n" x
)))
1152 (insert (format " %s\n" elt
)))))))
1155 (provide 'mule-diag
)
1157 ;; arch-tag: cd3b607c-2893-45a0-a4fa-a6535754dbee
1158 ;;; mule-diag.el ends here