(diff-find-source-location): Don't call
[emacs.git] / lisp / international / mule-diag.el
blobcf979c60bcb0563afb0bd3b5c5237a854d90c120
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
9 ;; Copyright (C) 2003
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/>.
30 ;;; Commentary:
32 ;;; Code:
34 ;; Make sure the help-xref button type is defined.
35 (require 'help-fns)
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 " "))
42 (princ "\n"))
44 ;;; CHARSET
46 (define-button-type 'sort-listed-character-sets
47 'help-echo (purecopy "mouse-2, RET: sort on this column")
48 'face 'bold
49 'action #'(lambda (button)
50 (sort-listed-character-sets (button-get button 'sort-key))))
52 (define-button-type 'list-charset-chars
53 :supertype 'help-xref
54 'help-function #'list-charset-chars
55 'help-echo "mouse-2, RET: show table of characters for this character set")
57 ;;;###autoload
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."
68 (interactive "P")
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
72 (if arg
73 (list-character-sets-2)
74 ;; Insert header.
75 (insert "Supplementary character sets are shown below.\n")
76 (insert
77 (substitute-command-keys
78 (concat "Use "
79 (if (display-mouse-p) "\\[help-follow-mouse] or ")
80 "\\[help-follow]:\n")))
81 (insert " on a column title to sort by that title,")
82 (indent-to 48)
83 (insert "+----DIMENSION\n")
84 (insert " on a charset name to list characters.")
85 (indent-to 48)
86 (insert "| +--CHARS\n")
87 (let ((columns '(("CHARSET-NAME" . name) "\t\t\t\t\t"
88 ("D CH FINAL-CHAR" . iso-spec)))
89 pos)
90 (while columns
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)))
98 (insert "\n"))
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)
105 (if sort-key
106 (save-excursion
107 (let ((buffer-read-only nil))
108 (goto-char (point-min))
109 (search-forward "\n-")
110 (forward-line 1)
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')."
117 (or sort-key
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.
132 (setq sort-func
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
138 (function
139 (lambda (x y)
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))
153 (if (eq elt t)
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))
159 (insert "\t")
160 (indent-to 48)
161 (insert (format "%d %3d "
162 (nth 1 elt) (nth 2 elt)) ; DIMENSION and CHARS
163 (if (< (nth 3 elt) 0)
164 "none"
165 (nth 3 elt)))) ; FINAL-CHAR
166 (insert "\n"))))
169 ;; List all character sets in a form that a program can easily parse.
171 (defun list-character-sets-2 ()
172 (insert "#########################
173 ## LIST OF CHARSETS
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,
178 ## DIMENSION (1-4)
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"
186 charset
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
196 "Obsolete.")
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)
210 ;;;###autoload
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
223 default-value)))
224 (if (> (length charset) 0)
225 (intern charset))))
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)
233 (let (i ch)
234 (insert-char ?- (+ 7 (* 4 16)))
235 (insert "\n ")
236 (setq i 0)
237 (while (< i 16)
238 (insert (format "%4X" i))
239 (setq i (1+ i)))
240 (setq i (* (/ min 16) 16))
241 (while (<= i max)
242 (if (= (% i 16) 0)
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))
253 (if (> ch #x10FFFF)
254 (setq ch 32))))
255 (insert "\t" ch)
256 (setq i (1+ i))))
257 (insert "\n"))
259 ;;;###autoload
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
269 ;; instance:
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)))
273 (if slot
274 (setcdr slot
275 (cons (format " (%s)" charset)
276 (cdr slot)))))
277 (setq tab-width 4)
278 (set-buffer-multibyte t)
279 (let ((dim (charset-dimension charset))
280 (chars (charset-chars charset))
281 ;; (plane (charset-iso-graphic-plane charset))
282 (plane 1)
283 (range (plist-get (charset-plist charset) :code-space))
284 min max min2 max2)
285 (if (> dim 2)
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)
290 max (aref range 1))
291 (if (= dim 1)
292 (list-block-of-chars charset 0 min max)
293 (setq min2 (aref range 2)
294 max2 (aref range 3))
295 (let ((i min2))
296 (while (<= i max2)
297 (list-block-of-chars charset i min max)
298 (setq i (1+ i)))))
299 (put-text-property (point-min) (point-max) 'charset charset)
300 (widen)))))
303 ;;;###autoload
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))
319 (unless (= i 0)
320 (insert ?x))
321 (insert (format "%d" (charset-chars charset (1+ i)))))
322 (insert ?\n)
323 (let ((char (charset-iso-final-char charset)))
324 (when (> char 0)
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))))
329 (let (aliases)
330 (dolist (c charset-list)
331 (if (and (not (eq c charset))
332 (eq charset (get-charset-property c :name)))
333 (push c aliases)))
334 (if aliases
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)
340 (:invalid-code
342 ,(lambda (c)
343 (format "Invalid character: %c (code %d)" c c)))
344 (:emacs-mule-id "Id in emacs-mule coding system: "
345 number-to-string)
346 (:parents "Parents: "
347 (lambda (parents)
348 (mapconcat ,(lambda (elt)
349 (format "%s" elt))
350 parents
351 ", ")))
352 (:code-space "Code space: " ,(lambda (c)
353 (format "%s" c)))
354 (:code-offset "Code offset: " number-to-string)
355 (:iso-revision-number "ISO revision number: "
356 number-to-string)
357 (:supplementary-p
358 "Used only as a parent of some other charset." nil)))
359 (let ((val (get-charset-property charset (car elt))))
360 (when val
361 (if (cadr elt) (insert (cadr elt)))
362 (if (nth 2 elt)
363 (insert (funcall (nth 2 elt) val)))
364 (insert ?\n)))))))
366 ;;; CODING-SYSTEM
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)
375 (let (charset)
376 (dotimes (graphic-register 4)
377 (setq charset (aref designations graphic-register))
378 (princ (format
379 " G%d -- %s\n"
380 graphic-register
381 (cond ((null charset)
382 "never used")
383 ((eq charset t)
384 "no initial designation, and used by any charsets")
385 ((symbolp charset)
386 (format "%s:%s"
387 charset (charset-description charset)))
388 ((listp charset)
389 (if (charsetp (car charset))
390 (format "%s:%s, and also used by the following:"
391 (car charset)
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))
398 (while charset
399 (cond ((eq (car charset) t)
400 (princ "\tany other charsets\n"))
401 ((charsetp (car charset))
402 (princ (format "\t%s:%s\n"
403 (car charset)
404 (charset-description (car charset)))))
406 "invalid designation information"))
407 (setq charset (cdr charset)))))))
409 ;;;###autoload
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)
416 (interactive-p))
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))
420 ;; Fixme: use this
421 (extra-spec (coding-system-plist coding-system)))
422 (princ "Type: ")
423 (princ type)
424 (cond ((eq type 'undecided)
425 (princ " (do automatic conversion)"))
426 ((eq type 'utf-8)
427 (princ " (UTF-8: Emacs internal multibyte form)"))
428 ((eq type 'utf-16)
429 ;; (princ " (UTF-16)")
431 ((eq type 'shift-jis)
432 (princ " (Shift-JIS, MS-KANJI)"))
433 ((eq type 'iso-2022)
434 (princ " (variant of ISO-2022)\n")
435 (princ "Initial designations:\n")
436 (print-designation (coding-system-get coding-system
437 :designation))
439 (when (coding-system-get coding-system :flags)
440 (princ "Other specifications: \n ")
441 (apply #'print-list
442 (coding-system-get coding-system :flags))))
443 ((eq type 'charset)
444 (princ " (charset)"))
445 ((eq type 'ccl)
446 (princ " (do conversion by CCL program)"))
447 ((eq type 'raw-text)
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")
456 (princ eol-type)
457 (princ "\n"))
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)))
463 (when postread
464 (princ "After decoding text normally,")
465 (princ " perform post-conversion using the function: ")
466 (princ "\n ")
467 (princ postread)
468 (princ "\n")))
469 (let ((prewrite (coding-system-get coding-system :pre-write-conversion)))
470 (when prewrite
471 (princ "Before encoding text normally,")
472 (princ " perform pre-conversion using the function: ")
473 (princ "\n ")
474 (princ prewrite)
475 (princ "\n")))
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))
479 charsets)
480 (cond
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\
485 ."""))
487 (insert "This coding system encodes the following charsets:\n ")
488 (while charsets
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)))))))))))
495 ;;;###autoload
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
501 in place of `..':
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'"
518 (interactive)
519 (let* ((proc (get-buffer-process (current-buffer)))
520 (process-coding-systems (if proc (process-coding-system proc))))
521 (message
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)
547 (princ "nil\n")
548 (princ (format "%c -- %s"
549 (coding-system-mnemonic coding-system)
550 coding-system))
551 (let ((aliases (coding-system-aliases coding-system)))
552 (cond ((eq coding-system (car aliases))
553 (if (cdr 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))))))))
565 (princ "\n")
566 (or (eq doc-string 'tightly)
567 (princ "\n"))
568 (if doc-string
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))))))
576 ;;;###autoload
577 (defun describe-current-coding-system ()
578 "Display coding systems currently used, in detail."
579 (interactive)
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
610 (princ "
611 Priority order for recognizing coding systems when reading files:\n")
612 (let ((i 1))
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))
617 (if (cdr aliases)
618 (princ (cons 'alias: (cdr aliases))))
619 (princ (list 'alias 'of (car aliases))))
620 (terpri)
621 (setq i (1+ i)))))
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?
628 (if nil
629 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else))
630 coding-system codings)
631 (while categories
632 (setq coding-system (symbol-value (car categories)))
633 (mapc
634 (lambda (x)
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))
641 (if codings
642 (let ((max-col (window-width))
643 pos)
644 (princ (format "\
645 The following are decoded correctly but recognized as %s:\n "
646 coding-system))
647 (while codings
648 (setq pos (point))
649 (insert (format " %s" (car codings)))
650 (when (> (current-column) max-col)
651 (goto-char pos)
652 (insert "\n ")
653 (goto-char (point-max)))
654 (setq codings (cdr codings)))
655 (insert "\n\n")))
656 (setq categories (cdr categories)))))
658 (princ "Particular coding systems specified for certain file names:\n")
659 (terpri)
660 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
661 (princ " ---------\t--------------\t\t----------------\n")
662 (let ((func (lambda (operation alist)
663 (princ " ")
664 (princ operation)
665 (if (not alist)
666 (princ "\tnothing specified\n")
667 (while alist
668 (indent-to 16)
669 (prin1 (car (car alist)))
670 (if (>= (current-column) 40)
671 (newline))
672 (indent-to 40)
673 (princ (cdr (car alist)))
674 (princ "\n")
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))
679 (help-mode))))
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))
691 (princ ",")
692 (princ alias))
693 (princ (format ":%s:%c:%d:"
694 type
695 (coding-system-mnemonic coding-system)
696 (if (integerp eol-type) eol-type 3)))
697 (cond ((eq type 'iso2022)
698 (let ((idx 0)
699 charset)
700 (while (< idx 4)
701 (setq charset (aref flags idx))
702 (cond ((null charset)
703 (princ -1))
704 ((eq charset t)
705 (princ -2))
706 ((charsetp charset)
707 (princ charset))
708 ((listp charset)
709 (princ "(")
710 (princ (car charset))
711 (setq charset (cdr charset))
712 (while charset
713 (princ ",")
714 (princ (car charset))
715 (setq charset (cdr charset)))
716 (princ ")")))
717 (princ ",")
718 (setq idx (1+ idx)))
719 (while (< idx 12)
720 (princ (if (aref flags idx) 1 0))
721 (princ ",")
722 (setq idx (1+ idx)))
723 (princ (if (aref flags idx) 1 0))))
724 ((eq type 'ccl)
725 (let (i len)
726 (if (symbolp (car flags))
727 (princ (format " %s" (car flags)))
728 (setq i 0 len (length (car flags)))
729 (while (< i len)
730 (princ (format " %x" (aref (car flags) i)))
731 (setq i (1+ i))))
732 (princ ",")
733 (if (symbolp (cdr flags))
734 (princ (format "%s" (cdr flags)))
735 (setq i 0 len (length (cdr flags)))
736 (while (< i len)
737 (princ (format " %x" (aref (cdr flags) i)))
738 (setq i (1+ i))))))
739 (t (princ 0)))
740 (princ ":")
741 (princ (coding-system-doc-string coding-system))
742 (princ "\n"))))
744 ;;;###autoload
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."
751 (interactive "P")
752 (with-output-to-temp-buffer "*Help*"
753 (list-coding-systems-1 arg)))
755 (defun list-coding-systems-1 (arg)
756 (if (null arg)
757 (princ "\
758 ###############################################
759 # List of coding systems in the following format:
760 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
761 # DOC-STRING
763 (princ "\
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,
770 ## where
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)
776 ## FLAGS =
777 ## if TYPE = 2 then
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
783 ## else
784 ## 0
785 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
788 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only)))
789 (if (null arg)
790 (print-coding-system-briefly coding-system 'tightly)
791 (print-coding-system coding-system))))
793 ;; Fixme: delete?
794 ;;;###autoload
795 (defun list-coding-categories ()
796 "Display a list of all coding categories."
797 (with-output-to-temp-buffer "*Help*"
798 (princ "\
799 ############################
800 ## LIST OF CODING CATEGORIES (ordered by priority)
801 ## CATEGORY:CODING-SYSTEM
804 (let ((l coding-category-list))
805 (while l
806 (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
807 (setq l (cdr l))))))
809 ;;; FONT
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))))
823 ;;;###autoload
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"))
830 (let (font-info)
831 (if (or (not fontname) (= (length fontname) 0))
832 (setq fontname (face-attribute 'default :font)))
833 (setq font-info (font-info fontname))
834 (if (null font-info)
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
839 ;; this problem.
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
849 ;; the current line.
850 (beginning-of-line)
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)))
859 (if to
860 (insert (format " (#x%02X .. #x%02X)" from to))
861 (insert (format " (#x%02X)" from))))
863 ;; Insert a requested font name.
864 (dolist (elt val)
865 (if (not elt)
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)))
884 (if (not family)
885 (setq family "*-*")
886 (if (symbolp family)
887 (setq family (symbol-name family)))
888 (or (string-match "-" family)
889 (setq family (concat "*-" family))))
890 (if (not registry)
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
912 default fontset.
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
915 the current buffer."
916 (if (eq fontset t)
917 (setq fontset (query-fontset "fontset-default"))
918 (if (eq fontset nil)
919 (setq fontset (face-attribute 'default :fontset))))
920 (beginning-of-line)
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))))
940 (when default-info
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)))
956 (widen))
958 (defvar fontset-alias-alist)
959 (declare-function fontset-list "fontset.c" ())
961 ;;;###autoload
962 (defun describe-fontset (fontset)
963 "Display information about FONTSET.
964 This shows which font is used for which character(s)."
965 (interactive
966 (if (not (and window-system (fboundp 'fontset-list)))
967 (error "No fontsets being used")
968 (let ((fontset-list (nconc
969 (fontset-list)
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))
985 ;;;###autoload
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."
991 (interactive "P")
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.
998 (let ((fontsets
999 (sort (fontset-list)
1000 (lambda (x y)
1001 (string< (fontset-plain-name x)
1002 (fontset-plain-name y))))))
1003 (while fontsets
1004 (if arg
1005 (print-fontset (car fontsets) nil)
1006 (insert "Fontset: " (car fontsets) "\n"))
1007 (setq fontsets (cdr fontsets))))))))
1009 ;;;###autoload
1010 (defun list-input-methods ()
1011 "Display information about all input methods."
1012 (interactive)
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
1017 (save-excursion
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)
1025 (princ "
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)))))
1034 (let (language)
1035 (dolist (elt input-method-alist)
1036 (when (not (equal language (nth 1 elt)))
1037 (setq language (nth 1 elt))
1038 (princ language)
1039 (terpri))
1040 (princ (format " %s (`%s' in mode line)\n %s\n"
1041 (car elt)
1042 (let ((title (nth 3 elt)))
1043 (if (and (consp title) (stringp (car title)))
1044 (car title)
1045 title))
1046 (nth 4 elt)))))))
1048 ;;; DIAGNOSIS
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"))
1056 ;;;###autoload
1057 (defun mule-diag ()
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)."
1064 (interactive)
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"))
1077 (insert "\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
1086 "\n\n")
1088 (insert-section 2 "Display")
1089 (if window-system
1090 (insert (format "Window-system: %s, version %s"
1091 window-system window-system-version))
1092 (insert "Terminal: " (getenv "TERM")))
1093 (insert "\n\n")
1095 (if window-system
1096 (let ((font (cdr (assq 'font (frame-parameters)))))
1097 (insert "The font and fontset of the selected frame are:\n"
1098 " font: " font "\n"
1099 " fontset: " (face-attribute 'default :fontset) "\n"))
1100 (insert "Coding system of the terminal: "
1101 (symbol-name (terminal-coding-system))))
1102 (insert "\n\n")
1104 (insert-section 3 "Input methods")
1105 (list-input-methods-1)
1106 (insert "\n")
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)
1113 (insert "\n")
1115 (insert-section 5 "Character sets")
1116 (list-character-sets-2)
1117 (insert "\n")
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))))
1128 ;;;###autoload
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."
1133 (interactive "P")
1134 (setq limit (if limit (prefix-numeric-value limit) 20))
1135 (if (eq font-log t)
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))
1143 (let ((i 0))
1144 (catch 'tag
1145 (mapc #'(lambda (x)
1146 (setq i (1+ i))
1147 (when (= i limit)
1148 (insert " ...\n")
1149 (throw 'tag nil))
1150 (insert (format " %s\n" x)))
1151 elt)))
1152 (insert (format " %s\n" elt)))))))
1155 (provide 'mule-diag)
1157 ;; arch-tag: cd3b607c-2893-45a0-a4fa-a6535754dbee
1158 ;;; mule-diag.el ends here