1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003
4 ;; Free Software Foundation, Inc.
5 ;; Copyright (C) 1995, 1997, 1999, 2000, 2001, 2002, 2003
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 2, or (at your option)
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; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 ;; Boston, MA 02110-1301, USA.
35 ;; Make sure the help-xref button type is defined.
38 ;;; General utility function
40 (defun print-list (&rest args
)
41 "Print all arguments with single space separator in one line."
46 (setq args
(cdr args
)))
52 (define-button-type 'sort-listed-character-sets
53 'help-echo
(purecopy "mouse-2, RET: sort on this column")
55 'action
#'(lambda (button)
56 (sort-listed-character-sets (button-get button
'sort-key
))))
58 (define-button-type 'list-charset-chars
60 'help-function
#'list-charset-chars
61 'help-echo
"mouse-2, RET: show table of characters for this character set")
64 (defun list-character-sets (arg)
65 "Display a list of all character sets.
67 The D column contains the dimension of this character set. The CH
68 column contains the number of characters in a block of this character
69 set. The FINAL-CHAR column contains an ISO-2022 <final-char> to use
70 for designating this character set in ISO-2022-based coding systems.
72 With prefix arg, the output format gets more cryptic,
73 but still shows the full information."
75 (help-setup-xref (list #'list-character-sets arg
) (interactive-p))
76 (with-output-to-temp-buffer "*Character Set List*"
77 (with-current-buffer standard-output
79 (list-character-sets-2)
81 (insert "Supplementary character sets are shown below.\n")
83 (substitute-command-keys
85 (if (display-mouse-p) "\\[help-follow-mouse] or ")
86 "\\[help-follow]:\n")))
87 (insert " on a column title to sort by that title,")
89 (insert "+----DIMENSION\n")
90 (insert " on a charset name to list characters.")
92 (insert "| +--CHARS\n")
93 (let ((columns '(("CHARSET-NAME" . name
) "\t\t\t\t\t"
94 ("D CH FINAL-CHAR" . iso-spec
)))
97 (if (stringp (car columns
))
98 (insert (car columns
))
99 (insert-text-button (car (car columns
))
100 :type
'sort-listed-character-sets
101 'sort-key
(cdr (car columns
)))
102 (goto-char (point-max)))
103 (setq columns
(cdr columns
)))
105 (insert "------------\t\t\t\t\t- --- ----------\n")
107 ;; Insert body sorted by charset IDs.
108 (list-character-sets-1 'name
)))))
110 (defun sort-listed-character-sets (sort-key)
113 (let ((buffer-read-only nil
))
114 (goto-char (point-min))
115 (search-forward "\n-")
117 (delete-region (point) (point-max))
118 (list-character-sets-1 sort-key
)))))
120 (defun list-character-sets-1 (sort-key)
121 "Insert a list of character sets sorted by SORT-KEY.
122 SORT-KEY should be `name' or `iso-spec' (default `name')."
124 (setq sort-key
'name
))
125 (let ((tail charset-list
)
126 charset-info-list supplementary-list charset sort-func
)
127 (dolist (charset charset-list
)
128 ;; Generate a list that contains all information to display.
129 (let ((elt (list charset
130 (charset-dimension charset
)
131 (charset-chars charset
)
132 (charset-iso-final-char charset
))))
133 (if (plist-get (charset-plist charset
) :supplementary-p
)
134 (push elt supplementary-list
)
135 (push elt charset-info-list
))))
137 ;; Determine a predicate for `sort' by SORT-KEY.
139 (cond ((eq sort-key
'name
)
140 (lambda (x y
) (string< (car x
) (car y
))))
142 ((eq sort-key
'iso-spec
)
143 ;; Sort by DIMENSION CHARS FINAL-CHAR
146 (or (< (nth 1 x
) (nth 1 y
))
147 (and (= (nth 1 x
) (nth 1 y
))
148 (or (< (nth 2 x
) (nth 2 y
))
149 (and (= (nth 2 x
) (nth 2 y
))
150 (< (nth 3 x
) (nth 3 y
)))))))))
152 (error "Invalid charset sort key: %s" sort-key
))))
154 (setq charset-info-list
(sort charset-info-list sort-func
))
155 (setq supplementary-list
(sort supplementary-list sort-func
))
157 ;; Insert information of character sets.
158 (dolist (elt (append charset-info-list
(list t
) supplementary-list
))
160 (insert "-------------- Supplementary Character Sets --------------")
161 (insert-text-button (symbol-name (car elt
)) ; NAME
162 :type
'list-charset-chars
163 'help-args
(list (car elt
)))
164 (goto-char (point-max))
167 (insert (format "%d %3d "
168 (nth 1 elt
) (nth 2 elt
)) ; DIMENSION and CHARS
169 (if (< (nth 3 elt
) 0)
171 (nth 3 elt
)))) ; FINAL-CHAR
175 ;; List all character sets in a form that a program can easily parse.
177 (defun list-character-sets-2 ()
178 (insert "#########################
180 ## Each line corresponds to one charset.
181 ## The following attributes are listed in this order
182 ## separated by a colon `:' in one line.
183 ## CHARSET-SYMBOL-NAME,
184 ## DIMENSION (1 or 2)
186 ## WIDTH (occupied column numbers: 1 or 2),
187 ## DIRECTION (0:left-to-right, 1:right-to-left),
188 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
189 ## ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR)
190 ## DESCRIPTION (describing string of the charset)
192 (let ((l charset-list
)
195 (setq charset
(car l
) l
(cdr l
))
196 (princ (format "%s:%d:%d:%d:%d:%s\n"
198 (charset-dimension charset
)
199 (charset-chars charset
)
200 (aref char-width-table
(make-char charset
))
201 ;;; (charset-direction charset)
202 (charset-iso-final-char charset
)
203 ;;; (charset-iso-graphic-plane charset)
204 (charset-description charset
))))))
206 (defvar non-iso-charset-alist nil
208 (make-obsolete-variable 'non-iso-charset-alist
"no longer relevant" "23.1")
210 (defun decode-codepage-char (codepage code
)
211 "Decode a character that has code CODE in CODEPAGE.
212 Return a decoded character string. Each CODEPAGE corresponds to a
213 coding system cpCODEPAGE. This function is obsolete."
214 (decode-char (intern (format "cp%d" codepage
)) code
))
215 (make-obsolete 'decode-codepage-char
'decode-char
"23.1")
217 ;; A variable to hold charset input history.
218 (defvar charset-history nil
)
222 (defun read-charset (prompt &optional default-value initial-input
)
223 "Read a character set from the minibuffer, prompting with string PROMPT.
224 It must be an Emacs character set listed in the variable `charset-list'.
226 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
227 DEFAULT-VALUE, if non-nil, is the default value.
228 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
229 See the documentation of the function `completing-read' for the
230 detailed meanings of these arguments."
231 (let* ((table (mapcar (lambda (x) (list (symbol-name x
))) charset-list
))
232 (charset (completing-read prompt table
233 nil t initial-input
'charset-history
235 (if (> (length charset
) 0)
238 ;; List characters of the range MIN and MAX of CHARSET. If dimension
239 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
240 ;; (block index) of the characters, and MIN and MAX are the second
241 ;; bytes of the characters. If the dimension is one, ROW should be 0.
243 (defun list-block-of-chars (charset row min max
)
245 (insert-char ?-
(+ 7 (* 4 16)))
249 (insert (format "%4X" i
))
251 (setq i
(* (/ min
16) 16))
254 (insert (format "\n%6Xx" (/ (+ (* row
256) i
) 16))))
255 (setq ch
(if (< i min
)
257 (or (decode-char charset
(+ (* row
256) i
))
258 32))) ; gap in mapping
259 ;; Don't insert a control code.
260 (if (or (< ch
32) (= ch
127))
261 (setq ch
(single-key-description ch
))
262 (if (and (>= ch
128) (< ch
160))
263 (setq ch
(format "%02Xh" ch
))))
269 (defun list-charset-chars (charset)
270 "Display a list of characters in character set CHARSET."
271 (interactive (list (read-charset "Character set: ")))
272 (or (charsetp charset
)
273 (error "Invalid character set: %s" charset
))
274 (with-output-to-temp-buffer "*Character List*"
275 (with-current-buffer standard-output
276 (if (coding-system-p charset
)
277 ;; Useful to be able to do C-u C-x = to find file code, for
279 (set-buffer-file-coding-system charset
))
280 (setq mode-line-format
(copy-sequence mode-line-format
))
281 (let ((slot (memq 'mode-line-buffer-identification mode-line-format
)))
284 (cons (format " (%s)" charset
)
287 (set-buffer-multibyte t
)
288 (let ((dim (charset-dimension charset
))
289 (chars (charset-chars charset
))
290 ;; (plane (charset-iso-graphic-plane charset))
292 (range (plist-get (charset-plist charset
) :code-space
))
295 (error "Can only list 1- and 2-dimensional charsets"))
296 (insert (format "Characters in the coded character set %s.\n" charset
))
297 (narrow-to-region (point) (point))
298 (setq min
(aref range
0)
301 (list-block-of-chars charset
0 min max
)
302 (setq min2
(aref range
2)
306 (list-block-of-chars charset i min max
)
308 (put-text-property (point-min) (point-max) 'charset charset
)
313 (defun describe-character-set (charset)
314 "Display information about built-in character set CHARSET."
315 (interactive (list (read-charset "Charset: ")))
316 (or (charsetp charset
)
317 (error "Invalid charset: %S" charset
))
318 (help-setup-xref (list #'describe-character-set charset
) (interactive-p))
319 (with-output-to-temp-buffer (help-buffer)
320 (with-current-buffer standard-output
321 (insert "Character set: " (symbol-name charset
))
322 (let ((name (get-charset-property charset
:name
)))
323 (if (not (eq name charset
))
324 (insert " (alias of " (symbol-name name
) ?\
))))
325 (insert "\n\n" (charset-description charset
) "\n\n")
326 (insert "Number of contained characters: ")
327 (dotimes (i (charset-dimension charset
))
330 (insert (format "%d" (charset-chars charset
(1+ i
)))))
332 (let ((char (charset-iso-final-char charset
)))
334 (insert "Final char of ISO2022 designation sequence: ")
335 (insert (format "`%c'\n" char
))))
336 (insert (format "Width (how many columns on screen): %d\n"
337 (aref char-width-table
(make-char charset
))))
339 (dolist (c charset-list
)
340 (if (and (not (eq c charset
))
341 (eq charset
(get-charset-property c
:name
)))
344 (insert "Aliases: " (mapconcat #'symbol-name aliases
", ") ?
\n)))
346 (dolist (elt `((:ascii-compatible-p
"ASCII compatible." nil
)
347 (:map
"Map file: " identity
)
348 (:unify-map
"Unification map file: " identity
)
352 (format "Invalid character: %c (code %d)" c c
)))
353 (:emacs-mule-id
"Id in emacs-mule coding system: "
355 (:parents
"Parents: "
357 (mapconcat ,(lambda (elt)
361 (:code-space
"Code space: " ,(lambda (c)
363 (:code-offset
"Code offset: " number-to-string
)
364 (:iso-revision-number
"ISO revision number: "
367 "Used only as a parent of some other charset." nil
)))
368 (let ((val (get-charset-property charset
(car elt
))))
370 (if (cadr elt
) (insert (cadr elt
)))
372 (insert (funcall (nth 2 elt
) val
)))
377 (eval-when-compile ; dynamic bondage
378 (defvar graphic-register
))
380 ;; Print information about designation of each graphic register in
381 ;; DESIGNATIONS in human readable format. See the documentation of
382 ;; `define-coding-system' for the meaning of DESIGNATIONS
383 ;; (`:designation' property).
384 (defun print-designation (designations)
386 (dotimes (graphic-register 4)
387 (setq charset
(aref designations graphic-register
))
391 (cond ((null charset
)
394 "no initial designation, and used by any charsets")
397 charset
(charset-description charset
)))
399 (if (charsetp (car charset
))
400 (format "%s:%s, and also used by the following:"
402 (charset-description (car charset
)))
403 "no initial designation, and used by the following:"))
405 "invalid designation information"))))
406 (when (listp charset
)
407 (setq charset
(cdr charset
))
409 (cond ((eq (car charset
) t
)
410 (princ "\tany other charsets\n"))
411 ((charsetp (car charset
))
412 (princ (format "\t%s:%s\n"
414 (charset-description (car charset
)))))
416 "invalid designation information"))
417 (setq charset
(cdr charset
)))))))
420 (defun describe-coding-system (coding-system)
421 "Display information about CODING-SYSTEM."
422 (interactive "zDescribe coding system (default current choices): ")
423 (if (null coding-system
)
424 (describe-current-coding-system)
425 (help-setup-xref (list #'describe-coding-system coding-system
)
427 (with-output-to-temp-buffer (help-buffer)
428 (print-coding-system-briefly coding-system
'doc-string
)
429 (let ((type (coding-system-type coding-system
))
431 (extra-spec (coding-system-plist coding-system
)))
434 (cond ((eq type
'undecided
)
435 (princ " (do automatic conversion)"))
437 (princ " (UTF-8: Emacs internal multibyte form)"))
439 ;; (princ " (UTF-16)")
441 ((eq type
'shift-jis
)
442 (princ " (Shift-JIS, MS-KANJI)"))
444 (princ " (variant of ISO-2022)\n")
445 (princ "Initial designations:\n")
446 (print-designation (coding-system-get coding-system
449 (when (coding-system-get coding-system
:flags
)
450 (princ "Other specifications: \n ")
452 (coding-system-get coding-system
:flags
))))
454 (princ " (charset)"))
456 (princ " (do conversion by CCL program)"))
458 (princ " (text with random binary characters)"))
459 ((eq type
'emacs-mule
)
460 (princ " (Emacs 21 internal encoding)"))
461 (t (princ ": invalid coding-system.")))
462 (princ "\nEOL type: ")
463 (let ((eol-type (coding-system-eol-type coding-system
)))
464 (cond ((vectorp eol-type
)
465 (princ "Automatic selection from:\n\t")
468 ((or (null eol-type
) (eq eol-type
0)) (princ "LF\n"))
469 ((eq eol-type
1) (princ "CRLF\n"))
470 ((eq eol-type
2) (princ "CR\n"))
471 (t (princ "invalid\n")))))
472 (let ((postread (coding-system-get coding-system
:post-read-conversion
)))
474 (princ "After decoding text normally,")
475 (princ " perform post-conversion using the function: ")
479 (let ((prewrite (coding-system-get coding-system
:pre-write-conversion
)))
481 (princ "Before encoding text normally,")
482 (princ " perform pre-conversion using the function: ")
486 (with-current-buffer standard-output
487 (let ((charsets (coding-system-charset-list coding-system
)))
488 (when (and (not (eq (coding-system-base coding-system
) 'raw-text
))
491 ((eq charsets
'iso-2022
)
492 (insert "This coding system can encode all ISO 2022 charsets."))
493 ((eq charsets
'emacs-mule
)
494 (insert "This coding system can encode all emacs-mule charsets\
497 (insert "This coding system encodes the following charsets:\n ")
499 (insert " " (symbol-name (car charsets
)))
500 (search-backward (symbol-name (car charsets
)))
501 (help-xref-button 0 'help-character-set
(car charsets
))
502 (goto-char (point-max))
503 (setq charsets
(cdr charsets
)))))))))))
506 (defun describe-current-coding-system-briefly ()
507 "Display coding systems currently used in a brief format in echo area.
509 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
510 where mnemonics of the following coding systems come in this order
512 `buffer-file-coding-system' (of the current buffer)
513 eol-type of `buffer-file-coding-system' (of the current buffer)
514 Value returned by `keyboard-coding-system'
515 eol-type of `keyboard-coding-system'
516 Value returned by `terminal-coding-system'.
517 eol-type of `terminal-coding-system'
518 `process-coding-system' for read (of the current buffer, if any)
519 eol-type of `process-coding-system' for read (of the current buffer, if any)
520 `process-coding-system' for write (of the current buffer, if any)
521 eol-type of `process-coding-system' for write (of the current buffer, if any)
522 `default-buffer-file-coding-system'
523 eol-type of `default-buffer-file-coding-system'
524 `default-process-coding-system' for read
525 eol-type of `default-process-coding-system' for read
526 `default-process-coding-system' for write
527 eol-type of `default-process-coding-system'"
529 (let* ((proc (get-buffer-process (current-buffer)))
530 (process-coding-systems (if proc
(process-coding-system proc
))))
532 "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]"
533 (coding-system-mnemonic buffer-file-coding-system
)
534 (coding-system-eol-type-mnemonic buffer-file-coding-system
)
535 (coding-system-mnemonic (keyboard-coding-system))
536 (coding-system-eol-type-mnemonic (keyboard-coding-system))
537 (coding-system-mnemonic (terminal-coding-system))
538 (coding-system-eol-type-mnemonic (terminal-coding-system))
539 (coding-system-mnemonic (car process-coding-systems
))
540 (coding-system-eol-type-mnemonic (car process-coding-systems
))
541 (coding-system-mnemonic (cdr process-coding-systems
))
542 (coding-system-eol-type-mnemonic (cdr process-coding-systems
))
543 (coding-system-mnemonic default-buffer-file-coding-system
)
544 (coding-system-eol-type-mnemonic default-buffer-file-coding-system
)
545 (coding-system-mnemonic (car default-process-coding-system
))
546 (coding-system-eol-type-mnemonic (car default-process-coding-system
))
547 (coding-system-mnemonic (cdr default-process-coding-system
))
548 (coding-system-eol-type-mnemonic (cdr default-process-coding-system
))
551 (defun print-coding-system-briefly (coding-system &optional doc-string
)
552 "Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
553 If DOC-STRING is non-nil, print also the docstring of CODING-SYSTEM.
554 If DOC-STRING is `tightly', don't print an empty line before the
555 docstring, and print only the first line of the docstring."
556 (if (not coding-system
)
558 (princ (format "%c -- %s"
559 (coding-system-mnemonic coding-system
)
561 (let ((aliases (coding-system-aliases coding-system
)))
562 (cond ((eq coding-system
(car aliases
))
564 (princ (format " %S" (cons 'alias
: (cdr aliases
))))))
565 ((memq coding-system aliases
)
566 (princ (format " (alias of %s)" (car aliases
))))
568 (let ((eol-type (coding-system-eol-type coding-system
))
569 (base-eol-type (coding-system-eol-type (car aliases
))))
570 (if (and (integerp eol-type
)
571 (vectorp base-eol-type
)
572 (not (eq coding-system
(aref base-eol-type eol-type
))))
573 (princ (format " (alias of %s)"
574 (aref base-eol-type eol-type
))))))))
576 (or (eq doc-string
'tightly
)
579 (let ((doc (or (coding-system-doc-string coding-system
) "")))
580 (when (eq doc-string
'tightly
)
581 (if (string-match "\n" doc
)
582 (setq doc
(substring doc
0 (match-beginning 0))))
583 (setq doc
(concat " " doc
)))
584 (princ (format "%s\n" doc
))))))
587 (defun describe-current-coding-system ()
588 "Display coding systems currently used, in detail."
590 (with-output-to-temp-buffer "*Help*"
591 (let* ((proc (get-buffer-process (current-buffer)))
592 (process-coding-systems (if proc
(process-coding-system proc
))))
593 (princ "Coding system for saving this buffer:\n ")
594 (if (local-variable-p 'buffer-file-coding-system
)
595 (print-coding-system-briefly buffer-file-coding-system
)
596 (princ "Not set locally, use the default.\n"))
597 (princ "Default coding system (for new files):\n ")
598 (print-coding-system-briefly default-buffer-file-coding-system
)
599 (princ "Coding system for keyboard input:\n ")
600 (print-coding-system-briefly (keyboard-coding-system))
601 (princ "Coding system for terminal output:\n ")
602 (print-coding-system-briefly (terminal-coding-system))
603 (princ "Coding system for inter-client cut and paste:\n ")
604 (print-coding-system-briefly selection-coding-system
)
605 (when (get-buffer-process (current-buffer))
606 (princ "Coding systems for process I/O:\n")
607 (princ " encoding input to the process: ")
608 (print-coding-system-briefly (cdr process-coding-systems
))
609 (princ " decoding output from the process: ")
610 (print-coding-system-briefly (car process-coding-systems
)))
611 (princ "Defaults for subprocess I/O:\n")
612 (princ " decoding: ")
613 (print-coding-system-briefly (car default-process-coding-system
))
614 (princ " encoding: ")
615 (print-coding-system-briefly (cdr default-process-coding-system
)))
617 (with-current-buffer standard-output
620 Priority order for recognizing coding systems when reading files:\n")
622 (dolist (elt (coding-system-priority-list))
623 (princ (format " %d. %s " i elt
))
624 (let ((aliases (coding-system-aliases elt
)))
625 (if (eq elt
(car aliases
))
627 (princ (cons 'alias
: (cdr aliases
))))
628 (princ (list 'alias
'of
(car aliases
))))
632 (princ "\n Other coding systems cannot be distinguished automatically
633 from these, and therefore cannot be recognized automatically
634 with the present coding system priorities.\n\n")
636 ;; Fixme: should this be replaced or junked?
638 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else
))
639 coding-system codings
)
641 (setq coding-system
(symbol-value (car categories
)))
644 (if (and (not (eq x coding-system
))
645 (let ((flags (coding-system-get :flags
)))
646 (not (or (memq 'use-roman flags
)
647 (memq 'use-oldjis flags
)))))
648 (setq codings
(cons x codings
))))
649 (get (car categories
) 'coding-systems
))
651 (let ((max-col (window-width))
654 The following are decoded correctly but recognized as %s:\n "
658 (insert (format " %s" (car codings
)))
659 (when (> (current-column) max-col
)
662 (goto-char (point-max)))
663 (setq codings
(cdr codings
)))
665 (setq categories
(cdr categories
)))))
667 (princ "Particular coding systems specified for certain file names:\n")
669 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
670 (princ " ---------\t--------------\t\t----------------\n")
671 (let ((func (lambda (operation alist
)
675 (princ "\tnothing specified\n")
678 (prin1 (car (car alist
)))
679 (if (>= (current-column) 40)
682 (princ (cdr (car alist
)))
684 (setq alist
(cdr alist
)))))))
685 (funcall func
"File I/O" file-coding-system-alist
)
686 (funcall func
"Process I/O" process-coding-system-alist
)
687 (funcall func
"Network I/O" network-coding-system-alist
))
690 (defun print-coding-system (coding-system)
691 "Print detailed information on CODING-SYSTEM."
692 (let ((type (coding-system-type coding-system
))
693 (eol-type (coding-system-eol-type coding-system
))
694 (flags (coding-system-get coding-system
:flags
))
695 (aliases (coding-system-aliases coding-system
)))
696 (if (not (eq (car aliases
) coding-system
))
697 (princ (format "%s (alias of %s)\n" coding-system
(car aliases
)))
698 (princ coding-system
)
699 (setq aliases
(cdr aliases
))
702 (princ (car aliases
))
703 (setq aliases
(cdr aliases
)))
704 (princ (format ":%s:%c:%d:"
706 (coding-system-mnemonic coding-system
)
707 (if (integerp eol-type
) eol-type
3)))
708 (cond ((eq type
'iso2022
)
712 (setq charset
(aref flags idx
))
713 (cond ((null charset
)
721 (princ (car charset
))
722 (setq charset
(cdr charset
))
725 (princ (car charset
))
726 (setq charset
(cdr charset
)))
731 (princ (if (aref flags idx
) 1 0))
734 (princ (if (aref flags idx
) 1 0))))
737 (if (symbolp (car flags
))
738 (princ (format " %s" (car flags
)))
739 (setq i
0 len
(length (car flags
)))
741 (princ (format " %x" (aref (car flags
) i
)))
744 (if (symbolp (cdr flags
))
745 (princ (format "%s" (cdr flags
)))
746 (setq i
0 len
(length (cdr flags
)))
748 (princ (format " %x" (aref (cdr flags
) i
)))
752 (princ (coding-system-doc-string coding-system
))
756 (defun list-coding-systems (&optional arg
)
757 "Display a list of all coding systems.
758 This shows the mnemonic letter, name, and description of each coding system.
760 With prefix arg, the output format gets more cryptic,
761 but still contains full information about each coding system."
763 (with-output-to-temp-buffer "*Help*"
764 (list-coding-systems-1 arg
)))
766 (defun list-coding-systems-1 (arg)
769 ###############################################
770 # List of coding systems in the following format:
771 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
775 #########################
776 ## LIST OF CODING SYSTEMS
777 ## Each line corresponds to one coding system
778 ## Format of a line is:
779 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
780 ## :PRE-WRITE-CONVERSION:DOC-STRING,
782 ## NAME = coding system name
783 ## ALIAS = alias of the coding system
784 ## TYPE = nil (no conversion), t (undecided or automatic detection),
785 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
786 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
789 ## comma (`,') separated data of the following:
790 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
791 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
792 ## else if TYPE = 4 then
793 ## comma (`,') separated CCL programs for read and write
796 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
799 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only
)))
801 (print-coding-system-briefly coding-system
'tightly
)
802 (print-coding-system coding-system
))))
806 (defun list-coding-categories ()
807 "Display a list of all coding categories."
808 (with-output-to-temp-buffer "*Help*"
810 ############################
811 ## LIST OF CODING CATEGORIES (ordered by priority)
812 ## CATEGORY:CODING-SYSTEM
815 (let ((l coding-category-list
))
817 (princ (format "%s:%s\n" (car l
) (symbol-value (car l
))))
822 (defun describe-font-internal (font-info &optional verbose
)
823 "Print information about a font in FONT-INFO."
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 fonts which partially match FONTNAME."
834 (interactive "sFontname (default current choice for ASCII chars): ")
835 (or (and window-system
(fboundp 'fontset-list
))
836 (error "No fontsets being used"))
837 (when (or (not fontname
) (= (length fontname
) 0))
838 (setq fontname
(cdr (assq 'font
(frame-parameters))))
839 (if (query-fontset fontname
)
841 (nth 1 (assq 'ascii
(aref (fontset-info fontname
) 2))))))
842 (let ((font-info (font-info fontname
)))
844 (message "No matching font")
845 (with-output-to-temp-buffer "*Help*"
846 (describe-font-internal font-info
'verbose
)))))
848 (defun print-fontset-element (val)
849 ;; VAL has this format:
850 ;; ((REQUESTED-FONT-NAME OPENED-FONT-NAME ...) ...)
851 ;; CHAR RANGE is already inserted. Get character codes from
854 (let ((from (following-char))
855 (to (if (looking-at "[^.]*[.]* ")
856 (char-after (match-end 0)))))
857 (if (re-search-forward "[ \t]*$" nil t
)
858 (delete-region (match-beginning 0) (match-end 0)))
860 ;; For non-ASCII characters, insert also CODE RANGE.
861 (if (or (>= from
128) (and to
(>= to
128)))
863 (insert (format " (#x%02X .. #x%02X)" from to
))
864 (insert (format " (#x%02X)" from
))))
866 ;; Insert a requested font name.
868 (let ((requested (car elt
)))
869 (if (stringp requested
)
870 (insert "\n " requested
)
871 (let ((family (aref requested
0))
872 (registry (aref requested
5)))
875 (or (string-match "-" family
)
876 (setq family
(concat "*-" family
))))
877 (or (string-match "-" registry
)
878 (= (aref registry
(1- (length registry
))) ?
*)
879 (setq registry
(concat registry
"*")))
880 (insert "\n -" family
881 ?-
(or (aref requested
1) ?
*) ; weight
882 ?-
(or (aref requested
2) ?
*) ; slant
883 ?-
(or (aref requested
3) ?
*) ; width
884 ?-
(or (aref requested
4) ?
*) ; adstyle
885 "-*-*-*-*-*-*-" registry
))))
887 ;; Insert opened font names (if any).
888 (if (and (boundp 'print-opened
) (symbol-value 'print-opened
))
889 (dolist (opened (cdr elt
))
890 (insert "\n\t[" opened
"]"))))))
892 (defun print-fontset (fontset &optional print-opened
)
893 "Print information about FONTSET.
894 If FONTSET is nil, print information about the default fontset.
895 If optional arg PRINT-OPENED is non-nil, also print names of all opened
896 fonts for FONTSET. This function actually inserts the information in
899 (setq fontset
(query-fontset "fontset-default")))
901 (insert "Fontset: " fontset
"\n")
902 (insert (propertize "CHAR RANGE" 'face
'underline
)
903 " (" (propertize "CODE RANGE" 'face
'underline
) ")\n")
904 (insert " " (propertize "FONT NAME" 'face
'underline
)
905 " (" (propertize "REQUESTED" 'face
'underline
)
906 " and [" (propertize "OPENED" 'face
'underline
) "])")
907 (let ((info (fontset-info fontset
)))
908 (describe-vector info
'print-fontset-element
)
909 (insert "\n ---<fallback to the default fontset>---")
910 (describe-vector (char-table-extra-slot info
0) 'print-fontset-element
)))
913 (defun describe-fontset (fontset)
914 "Display information about FONTSET.
915 This shows which font is used for which character(s)."
917 (if (not (and window-system
(fboundp 'fontset-list
)))
918 (error "No fontsets being used")
919 (let ((fontset-list (nconc
921 (mapcar 'cdr fontset-alias-alist
)))
922 (completion-ignore-case t
))
923 (list (completing-read
924 "Fontset (default used by the current frame): "
925 fontset-list nil t
)))))
926 (if (= (length fontset
) 0)
927 (setq fontset
(frame-parameter nil
'font
)))
928 (setq fontset
(query-fontset fontset
))
929 (help-setup-xref (list #'describe-fontset fontset
) (interactive-p))
930 (with-output-to-temp-buffer (help-buffer)
931 (with-current-buffer standard-output
932 (print-fontset fontset t
))))
935 (defun list-fontsets (arg)
936 "Display a list of all fontsets.
937 This shows the name, size, and style of each fontset.
938 With prefix arg, also list the fonts contained in each fontset;
939 see the function `describe-fontset' for the format of the list."
941 (if (not (and window-system
(fboundp 'fontset-list
)))
942 (error "No fontsets being used")
943 (help-setup-xref (list #'list-fontsets arg
) (interactive-p))
944 (with-output-to-temp-buffer (help-buffer)
945 (with-current-buffer standard-output
946 ;; This code is duplicated near the end of mule-diag.
950 (string< (fontset-plain-name x
)
951 (fontset-plain-name y
))))))
954 (print-fontset (car fontsets
) nil
)
955 (insert "Fontset: " (car fontsets
) "\n"))
956 (setq fontsets
(cdr fontsets
))))))))
959 (defun list-input-methods ()
960 "Display information about all input methods."
962 (help-setup-xref '(list-input-methods) (interactive-p))
963 (with-output-to-temp-buffer (help-buffer)
964 (list-input-methods-1)
965 (with-current-buffer standard-output
967 (goto-char (point-min))
968 (while (re-search-forward
969 "^ \\([^ ]+\\) (`.*' in mode line)$" nil t
)
970 (help-xref-button 1 'help-input-method
(match-string 1)))))))
972 (defun list-input-methods-1 ()
973 (if (not input-method-alist
)
976 No input method is available, perhaps because you have not
977 installed LEIM (Libraries of Emacs Input Methods)."))
978 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
979 (princ " SHORT-DESCRIPTION\n------------------------------\n")
980 (setq input-method-alist
981 (sort input-method-alist
982 (lambda (x y
) (string< (nth 1 x
) (nth 1 y
)))))
983 (let ((l input-method-alist
)
986 (setq elt
(car l
) l
(cdr l
))
987 (when (not (equal language
(nth 1 elt
)))
988 (setq language
(nth 1 elt
))
991 (princ (format " %s (`%s' in mode line)\n %s\n"
993 (let ((title (nth 3 elt
)))
994 (if (and (consp title
) (stringp (car title
)))
997 (let ((description (nth 4 elt
)))
998 (string-match ".*" description
)
999 (match-string 0 description
))))))))
1003 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1004 (defun insert-section (section-number title
)
1005 (insert "########################################\n"
1006 "# Section " (format "%d" section-number
) ". " title
"\n"
1007 "########################################\n\n"))
1011 "Display diagnosis of the multilingual environment (Mule).
1013 This shows various information related to the current multilingual
1014 environment, including lists of input methods, coding systems,
1015 character sets, and fontsets (if Emacs is running under a window
1016 system which uses fontsets)."
1018 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1019 (with-current-buffer standard-output
1020 (insert "###############################################\n"
1021 "### Current Status of Multilingual Features ###\n"
1022 "###############################################\n\n"
1023 "CONTENTS: Section 1. General Information\n"
1024 " Section 2. Display\n"
1025 " Section 3. Input methods\n"
1026 " Section 4. Coding systems\n"
1027 " Section 5. Character sets\n")
1028 (if (and window-system
(fboundp 'fontset-list
))
1029 (insert " Section 6. Fontsets\n"))
1032 (insert-section 1 "General Information")
1033 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1034 (insert "Configuration options:\n " system-configuration-options
"\n\n")
1035 (insert "Multibyte characters awareness:\n"
1036 (format " default: %S\n" default-enable-multibyte-characters
)
1037 (format " current-buffer: %S\n\n" enable-multibyte-characters
))
1038 (insert "Current language environment: " current-language-environment
1041 (insert-section 2 "Display")
1043 (insert "Window-system: "
1044 (symbol-name window-system
)
1045 (format "%s" window-system-version
))
1046 (insert "Terminal: " (getenv "TERM")))
1049 (if (eq window-system
'x
)
1050 (let ((font (cdr (assq 'font
(frame-parameters)))))
1051 (insert "The selected frame is using the "
1052 (if (query-fontset font
) "fontset" "font")
1054 (insert "Coding system of the terminal: "
1055 (symbol-name (terminal-coding-system))))
1058 (insert-section 3 "Input methods")
1059 (list-input-methods-1)
1061 (if default-input-method
1062 (insert (format "Default input method: %s\n" default-input-method
))
1063 (insert "No default input method is specified\n"))
1065 (insert-section 4 "Coding systems")
1066 (list-coding-systems-1 t
)
1069 (insert-section 5 "Character sets")
1070 (list-character-sets-2)
1073 (when (and window-system
(fboundp 'fontset-list
))
1074 ;; This code duplicates most of list-fontsets.
1075 (insert-section 6 "Fontsets")
1076 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1077 (insert "------------\t\t\t\t\t\t ----- -----\n")
1078 (let ((fontsets (fontset-list)))
1080 (print-fontset (car fontsets
) t
)
1081 (setq fontsets
(cdr fontsets
)))))
1082 (print-help-return-message))))
1085 (defcustom unicodedata-file nil
1086 "Location of UnicodeData file.
1087 This is the UnicodeData.txt file from the Unicode consortium, used for
1088 diagnostics. If it is non-nil `describe-char-after' will print data
1091 :type
'(choice (const :tag
"None" nil
)
1094 ;; We could convert the unidata file into a Lispy form once-for-all
1095 ;; and distribute it for loading on demand. It might be made more
1096 ;; space-efficient by splitting strings word-wise and replacing them
1097 ;; with lists of symbols interned in a private obarray, e.g.
1098 ;; "LATIN SMALL LETTER A" => '(LATIN SMALL LETTER A).
1101 (defun unicode-data (char)
1102 "Return a list of Unicode data for unicode CHAR.
1103 Each element is a list of a property description and the property value.
1104 The list is null if CHAR isn't found in `unicodedata-file'."
1105 (when unicodedata-file
1106 (unless (file-exists-p unicodedata-file
)
1107 (error "`unicodedata-file' %s not found" unicodedata-file
))
1109 (set-buffer (find-file-noselect unicodedata-file t t
))
1110 (goto-char (point-min))
1111 (let ((hex (format "%04X" char
))
1113 (if (re-search-forward (concat "^" hex
) nil t
)
1115 ;; It's not listed explicitly. Look for ranges, e.g. CJK
1116 ;; ideographs, and check whether it's in one of them.
1117 (while (and (re-search-forward "^\\([^;]+\\);[^;]+First>;" nil t
)
1118 (>= char
(setq first
1119 (string-to-number (match-string 1) 16)))
1122 (looking-at "^\\([^;]+\\);[^;]+Last>;")
1125 (string-to-number (match-string 1) 16))))))
1126 (if (and (>= char first
)
1130 (let ((fields (mapcar (lambda (elt)
1131 (if (> (length elt
) 0)
1135 (line-beginning-position)
1136 (line-end-position))
1138 ;; The length depends on whether the last field was empty.
1139 (unless (or (= 13 (length fields
))
1140 (= 14 (length fields
)))
1141 (error "Invalid contents in %s" unicodedata-file
))
1142 ;; The field names and values lists are slightly
1143 ;; modified from Mule-UCS unidata.el.
1145 (list "Name" (let ((name (nth 0 fields
)))
1146 ;; Check for <..., First>, <..., Last>
1147 (if (string-match "\\`\\(<[^,]+\\)," name
)
1148 (concat (match-string 1 name
) ">")
1153 '(("Lu" .
"uppercase letter")
1154 ("Ll" .
"lowercase letter")
1155 ("Lt" .
"titlecase letter")
1156 ("Mn" .
"non-spacing mark")
1157 ("Mc" .
"spacing-combining mark")
1158 ("Me" .
"enclosing mark")
1159 ("Nd" .
"decimal digit")
1160 ("Nl" .
"letter number")
1161 ("No" .
"other number")
1162 ("Zs" .
"space separator")
1163 ("Zl" .
"line separator")
1164 ("Zp" .
"paragraph separator")
1165 ("Cc" .
"other control")
1166 ("Cf" .
"other format")
1167 ("Cs" .
"surrogate")
1168 ("Co" .
"private use")
1169 ("Cn" .
"not assigned")
1170 ("Lm" .
"modifier letter")
1171 ("Lo" .
"other letter")
1172 ("Pc" .
"connector punctuation")
1173 ("Pd" .
"dash punctuation")
1174 ("Ps" .
"open punctuation")
1175 ("Pe" .
"close punctuation")
1176 ("Pi" .
"initial-quotation punctuation")
1177 ("Pf" .
"final-quotation punctuation")
1178 ("Po" .
"other punctuation")
1179 ("Sm" .
"math symbol")
1180 ("Sc" .
"currency symbol")
1181 ("Sk" .
"modifier symbol")
1182 ("So" .
"other symbol")))))
1183 (list "Combining class"
1185 (string-to-number (nth 2 fields
))
1187 (1 .
"Overlays and interior")
1189 (8 .
"Hiragana/Katakana voicing marks")
1191 (10 .
"Start of fixed position classes")
1192 (199 .
"End of fixed position classes")
1193 (200 .
"Below left attached")
1194 (202 .
"Below attached")
1195 (204 .
"Below right attached")
1196 (208 .
"Left attached (reordrant around \
1197 single base character)")
1198 (210 .
"Right attached")
1199 (212 .
"Above left attached")
1200 (214 .
"Above attached")
1201 (216 .
"Above right attached")
1202 (218 .
"Below left")
1204 (222 .
"Below right")
1205 (224 .
"Left (reordrant around single base \
1208 (228 .
"Above left")
1210 (232 .
"Above right")
1211 (233 .
"Double below")
1212 (234 .
"Double above")
1213 (240 .
"Below (iota subscript)")))))
1214 (list "Bidi category"
1217 '(("L" .
"Left-to-Right")
1218 ("LRE" .
"Left-to-Right Embedding")
1219 ("LRO" .
"Left-to-Right Override")
1220 ("R" .
"Right-to-Left")
1221 ("AL" .
"Right-to-Left Arabic")
1222 ("RLE" .
"Right-to-Left Embedding")
1223 ("RLO" .
"Right-to-Left Override")
1224 ("PDF" .
"Pop Directional Format")
1225 ("EN" .
"European Number")
1226 ("ES" .
"European Number Separator")
1227 ("ET" .
"European Number Terminator")
1228 ("AN" .
"Arabic Number")
1229 ("CS" .
"Common Number Separator")
1230 ("NSM" .
"Non-Spacing Mark")
1231 ("BN" .
"Boundary Neutral")
1232 ("B" .
"Paragraph Separator")
1233 ("S" .
"Segment Separator")
1234 ("WS" .
"Whitespace")
1235 ("ON" .
"Other Neutrals")))))
1236 (list "Decomposition"
1238 (let* ((parts (split-string (nth 4 fields
)))
1240 (if (string-match "\\`<\\(.+\\)>\\'" info
)
1241 (setq info
(match-string 1 info
))
1243 (if info
(setq parts
(cdr parts
)))
1244 (setq parts
(mapconcat
1246 (string (string-to-number arg
16)))
1248 (concat info parts
))))
1249 (list "Decimal digit value"
1253 (list "Numeric value"
1256 (if (equal "Y" (nth 8 fields
))
1258 (list "Old name" (nth 9 fields
))
1259 (list "ISO 10646 comment" (nth 10 fields
))
1260 (list "Uppercase" (and (nth 11 fields
)
1261 (string (string-to-number
1262 (nth 11 fields
) 16))))
1263 (list "Lowercase" (and (nth 12 fields
)
1264 (string (string-to-number
1265 (nth 12 fields
) 16))))
1266 (list "Titlecase" (and (nth 13 fields
)
1267 (string (string-to-number
1268 (nth 13 fields
) 16)))))))))))
1270 (provide 'mule-diag
)
1272 ;;; arch-tag: cd3b607c-2893-45a0-a4fa-a6535754dbee
1273 ;;; mule-diag.el ends here