]> code.delx.au - gnu-emacs/blob - lisp/international/mule-diag.el
731d6889ef5a3a9d69d93a5380ad99e066cbfaaf
[gnu-emacs] / lisp / international / mule-diag.el
1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
2
3 ;; Copyright (C) 1997-1998, 2000-2016 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
8 ;; Copyright (C) 2003
9 ;; National Institute of Advanced Industrial Science and Technology (AIST)
10 ;; Registration Number H13PRO009
11
12 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
13
14 ;; This file is part of GNU Emacs.
15
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
20
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.
25
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28
29 ;;; Commentary:
30
31 ;;; Code:
32
33 ;; Make sure the help-xref button type is defined.
34 (require 'help-mode)
35
36 ;;; General utility function
37
38 (defun print-list (&rest args)
39 "Print all arguments with single space separator in one line."
40 (princ (mapconcat (lambda (arg) (prin1-to-string arg t)) args " "))
41 (princ "\n"))
42
43 ;;; CHARSET
44
45 (define-button-type 'sort-listed-character-sets
46 'help-echo (purecopy "mouse-2, RET: sort on this column")
47 'face 'bold
48 'action #'(lambda (button)
49 (sort-listed-character-sets (button-get button 'sort-key))))
50
51 (define-button-type 'list-charset-chars
52 :supertype 'help-xref
53 'help-function #'list-charset-chars
54 'help-echo "mouse-2, RET: show table of characters for this character set")
55
56 ;;;###autoload
57 (defun list-character-sets (arg)
58 "Display a list of all character sets.
59
60 The D column contains the dimension of this character set. The CH
61 column contains the number of characters in a block of this character
62 set. The FINAL-BYTE column contains an ISO-2022 <final-byte> to use
63 in the designation escape sequence for this character set in
64 ISO-2022-based coding systems.
65
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)
70 (called-interactively-p 'interactive))
71 (with-output-to-temp-buffer "*Character Set List*"
72 (with-current-buffer standard-output
73 (if arg
74 (list-character-sets-2)
75 ;; Insert header.
76 (insert "Supplementary character sets are shown below.\n")
77 (insert
78 (substitute-command-keys
79 (concat "Use "
80 (if (display-mouse-p) "\\[help-follow-mouse] or ")
81 "\\[help-follow]:\n")))
82 (insert " on a column title to sort by that title,")
83 (indent-to 48)
84 (insert "+----DIMENSION\n")
85 (insert " on a charset name to list characters.")
86 (indent-to 48)
87 (insert "| +--CHARS\n")
88 (let ((columns '(("CHARSET-NAME" . name) "\t\t\t\t\t"
89 ("D CH FINAL-BYTE" . iso-spec)))
90 pos)
91 (while columns
92 (if (stringp (car columns))
93 (insert (car columns))
94 (insert-text-button (car (car columns))
95 :type 'sort-listed-character-sets
96 'sort-key (cdr (car columns)))
97 (goto-char (point-max)))
98 (setq columns (cdr columns)))
99 (insert "\n"))
100 (insert "------------\t\t\t\t\t- --- ----------\n")
101
102 ;; Insert body sorted by charset IDs.
103 (list-character-sets-1 'name)))))
104
105 (defun sort-listed-character-sets (sort-key)
106 (if sort-key
107 (save-excursion
108 (let ((buffer-read-only nil))
109 (goto-char (point-min))
110 (search-forward "\n-")
111 (forward-line 1)
112 (delete-region (point) (point-max))
113 (list-character-sets-1 sort-key)))))
114
115 (defun list-character-sets-1 (sort-key)
116 "Insert a list of character sets sorted by SORT-KEY.
117 SORT-KEY should be `name' or `iso-spec' (default `name')."
118 (or sort-key
119 (setq sort-key 'name))
120 (let ((tail charset-list)
121 charset-info-list supplementary-list charset sort-func)
122 (dolist (charset charset-list)
123 ;; Generate a list that contains all information to display.
124 (let ((elt (list charset
125 (charset-dimension charset)
126 (charset-chars charset)
127 (charset-iso-final-char charset))))
128 (if (plist-get (charset-plist charset) :supplementary-p)
129 (push elt supplementary-list)
130 (push elt charset-info-list))))
131
132 ;; Determine a predicate for `sort' by SORT-KEY.
133 (setq sort-func
134 (cond ((eq sort-key 'name)
135 (lambda (x y) (string< (car x) (car y))))
136
137 ((eq sort-key 'iso-spec)
138 ;; Sort by DIMENSION CHARS FINAL-CHAR
139 (function
140 (lambda (x y)
141 (or (< (nth 1 x) (nth 1 y))
142 (and (= (nth 1 x) (nth 1 y))
143 (or (< (nth 2 x) (nth 2 y))
144 (and (= (nth 2 x) (nth 2 y))
145 (< (nth 3 x) (nth 3 y)))))))))
146 (t
147 (error "Invalid charset sort key: %s" sort-key))))
148
149 (setq charset-info-list (sort charset-info-list sort-func))
150 (setq supplementary-list (sort supplementary-list sort-func))
151
152 ;; Insert information of character sets.
153 (dolist (elt (append charset-info-list (list t) supplementary-list))
154 (if (eq elt t)
155 (progn
156 (insert "\n-------------- ")
157 (insert-text-button "Supplementary Character Sets"
158 'type 'help-info
159 'help-args '("(emacs)Charsets"))
160 (insert " --------------
161 Character sets for defining other charsets, or for backward compatibility
162 "))
163 (insert-text-button (symbol-name (car elt)) ; NAME
164 :type 'list-charset-chars
165 'help-args (list (car elt)))
166 (goto-char (point-max))
167 (insert "\t")
168 (indent-to 48)
169 (insert (format "%d %3d "
170 (nth 1 elt) (nth 2 elt)) ; DIMENSION and CHARS
171 (if (< (nth 3 elt) 0)
172 "none"
173 (nth 3 elt)))) ; FINAL-CHAR
174 (insert "\n"))))
175
176
177 ;; List all character sets in a form that a program can easily parse.
178
179 (defun list-character-sets-2 ()
180 (insert "#########################
181 ## LIST OF CHARSETS
182 ## Each line corresponds to one charset.
183 ## The following attributes are listed in this order
184 ## separated by a colon `:' in one line.
185 ## CHARSET-SYMBOL-NAME,
186 ## DIMENSION (1-4)
187 ## CHARS (number of characters in first dimension of charset)
188 ## ISO-FINAL-CHAR (character code of ISO-2022's final character)
189 ## -1 means that no final character is assigned.
190 ## DESCRIPTION (describing string of the charset)
191 ")
192 (dolist (charset charset-list)
193 (princ (format "%s:%d:%d:%d:%s\n"
194 charset
195 (charset-dimension charset)
196 (charset-chars charset)
197 ;;; (char-width (make-char charset))
198 ;;; (charset-direction charset)
199 (charset-iso-final-char charset)
200 ;;; (charset-iso-graphic-plane charset)
201 (charset-description charset)))))
202
203 (defvar non-iso-charset-alist nil
204 "Obsolete.")
205 (make-obsolete-variable 'non-iso-charset-alist "no longer relevant." "23.1")
206
207 ;; A variable to hold charset input history.
208 (defvar charset-history nil)
209
210
211 ;;;###autoload
212 (defun read-charset (prompt &optional default-value initial-input)
213 "Read a character set from the minibuffer, prompting with string PROMPT.
214 It must be an Emacs character set listed in the variable `charset-list'.
215
216 Optional arguments are DEFAULT-VALUE and INITIAL-INPUT.
217 DEFAULT-VALUE, if non-nil, is the default value.
218 INITIAL-INPUT, if non-nil, is a string inserted in the minibuffer initially.
219 See the documentation of the function `completing-read' for the detailed
220 meanings of these arguments."
221 (let* ((table (mapcar (lambda (x) (list (symbol-name x))) charset-list))
222 (charset (completing-read prompt table
223 nil t initial-input 'charset-history
224 default-value)))
225 (if (> (length charset) 0)
226 (intern charset))))
227
228 ;; List characters of the range MIN and MAX of CHARSET. If dimension
229 ;; of CHARSET is two (i.e. 2-byte charset), ROW is the first byte
230 ;; (block index) of the characters, and MIN and MAX are the second
231 ;; bytes of the characters. If the dimension is one, ROW should be 0.
232
233 (defun list-block-of-chars (charset row min max)
234 (let (i ch)
235 (insert-char ?- (+ 7 (* 4 16)))
236 (insert "\n ")
237 (setq i 0)
238 (while (< i 16)
239 (insert (format "%4X" i))
240 (setq i (1+ i)))
241 (setq i (* (/ min 16) 16))
242 (while (<= i max)
243 (if (= (% i 16) 0)
244 (insert (format "\n%6Xx" (/ (+ (* row 256) i) 16))))
245 (setq ch (if (< i min)
246 32
247 (or (decode-char charset (+ (* row 256) i))
248 32))) ; gap in mapping
249 ;; Don't insert control codes, non-Unicode characters.
250 (if (or (< ch 32) (= ch 127))
251 (setq ch (single-key-description ch))
252 (if (and (>= ch 128) (< ch 160))
253 (setq ch (format "%02Xh" ch))
254 (if (> ch #x10FFFF)
255 (setq ch 32))))
256 (insert "\t" ch)
257 (setq i (1+ i))))
258 (insert "\n"))
259
260 ;;;###autoload
261 (defun list-charset-chars (charset)
262 "Display a list of characters in character set CHARSET."
263 (interactive (list (read-charset "Character set: ")))
264 (or (charsetp charset)
265 (error "Invalid character set: %s" charset))
266 (with-output-to-temp-buffer "*Character List*"
267 (with-current-buffer standard-output
268 (if (coding-system-p charset)
269 ;; Useful to be able to do C-u C-x = to find file code, for
270 ;; instance:
271 (set-buffer-file-coding-system charset))
272 (setq mode-line-format (copy-sequence mode-line-format))
273 (let ((slot (memq 'mode-line-buffer-identification mode-line-format)))
274 (if slot
275 (setcdr slot
276 (cons (format " (%s)" charset)
277 (cdr slot)))))
278 (setq tab-width 4)
279 (set-buffer-multibyte t)
280 (let ((dim (charset-dimension charset))
281 (chars (charset-chars charset))
282 ;; (plane (charset-iso-graphic-plane charset))
283 (plane 1)
284 (range (plist-get (charset-plist charset) :code-space))
285 min max min2 max2)
286 (if (> dim 2)
287 (error "Can only list 1- and 2-dimensional charsets"))
288 (insert (format "Characters in the coded character set %s.\n" charset))
289 (narrow-to-region (point) (point))
290 (setq min (aref range 0)
291 max (aref range 1))
292 (if (= dim 1)
293 (list-block-of-chars charset 0 min max)
294 (setq min2 (aref range 2)
295 max2 (aref range 3))
296 (let ((i min2))
297 (while (<= i max2)
298 (list-block-of-chars charset i min max)
299 (setq i (1+ i)))))
300 (put-text-property (point-min) (point-max) 'charset charset)
301 (widen)))))
302
303
304 ;;;###autoload
305 (defun describe-character-set (charset)
306 "Display information about built-in character set CHARSET."
307 (interactive (list (read-charset "Charset: ")))
308 (or (charsetp charset)
309 (error "Invalid charset: %S" charset))
310 (help-setup-xref (list #'describe-character-set charset)
311 (called-interactively-p 'interactive))
312 (with-output-to-temp-buffer (help-buffer)
313 (with-current-buffer standard-output
314 (insert "Character set: " (symbol-name charset))
315 (let ((name (get-charset-property charset :name)))
316 (if (not (eq name charset))
317 (insert " (alias of " (symbol-name name) ?\))))
318 (insert "\n\n" (charset-description charset) "\n\n")
319 (insert "Number of contained characters: ")
320 (dotimes (i (charset-dimension charset))
321 (unless (= i 0)
322 (insert ?x))
323 (insert (format "%d" (charset-chars charset (1+ i)))))
324 (insert ?\n)
325 (let ((char (charset-iso-final-char charset)))
326 (when (> char 0)
327 (insert "Final char of ISO2022 designation sequence: ")
328 (insert (format-message "`%c'\n" char))))
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)))
336
337 (dolist (elt `((:ascii-compatible-p "ASCII compatible." nil)
338 (:map "Map file: " identity)
339 (:unify-map "Unification map file: " identity)
340 (:invalid-code
341 nil
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 (let ((print-length 10) (print-level 2))
364 (princ (funcall (nth 2 elt) val) (current-buffer))))
365 (insert ?\n)))))))
366 \f
367 ;;; CODING-SYSTEM
368
369 (defvar graphic-register) ; dynamic bondage
370
371 ;; Print information about designation of each graphic register in
372 ;; DESIGNATIONS in human readable format. See the documentation of
373 ;; `define-coding-system' for the meaning of DESIGNATIONS
374 ;; (`:designation' property).
375 (defun print-designation (designations)
376 (let (charset)
377 (dotimes (graphic-register 4)
378 (setq charset (aref designations graphic-register))
379 (princ (format
380 " G%d -- %s\n"
381 graphic-register
382 (cond ((null charset)
383 "never used")
384 ((eq charset t)
385 "no initial designation, and used by any charsets")
386 ((symbolp charset)
387 (format "%s:%s"
388 charset (charset-description charset)))
389 ((listp charset)
390 (if (charsetp (car charset))
391 (format "%s:%s, and also used by the following:"
392 (car charset)
393 (charset-description (car charset)))
394 "no initial designation, and used by the following:"))
395 (t
396 "invalid designation information"))))
397 (when (listp charset)
398 (setq charset (cdr charset))
399 (while charset
400 (cond ((eq (car charset) t)
401 (princ "\tany other charsets\n"))
402 ((charsetp (car charset))
403 (princ (format "\t%s:%s\n"
404 (car charset)
405 (charset-description (car charset)))))
406 (t
407 "invalid designation information"))
408 (setq charset (cdr charset)))))))
409
410 ;;;###autoload
411 (defun describe-coding-system (coding-system)
412 "Display information about CODING-SYSTEM."
413 (interactive "zDescribe coding system (default current choices): ")
414 (if (null coding-system)
415 (describe-current-coding-system)
416 (help-setup-xref (list #'describe-coding-system coding-system)
417 (called-interactively-p 'interactive))
418 (with-output-to-temp-buffer (help-buffer)
419 (print-coding-system-briefly coding-system 'doc-string)
420 (let ((type (coding-system-type coding-system))
421 ;; Fixme: use this
422 (extra-spec (coding-system-plist coding-system)))
423 (princ "Type: ")
424 (princ type)
425 (cond ((eq type 'undecided)
426 (princ " (do automatic conversion)"))
427 ((eq type 'utf-8)
428 (princ " (UTF-8: Emacs internal multibyte form)"))
429 ((eq type 'utf-16)
430 ;; (princ " (UTF-16)")
431 )
432 ((eq type 'shift-jis)
433 (princ " (Shift-JIS, MS-KANJI)"))
434 ((eq type 'iso-2022)
435 (princ " (variant of ISO-2022)\n")
436 (princ "Initial designations:\n")
437 (print-designation (coding-system-get coding-system
438 :designation))
439
440 (when (coding-system-get coding-system :flags)
441 (princ "Other specifications: \n ")
442 (apply #'print-list
443 (coding-system-get coding-system :flags))))
444 ((eq type 'charset)
445 (princ " (charset)"))
446 ((eq type 'ccl)
447 (princ " (do conversion by CCL program)"))
448 ((eq type 'raw-text)
449 (princ " (text with random binary characters)"))
450 ((eq type 'emacs-mule)
451 (princ " (Emacs 21 internal encoding)"))
452 ((eq type 'big5))
453 (t (princ ": invalid coding-system.")))
454 (princ "\nEOL type: ")
455 (let ((eol-type (coding-system-eol-type coding-system)))
456 (cond ((vectorp eol-type)
457 (princ "Automatic selection from:\n\t")
458 (princ eol-type)
459 (princ "\n"))
460 ((or (null eol-type) (eq eol-type 0)) (princ "LF\n"))
461 ((eq eol-type 1) (princ "CRLF\n"))
462 ((eq eol-type 2) (princ "CR\n"))
463 (t (princ "invalid\n")))))
464 (let ((postread (coding-system-get coding-system :post-read-conversion)))
465 (when postread
466 (princ "After decoding text normally,")
467 (princ " perform post-conversion using the function: ")
468 (princ "\n ")
469 (princ postread)
470 (princ "\n")))
471 (let ((prewrite (coding-system-get coding-system :pre-write-conversion)))
472 (when prewrite
473 (princ "Before encoding text normally,")
474 (princ " perform pre-conversion using the function: ")
475 (princ "\n ")
476 (princ prewrite)
477 (princ "\n")))
478 (with-current-buffer standard-output
479 (let ((charsets (coding-system-charset-list coding-system)))
480 (when (and (not (eq (coding-system-base coding-system) 'raw-text))
481 charsets)
482 (cond
483 ((eq charsets 'iso-2022)
484 (insert "This coding system can encode all ISO 2022 charsets."))
485 ((eq charsets 'emacs-mule)
486 (insert "This coding system can encode all emacs-mule charsets\
487 ."""))
488 (t
489 (insert "This coding system encodes the following charsets:\n ")
490 (while charsets
491 (insert " " (symbol-name (car charsets)))
492 (search-backward (symbol-name (car charsets)))
493 (help-xref-button 0 'help-character-set (car charsets))
494 (goto-char (point-max))
495 (setq charsets (cdr charsets)))))))))))
496
497 ;;;###autoload
498 (defun describe-current-coding-system-briefly ()
499 "Display coding systems currently used in a brief format in echo area.
500
501 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
502 where mnemonics of the following coding systems come in this order
503 in place of `..':
504 `buffer-file-coding-system' (of the current buffer)
505 eol-type of `buffer-file-coding-system' (of the current buffer)
506 Value returned by `keyboard-coding-system'
507 eol-type of `keyboard-coding-system'
508 Value returned by `terminal-coding-system'.
509 eol-type of `terminal-coding-system'
510 `process-coding-system' for read (of the current buffer, if any)
511 eol-type of `process-coding-system' for read (of the current buffer, if any)
512 `process-coding-system' for write (of the current buffer, if any)
513 eol-type of `process-coding-system' for write (of the current buffer, if any)
514 default `buffer-file-coding-system'
515 eol-type of default `buffer-file-coding-system'
516 `default-process-coding-system' for read
517 eol-type of `default-process-coding-system' for read
518 `default-process-coding-system' for write
519 eol-type of `default-process-coding-system'"
520 (interactive)
521 (let* ((proc (get-buffer-process (current-buffer)))
522 (process-coding-systems (if proc (process-coding-system proc))))
523 (message
524 "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]"
525 (coding-system-mnemonic buffer-file-coding-system)
526 (coding-system-eol-type-mnemonic buffer-file-coding-system)
527 (coding-system-mnemonic (keyboard-coding-system))
528 (coding-system-eol-type-mnemonic (keyboard-coding-system))
529 (coding-system-mnemonic (terminal-coding-system))
530 (coding-system-eol-type-mnemonic (terminal-coding-system))
531 (coding-system-mnemonic (car process-coding-systems))
532 (coding-system-eol-type-mnemonic (car process-coding-systems))
533 (coding-system-mnemonic (cdr process-coding-systems))
534 (coding-system-eol-type-mnemonic (cdr process-coding-systems))
535 (coding-system-mnemonic (default-value 'buffer-file-coding-system))
536 (coding-system-eol-type-mnemonic
537 (default-value 'buffer-file-coding-system))
538 (coding-system-mnemonic (car default-process-coding-system))
539 (coding-system-eol-type-mnemonic (car default-process-coding-system))
540 (coding-system-mnemonic (cdr default-process-coding-system))
541 (coding-system-eol-type-mnemonic (cdr default-process-coding-system))
542 )))
543
544 (defun print-coding-system-briefly (coding-system &optional doc-string)
545 "Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
546 If DOC-STRING is non-nil, print also the docstring of CODING-SYSTEM.
547 If DOC-STRING is `tightly', don't print an empty line before the
548 docstring, and print only the first line of the docstring."
549 (if (not coding-system)
550 (princ "nil\n")
551 (princ (format "%c -- %s"
552 (coding-system-mnemonic coding-system)
553 coding-system))
554 (let ((aliases (coding-system-aliases coding-system)))
555 (cond ((eq coding-system (car aliases))
556 (if (cdr aliases)
557 (princ (format " %S" (cons 'alias: (cdr aliases))))))
558 ((memq coding-system aliases)
559 (princ (format " (alias of %s)" (car aliases))))
560 (t
561 (let ((eol-type (coding-system-eol-type coding-system))
562 (base-eol-type (coding-system-eol-type (car aliases))))
563 (if (and (integerp eol-type)
564 (vectorp base-eol-type)
565 (not (eq coding-system (aref base-eol-type eol-type))))
566 (princ (format " (alias of %s)"
567 (aref base-eol-type eol-type))))))))
568 (princ "\n")
569 (or (eq doc-string 'tightly)
570 (princ "\n"))
571 (if doc-string
572 (let ((doc (or (coding-system-doc-string coding-system) "")))
573 (when (eq doc-string 'tightly)
574 (if (string-match "\n" doc)
575 (setq doc (substring doc 0 (match-beginning 0))))
576 (setq doc (concat " " doc)))
577 (princ (format "%s\n" (substitute-command-keys doc)))))))
578
579 ;;;###autoload
580 (defun describe-current-coding-system ()
581 "Display coding systems currently used, in detail."
582 (interactive)
583 (with-output-to-temp-buffer "*Help*"
584 (let* ((proc (get-buffer-process (current-buffer)))
585 (process-coding-systems (if proc (process-coding-system proc))))
586 (princ "Coding system for saving this buffer:\n ")
587 (if (local-variable-p 'buffer-file-coding-system)
588 (print-coding-system-briefly buffer-file-coding-system)
589 (princ "Not set locally, use the default.\n"))
590 (princ "Default coding system (for new files):\n ")
591 (print-coding-system-briefly (default-value 'buffer-file-coding-system))
592 (princ "Coding system for keyboard input:\n ")
593 (print-coding-system-briefly (keyboard-coding-system))
594 (princ "Coding system for terminal output:\n ")
595 (print-coding-system-briefly (terminal-coding-system))
596 (when (boundp 'selection-coding-system)
597 (princ "Coding system for inter-client cut and paste:\n ")
598 (print-coding-system-briefly selection-coding-system))
599 (when (get-buffer-process (current-buffer))
600 (princ "Coding systems for process I/O:\n")
601 (princ " encoding input to the process: ")
602 (print-coding-system-briefly (cdr process-coding-systems))
603 (princ " decoding output from the process: ")
604 (print-coding-system-briefly (car process-coding-systems)))
605 (princ "Defaults for subprocess I/O:\n")
606 (princ " decoding: ")
607 (print-coding-system-briefly (car default-process-coding-system))
608 (princ " encoding: ")
609 (print-coding-system-briefly (cdr default-process-coding-system)))
610
611 (with-current-buffer standard-output
612
613 (princ "
614 Priority order for recognizing coding systems when reading files:\n")
615 (let ((i 1))
616 (dolist (elt (coding-system-priority-list))
617 (princ (format " %d. %s " i elt))
618 (let ((aliases (coding-system-aliases elt)))
619 (if (eq elt (car aliases))
620 (if (cdr aliases)
621 (princ (cons 'alias: (cdr aliases))))
622 (princ (list 'alias 'of (car aliases))))
623 (terpri)
624 (setq i (1+ i)))))
625
626 (princ "\n Other coding systems cannot be distinguished automatically
627 from these, and therefore cannot be recognized automatically
628 with the present coding system priorities.\n\n")
629
630 ;; Fixme: should this be replaced or junked?
631 (if nil
632 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else))
633 coding-system codings)
634 (while categories
635 (setq coding-system (symbol-value (car categories)))
636 (mapc
637 (lambda (x)
638 (if (and (not (eq x coding-system))
639 (let ((flags (coding-system-get :flags)))
640 (not (or (memq 'use-roman flags)
641 (memq 'use-oldjis flags)))))
642 (setq codings (cons x codings))))
643 (get (car categories) 'coding-systems))
644 (if codings
645 (let ((max-col (window-width))
646 pos)
647 (princ (format "\
648 The following are decoded correctly but recognized as %s:\n "
649 coding-system))
650 (while codings
651 (setq pos (point))
652 (insert (format " %s" (car codings)))
653 (when (> (current-column) max-col)
654 (goto-char pos)
655 (insert "\n ")
656 (goto-char (point-max)))
657 (setq codings (cdr codings)))
658 (insert "\n\n")))
659 (setq categories (cdr categories)))))
660
661 (princ "Particular coding systems specified for certain file names:\n")
662 (terpri)
663 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
664 (princ " ---------\t--------------\t\t----------------\n")
665 (let ((func (lambda (operation alist)
666 (princ " ")
667 (princ operation)
668 (if (not alist)
669 (princ "\tnothing specified\n")
670 (while alist
671 (indent-to 16)
672 (prin1 (car (car alist)))
673 (if (>= (current-column) 40)
674 (newline))
675 (indent-to 40)
676 (princ (cdr (car alist)))
677 (princ "\n")
678 (setq alist (cdr alist)))))))
679 (funcall func "File I/O" file-coding-system-alist)
680 (funcall func "Process I/O" process-coding-system-alist)
681 (funcall func "Network I/O" network-coding-system-alist))
682 (help-mode))))
683
684 (defun print-coding-system (coding-system)
685 "Print detailed information on CODING-SYSTEM."
686 (let ((type (coding-system-type coding-system))
687 (eol-type (coding-system-eol-type coding-system))
688 (flags (coding-system-get coding-system :flags))
689 (aliases (coding-system-aliases coding-system)))
690 (if (not (eq (car aliases) coding-system))
691 (princ (format "%s (alias of %s)\n" coding-system (car aliases)))
692 (princ coding-system)
693 (dolist (alias (cdr aliases))
694 (princ ",")
695 (princ alias))
696 (princ (format ":%s:%c:%d:"
697 type
698 (coding-system-mnemonic coding-system)
699 (if (integerp eol-type) eol-type 3)))
700 (cond ((eq type 'iso2022)
701 (let ((idx 0)
702 charset)
703 (while (< idx 4)
704 (setq charset (aref flags idx))
705 (cond ((null charset)
706 (princ -1))
707 ((eq charset t)
708 (princ -2))
709 ((charsetp charset)
710 (princ charset))
711 ((listp charset)
712 (princ "(")
713 (princ (car charset))
714 (setq charset (cdr charset))
715 (while charset
716 (princ ",")
717 (princ (car charset))
718 (setq charset (cdr charset)))
719 (princ ")")))
720 (princ ",")
721 (setq idx (1+ idx)))
722 (while (< idx 12)
723 (princ (if (aref flags idx) 1 0))
724 (princ ",")
725 (setq idx (1+ idx)))
726 (princ (if (aref flags idx) 1 0))))
727 ((eq type 'ccl)
728 (let (i len)
729 (if (symbolp (car flags))
730 (princ (format " %s" (car flags)))
731 (setq i 0 len (length (car flags)))
732 (while (< i len)
733 (princ (format " %x" (aref (car flags) i)))
734 (setq i (1+ i))))
735 (princ ",")
736 (if (symbolp (cdr flags))
737 (princ (format "%s" (cdr flags)))
738 (setq i 0 len (length (cdr flags)))
739 (while (< i len)
740 (princ (format " %x" (aref (cdr flags) i)))
741 (setq i (1+ i))))))
742 (t (princ 0)))
743 (princ ":")
744 (princ (coding-system-doc-string coding-system))
745 (princ "\n"))))
746
747 ;;;###autoload
748 (defun list-coding-systems (&optional arg)
749 "Display a list of all coding systems.
750 This shows the mnemonic letter, name, and description of each coding system.
751
752 With prefix ARG, the output format gets more cryptic,
753 but still contains full information about each coding system."
754 (interactive "P")
755 (with-output-to-temp-buffer "*Help*"
756 (list-coding-systems-1 arg)))
757
758 (defun list-coding-systems-1 (arg)
759 (if (null arg)
760 (princ "\
761 ###############################################
762 # List of coding systems in the following format:
763 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
764 # DOC-STRING
765 ")
766 (princ (substitute-command-keys "\
767 #########################
768 ## LIST OF CODING SYSTEMS
769 ## Each line corresponds to one coding system
770 ## Format of a line is:
771 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
772 ## :PRE-WRITE-CONVERSION:DOC-STRING,
773 ## where
774 ## NAME = coding system name
775 ## ALIAS = alias of the coding system
776 ## TYPE = nil (no conversion), t (undecided or automatic detection),
777 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
778 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
779 ## FLAGS =
780 ## if TYPE = 2 then
781 ## comma (`,') separated data of the following:
782 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
783 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
784 ## else if TYPE = 4 then
785 ## comma (`,') separated CCL programs for read and write
786 ## else
787 ## 0
788 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
789 ##
790 ")))
791 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only)))
792 (if (null arg)
793 (print-coding-system-briefly coding-system 'tightly)
794 (print-coding-system coding-system))))
795
796 ;; Fixme: delete?
797 ;;;###autoload
798 (defun list-coding-categories ()
799 "Display a list of all coding categories."
800 (with-output-to-temp-buffer "*Help*"
801 (princ "\
802 ############################
803 ## LIST OF CODING CATEGORIES (ordered by priority)
804 ## CATEGORY:CODING-SYSTEM
805 ##
806 ")
807 (let ((l coding-category-list))
808 (while l
809 (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
810 (setq l (cdr l))))))
811 \f
812 ;;; FONT
813
814 (declare-function font-info "font.c" (name &optional frame))
815
816 (defun describe-font-internal (font-info &optional ignored)
817 "Print information about a font in FONT-INFO.
818 The IGNORED argument is ignored."
819 (print-list "name (opened by):" (aref font-info 0))
820 (print-list " full name:" (aref font-info 1))
821 (and (aref font-info 12)
822 (print-list " file name:" (aref font-info 12)))
823 (print-list " size:" (format "%2d" (aref font-info 2)))
824 (print-list " height:" (format "%2d" (aref font-info 3)))
825 (print-list " baseline-offset:" (format "%2d" (aref font-info 4)))
826 (print-list "relative-compose:" (format "%2d" (aref font-info 5)))
827 (print-list " default-ascent:" (format "%2d" (aref font-info 6)))
828 (print-list " ascent:" (format "%2d" (aref font-info 8)))
829 (print-list " descent:" (format "%2d" (aref font-info 9)))
830 (print-list " average-width:" (format "%2d" (aref font-info 11)))
831 (print-list " space-width:" (format "%2d" (aref font-info 10)))
832 (print-list " max-width:" (format "%2d" (aref font-info 7))))
833
834 ;;;###autoload
835 (defun describe-font (fontname)
836 "Display information about a font whose name is FONTNAME.
837 The font must be already used by Emacs."
838 (interactive "sFont name (default current choice for ASCII chars): ")
839 (or (and window-system (fboundp 'fontset-list))
840 (error "No fonts being used"))
841 (let (font-info)
842 (if (or (not fontname) (= (length fontname) 0))
843 (setq fontname (face-attribute 'default :font)))
844 (setq font-info (font-info fontname))
845 (if (null font-info)
846 (if (fontp fontname 'font-object)
847 ;; The font should be surely used. So, there's some
848 ;; problem about getting information about it. It is
849 ;; better to print the fontname to show which font has
850 ;; this problem.
851 (message "No information about \"%s\"" (font-xlfd-name fontname))
852 (message "No matching font found"))
853 (with-output-to-temp-buffer "*Help*"
854 (describe-font-internal font-info)))))
855
856 (defun print-fontset-element (val)
857 ;; VAL has this format:
858 ;; ((REQUESTED-FONT-NAME OPENED-FONT-NAME ...) ...)
859 ;; CHAR RANGE is already inserted. Get character codes from
860 ;; the current line.
861 (beginning-of-line)
862 (let ((from (following-char))
863 (to (if (looking-at "[^.]*[.]* ")
864 (char-after (match-end 0)))))
865 (if (re-search-forward "[ \t]*$" nil t)
866 (delete-region (match-beginning 0) (match-end 0)))
867
868 ;; For non-ASCII characters, insert also CODE RANGE.
869 (if (or (>= from 128) (and to (>= to 128)))
870 (if to
871 (insert (format " (#x%02X .. #x%02X)" from to))
872 (insert (format " (#x%02X)" from))))
873
874 ;; Insert a requested font name.
875 (dolist (elt val)
876 (if (not elt)
877 (insert "\n -- inhibit fallback fonts --")
878 (let ((requested (car elt)))
879 (if (stringp requested)
880 (insert "\n " requested)
881 (let (family registry weight slant width adstyle)
882 (if (and (fboundp 'fontp) (fontp requested))
883 (setq family (font-get requested :family)
884 registry (font-get requested :registry)
885 weight (font-get requested :weight)
886 slant (font-get requested :slant)
887 width (font-get requested :width)
888 adstyle (font-get requested :adstyle))
889 (setq family (aref requested 0)
890 registry (aref requested 5)
891 weight (aref requested 1)
892 slant (aref requested 2)
893 width (aref requested 3)
894 adstyle (aref requested 4)))
895 (if (not family)
896 (setq family "*-*")
897 (if (symbolp family)
898 (setq family (symbol-name family)))
899 (or (string-match "-" family)
900 (setq family (concat "*-" family))))
901 (if (not registry)
902 (setq registry "*-*")
903 (if (symbolp registry)
904 (setq registry (symbol-name registry)))
905 (or (string-match "-" registry)
906 (= (aref registry (1- (length registry))) ?*)
907 (setq registry (concat registry "*"))))
908 (insert (format"\n -%s-%s-%s-%s-%s-*-*-*-*-*-*-%s"
909 family (or weight "*") (or slant "*") (or width "*")
910 (or adstyle "*") registry)))))
911
912 ;; Insert opened font names (if any).
913 (if (and (boundp 'print-opened) (symbol-value 'print-opened))
914 (dolist (opened (cdr elt))
915 (insert "\n\t[" opened "]")))))))
916
917 (declare-function query-fontset "fontset.c" (pattern &optional regexpp))
918 (declare-function fontset-info "fontset.c" (fontset &optional frame))
919
920 (defun print-fontset (fontset &optional print-opened)
921 "Print information about FONTSET.
922 FONTSET nil means the fontset of the selected frame, t means the
923 default fontset.
924 If optional arg PRINT-OPENED is non-nil, also print names of all opened
925 fonts for FONTSET. This function actually inserts the information in
926 the current buffer."
927 (if (eq fontset t)
928 (setq fontset (query-fontset "fontset-default"))
929 (if (eq fontset nil)
930 (setq fontset (face-attribute 'default :fontset))))
931 (beginning-of-line)
932 (narrow-to-region (point) (point))
933 (insert "Fontset: " fontset "\n")
934 (insert (propertize "CHAR RANGE" 'face 'underline)
935 " (" (propertize "CODE RANGE" 'face 'underline) ")\n")
936 (insert " " (propertize "FONT NAME" 'face 'underline)
937 " (" (propertize "REQUESTED" 'face 'underline)
938 " and [" (propertize "OPENED" 'face 'underline) "])")
939 (let* ((info (fontset-info fontset))
940 (default-info (char-table-extra-slot info 0))
941 start1 end1 start2 end2)
942 (describe-vector info 'print-fontset-element)
943 (when (char-table-range info nil)
944 ;; The default of FONTSET is described.
945 (setq start1 (re-search-backward "^default"))
946 (delete-region (point) (line-end-position))
947 (insert "\n ---<fallback to the default of the specified fontset>---")
948 (put-text-property (line-beginning-position) (point) 'face 'highlight)
949 (goto-char (point-max))
950 (setq end1 (setq start2 (point))))
951 (when default-info
952 (insert "\n ---<fallback to the default fontset>---")
953 (put-text-property (line-beginning-position) (point) 'face 'highlight)
954 (describe-vector default-info 'print-fontset-element)
955 (when (char-table-range default-info nil)
956 ;; The default of the default fontset is described.
957 (setq end2 (re-search-backward "^default"))
958 (delete-region (point) (line-end-position))
959 (insert "\n ---<fallback to the default of the default fontset>---")
960 (put-text-property (line-beginning-position) (point) 'face 'highlight)))
961 (if (and start1 end2)
962 ;; Reorder the printed information to match with the font
963 ;; searching strategy; i.e. FONTSET, the default fontset,
964 ;; default of FONTSET, default of the default fontset.
965 (transpose-regions start1 end1 start2 end2))
966 (goto-char (point-max)))
967 (widen))
968
969 (defvar fontset-alias-alist)
970 (declare-function fontset-list "fontset.c" ())
971
972 ;;;###autoload
973 (defun describe-fontset (fontset)
974 "Display information about FONTSET.
975 This shows which font is used for which character(s)."
976 (interactive
977 (if (not (and window-system (fboundp 'fontset-list)))
978 (error "No fontsets being used")
979 (let ((fontset-list (nconc
980 (fontset-list)
981 (mapcar 'cdr fontset-alias-alist)))
982 (completion-ignore-case t))
983 (list (completing-read
984 "Fontset (default used by the current frame): "
985 fontset-list nil t)))))
986 (if (= (length fontset) 0)
987 (setq fontset (face-attribute 'default :fontset))
988 (setq fontset (query-fontset fontset)))
989 (help-setup-xref (list #'describe-fontset fontset)
990 (called-interactively-p 'interactive))
991 (with-output-to-temp-buffer (help-buffer)
992 (with-current-buffer standard-output
993 (print-fontset fontset t))))
994
995 (declare-function fontset-plain-name "fontset" (fontset))
996
997 ;;;###autoload
998 (defun list-fontsets (arg)
999 "Display a list of all fontsets.
1000 This shows the name, size, and style of each fontset.
1001 With prefix arg, also list the fonts contained in each fontset;
1002 see the function `describe-fontset' for the format of the list."
1003 (interactive "P")
1004 (if (not (and window-system (fboundp 'fontset-list)))
1005 (error "No fontsets being used")
1006 (help-setup-xref (list #'list-fontsets arg)
1007 (called-interactively-p 'interactive))
1008 (with-output-to-temp-buffer (help-buffer)
1009 (with-current-buffer standard-output
1010 ;; This code is duplicated near the end of mule-diag.
1011 (let ((fontsets
1012 (sort (fontset-list)
1013 (lambda (x y)
1014 (string< (fontset-plain-name x)
1015 (fontset-plain-name y))))))
1016 (while fontsets
1017 (if arg
1018 (print-fontset (car fontsets) nil)
1019 (insert "Fontset: " (car fontsets) "\n"))
1020 (setq fontsets (cdr fontsets))))))))
1021 \f
1022 ;;;###autoload
1023 (defun list-input-methods ()
1024 "Display information about all input methods."
1025 (interactive)
1026 (help-setup-xref '(list-input-methods)
1027 (called-interactively-p 'interactive))
1028 (with-output-to-temp-buffer (help-buffer)
1029 (list-input-methods-1)
1030 (with-current-buffer standard-output
1031 (save-excursion
1032 (goto-char (point-min))
1033 (while (re-search-forward
1034 (substitute-command-keys "^ \\([^ ]+\\) (`.*' in mode line)$")
1035 nil t)
1036 (help-xref-button 1 'help-input-method (match-string 1)))))))
1037
1038 (defun list-input-methods-1 ()
1039 (if (not input-method-alist)
1040 (princ "
1041 No input method is available, perhaps because you have not
1042 installed LEIM (Libraries of Emacs Input Methods).")
1043 (princ (substitute-command-keys
1044 "LANGUAGE\n NAME (`TITLE' in mode line)\n"))
1045 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1046 (setq input-method-alist
1047 (sort input-method-alist
1048 (lambda (x y) (string< (nth 1 x) (nth 1 y)))))
1049
1050 (let (language)
1051 (dolist (elt input-method-alist)
1052 (when (not (equal language (nth 1 elt)))
1053 (setq language (nth 1 elt))
1054 (princ language)
1055 (terpri))
1056 (princ (format-message
1057 " %s (`%s' in mode line)\n %s\n"
1058 (car elt)
1059 (let ((title (nth 3 elt)))
1060 (if (and (consp title) (stringp (car title)))
1061 (car title)
1062 title))
1063 ;; If the doc is multi-line, indent all
1064 ;; non-blank lines. (Bug#8066)
1065 (replace-regexp-in-string
1066 "\n\\(.\\)" "\n \\1"
1067 (substitute-command-keys (or (nth 4 elt) "")))))))))
1068 \f
1069 ;;; DIAGNOSIS
1070
1071 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1072 (defun insert-section (section-number title)
1073 (insert "########################################\n"
1074 "# Section " (format "%d" section-number) ". " title "\n"
1075 "########################################\n\n"))
1076
1077 ;;;###autoload
1078 (defun mule-diag ()
1079 "Display diagnosis of the multilingual environment (Mule).
1080
1081 This shows various information related to the current multilingual
1082 environment, including lists of input methods, coding systems,
1083 character sets, and fontsets (if Emacs is running under a window
1084 system which uses fontsets)."
1085 (interactive)
1086 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1087 (with-current-buffer standard-output
1088 (insert "###############################################\n"
1089 "### Current Status of Multilingual Features ###\n"
1090 "###############################################\n\n"
1091 "CONTENTS: Section 1. General Information\n"
1092 " Section 2. Display\n"
1093 " Section 3. Input methods\n"
1094 " Section 4. Coding systems\n"
1095 " Section 5. Character sets\n")
1096 (if (and window-system (fboundp 'fontset-list))
1097 (insert " Section 6. Fontsets\n"))
1098 (insert "\n")
1099
1100 (insert-section 1 "General Information")
1101 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1102 (insert "Configuration options:\n " system-configuration-options "\n\n")
1103 (insert "Multibyte characters awareness:\n"
1104 (format " default: %S\n" (default-value
1105 'enable-multibyte-characters))
1106 (format " current-buffer: %S\n\n" enable-multibyte-characters))
1107 (insert "Current language environment: " current-language-environment
1108 "\n\n")
1109
1110 (insert-section 2 "Display")
1111 (if window-system
1112 (insert (format "Window-system: %s" window-system))
1113 (insert "Terminal: " (getenv "TERM")))
1114 (insert "\n\n")
1115
1116 (if window-system
1117 (let ((font (cdr (assq 'font (frame-parameters)))))
1118 (insert "The font and fontset of the selected frame are:\n"
1119 " font: " font "\n"
1120 " fontset: " (face-attribute 'default :fontset) "\n"))
1121 (insert "Coding system of the terminal: "
1122 (symbol-name (terminal-coding-system))))
1123 (insert "\n\n")
1124
1125 (insert-section 3 "Input methods")
1126 (list-input-methods-1)
1127 (insert "\n")
1128 (if default-input-method
1129 (insert (format "Default input method: %s\n" default-input-method))
1130 (insert "No default input method is specified\n"))
1131
1132 (insert-section 4 "Coding systems")
1133 (list-coding-systems-1 t)
1134 (insert "\n")
1135
1136 (insert-section 5 "Character sets")
1137 (list-character-sets-2)
1138 (insert "\n")
1139
1140 (when (and window-system (fboundp 'fontset-list))
1141 ;; This code duplicates most of list-fontsets.
1142 (insert-section 6 "Fontsets")
1143 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1144 (insert "------------\t\t\t\t\t\t ----- -----\n")
1145 (dolist (fontset (fontset-list))
1146 (print-fontset fontset t)
1147 (insert "\n")))
1148 (help-print-return-message))))
1149
1150 ;;;###autoload
1151 (defun font-show-log (&optional limit)
1152 "Show log of font listing and opening.
1153 Prefix arg LIMIT says how many fonts to show for each listing.
1154 The default is 20. If LIMIT is negative, do not limit the listing."
1155 (interactive "P")
1156 (setq limit (if limit (prefix-numeric-value limit) 20))
1157 (if (eq font-log t)
1158 (message "Font logging is currently suppressed")
1159 (with-output-to-temp-buffer "*Help*"
1160 (set-buffer standard-output)
1161 (dolist (elt (reverse font-log))
1162 (insert (format "%s: %s\n" (car elt) (cadr elt)))
1163 (setq elt (nth 2 elt))
1164 (if (or (vectorp elt) (listp elt))
1165 (let ((i 0))
1166 (catch 'tag
1167 (mapc #'(lambda (x)
1168 (setq i (1+ i))
1169 (when (= i limit)
1170 (insert " ...\n")
1171 (throw 'tag nil))
1172 (insert (format " %s\n" x)))
1173 elt)))
1174 (insert (format " %s\n" elt)))))))
1175
1176
1177 (provide 'mule-diag)
1178
1179 ;;; mule-diag.el ends here