Remove non-free old and crusty clearcase pkg
[packages] / mule-packages / mule-base / mule-diag.el
1 ;;; mule-diag.el --- Show diagnosis of multilingual environment (Mule)
2
3 ;; Copyright (C) 1995,1999 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
6
7 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 ;; 02111-1307, USA.
25
26 ;;; General utility function
27
28 (eval-when-compile (load "mule-util"))
29
30 ;; Print all arguments with single space separator in one line.
31 (defun print-list (&rest args)
32   (while (cdr args)
33     (when (car args)
34       (princ (car args))
35       (princ " "))
36     (setq args (cdr args)))
37   (princ (car args))
38   (princ "\n"))
39
40 ;; Re-order the elements of charset-list.
41 ;; (defun sort-charset-list ()
42 ;;   (setq charset-list
43 ;;         (sort charset-list
44 ;;               (function (lambda (x y) (< (charset-id x) (charset-id y)))))))
45 (defun sorted-charset-list ()
46   (sort (charset-list)
47         (function (lambda (x y) (< (charset-id x) (charset-id y))))))
48
49 ;;; CHARSET
50
51 ;;;###autoload
52 (defun list-character-sets (&optional arg)
53   "Display a list of all character sets.
54
55 The ID column contains a charset identification number for internal use.
56 The B column contains a number of bytes occupied in a buffer
57   by any character in this character set.
58 The W column contains a number of columns occupied on the screen
59   by any character in this character set.
60
61 With prefix arg, the output format gets more cryptic,
62 but still shows the full information."
63   (interactive "P")
64   ;; (sort-charset-list)
65   (with-output-to-temp-buffer "*Help*"
66     (save-excursion
67       (set-buffer standard-output)
68       (list-character-sets-1 arg)
69       (help-mode)
70       (setq truncate-lines t))))
71
72 (defun list-character-sets-1 (arg)
73   (let ((l (sorted-charset-list))
74         charset)
75     (if (null arg)
76         (progn
77           (insert "ID  Name                 B W Description\n")
78           (insert "--  ----                 - - -----------\n")
79           (while l
80             (setq charset (car l) l (cdr l))
81             (insert (format "%03d %s" (charset-id charset) charset))
82             (indent-to 28)
83             (insert (format "%d %d %s\n"
84                             (charset-bytes charset)
85                             (charset-width charset)
86                             (charset-description charset)))))
87       (insert "\
88 #########################
89 ## LIST OF CHARSETS
90 ## Each line corresponds to one charset.
91 ## The following attributes are listed in this order
92 ## separated by a colon `:' in one line.
93 ##      CHARSET-ID,
94 ##      CHARSET-SYMBOL-NAME,
95 ##      DIMENSION (1 or 2)
96 ##      CHARS (94 or 96)
97 ##      BYTES (of multibyte form: 1, 2, 3, or 4),
98 ##      WIDTH (occupied column numbers: 1 or 2),
99 ##      DIRECTION (0:left-to-right, 1:right-to-left),
100 ##      ISO-FINAL-CHAR (character code of ISO-2022's final character)
101 ##      ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR)
102 ##      DESCRIPTION (describing string of the charset)
103 ")
104       (while l
105         (setq charset (car l) l (cdr l))
106         (princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n" 
107                        (charset-id charset)
108                        charset
109                        (charset-dimension charset)
110                        (charset-chars charset)
111                        (charset-bytes charset)
112                        (charset-width charset)
113                        (charset-direction charset)
114                        (charset-iso-final-char charset)
115                        (charset-iso-graphic-plane charset)
116                        (charset-description charset)))))))
117 \f
118 ;;; CODING-SYSTEM
119
120 (defun describe-designation (cs register)
121   (let ((charset
122          (coding-system-property
123           cs (intern (format "charset-g%d" register))))
124         (force
125          (coding-system-property
126           cs (intern (format "force-g%d-on-output" register)))))
127     (princ
128      (format
129       "  G%d: %s%s\n"
130       register
131       (cond ((null charset) "never used")
132             ((eq t charset) "none")
133             (t (charset-name charset)))
134       (if force " (explicit designation required)" "")))))
135
136 ;;;###autoload
137 (defun describe-coding-system (coding-system)
138   "Display information about CODING-SYSTEM."
139   (interactive "zDescribe coding system (default, current choices): ")
140   (if (or (null coding-system)
141           (string= (symbol-name coding-system) ""))
142       (describe-current-coding-system)
143     (with-output-to-temp-buffer "*Help*"
144       (print-coding-system-briefly coding-system 'doc-string)
145       (let ((type (coding-system-type coding-system)))
146         (princ (format "Type: %s" type))
147         (when (eq type 'iso2022)
148           (princ " (variant of ISO-2022)\n")
149           (princ "Initial designations:\n")
150           ;;(print-designation flags)
151           (describe-designation coding-system 0)
152           (describe-designation coding-system 1)
153           (describe-designation coding-system 2)
154           (describe-designation coding-system 3)
155           (princ "Other Form: \n  ")
156           (princ (if (coding-system-short coding-system)
157                      "short-form"
158                    "long-form"))
159           (if (coding-system-no-ascii-eol coding-system)
160               (princ ", ASCII@EOL"))
161           (if (coding-system-no-ascii-cntl coding-system)
162               (princ ", ASCII@CNTL"))
163           (princ (if (coding-system-seven coding-system)
164                      ", 7-bit"
165                    ", 8-bit"))
166           (if (coding-system-lock-shift coding-system)
167               (princ ", use-locking-shift")
168             (princ ", use-single-shift"))
169           ;; (if (aref flags 10) (princ ", use-roman"))
170           ;; (if (aref flags 11) (princ ", use-old-jis"))
171           (if (coding-system-no-iso6429 coding-system)
172               (princ ", no-ISO6429"))
173           ;; (if (aref flags 13) (princ ", init-bol"))
174           ;; (if (aref flags 14) (princ ", designation-bol"))
175           ;; (if (aref flags 15) (princ ", convert-unsafe"))
176           ;; (if (aref flags 16) (princ ", accept-latin-extra-code"))
177           )
178         (princ "\nEOL type:")
179         (let ((eol-type (coding-system-eol-type coding-system)))
180           (cond ((null eol-type)
181                  (princ "\n  Automatic selection from\n    ")
182                  (princ (format "%s-unix, %s-dos or %s-mac.\n"
183                                 coding-system coding-system coding-system))
184                  )
185                 ((symbolp eol-type)
186                  (princ " ")
187                  (princ eol-type))
188                 (t (princ "invalid\n")))))
189       (let ((postread (coding-system-get coding-system 'post-read-conversion)))
190         (when postread
191           (princ "After decoding a text normally,")
192           (princ " perform post-conversion by the function: ")
193           (princ "\n  ")
194           (princ postread)
195           (princ "\n")))
196       (let ((prewrite (coding-system-get coding-system 'pre-write-conversion)))
197         (when prewrite
198           (princ "Before encoding a text normally,")
199           (princ " perform pre-conversion by the function: ")
200           (princ "\n  ")
201           (princ prewrite)
202           (princ "\n")))
203       (let ((charsets (coding-system-get coding-system 'safe-charsets)))
204         (when charsets
205           (if (eq charsets t)
206               (princ "This coding system can encode all charsets.\n")
207             (princ "This coding system encode the following charsets:\n")
208             (princ " ")
209             (while charsets
210               (princ " ")
211               (princ (car charsets))
212               (setq charsets (cdr charsets))))))
213       (save-excursion
214         (set-buffer standard-output)
215         (help-mode)))))
216
217 ;;;###autoload
218 (defun describe-current-coding-system-briefly ()
219   "Display coding systems currently used in a brief format in echo area.
220
221 The format is \"F[..],K[..],T[..], default F[..]\",
222 where mnemonics of the following coding systems come in this order
223 at the place of `..':
224   `buffer-file-coding-system` (of the current buffer)
225   eol-type of buffer-file-coding-system (of the current buffer)
226   Value returned by `keyboard-coding-system'
227   eol-type of (keyboard-coding-system)
228   Value returned by `terminal-coding-system.
229   eol-type of (terminal-coding-system)
230   `default-buffer-file-coding-system'
231   eol-type of default-buffer-file-coding-system"
232   (interactive)
233   (let* ((proc (get-buffer-process (current-buffer)))
234          (process-coding-systems (if proc (process-coding-system proc))))
235     (message
236      ;; "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]"
237      "F[%s%s],K[%s%s],T[%s%s], default F[%s%s]"
238      (coding-system-mnemonic buffer-file-coding-system)
239      (coding-system-eol-type-mnemonic buffer-file-coding-system)
240      (coding-system-mnemonic (keyboard-coding-system))
241      (coding-system-eol-type-mnemonic (keyboard-coding-system))
242      (coding-system-mnemonic (terminal-coding-system))
243      (coding-system-eol-type-mnemonic (terminal-coding-system))
244      ;; (coding-system-mnemonic (car process-coding-systems))
245      ;; (coding-system-eol-type-mnemonic (car process-coding-systems))
246      ;; (coding-system-mnemonic (cdr process-coding-systems))
247      ;; (coding-system-eol-type-mnemonic (cdr process-coding-systems))
248      (coding-system-mnemonic default-buffer-file-coding-system)
249      (coding-system-eol-type-mnemonic default-buffer-file-coding-system)
250      ;; (coding-system-mnemonic (car default-process-coding-system))
251      ;; (coding-system-eol-type-mnemonic (car default-process-coding-system))
252      ;; (coding-system-mnemonic (cdr default-process-coding-system))
253      ;; (coding-system-eol-type-mnemonic (cdr default-process-coding-system))
254      )))
255
256 ;; Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
257 (defun print-coding-system-briefly (coding-system &optional doc-string)
258   (if (not coding-system)
259       (princ "nil\n")
260     ;; In XEmacs, coding-system has own type.
261     (if (coding-system-p coding-system)
262         (setq coding-system (coding-system-name coding-system))
263       )
264     ;; In XEmacs, coding-system-mnemonic returns string.
265     (princ (format "%s -- %s"
266                    (coding-system-mnemonic coding-system)
267                    coding-system))
268     (let ((aliases (coding-system-get coding-system 'alias-coding-systems)))
269       (if (eq coding-system (car aliases))
270           (if (cdr aliases)
271               (princ (format " %S" (cons 'alias: (cdr aliases)))))
272         (if (memq coding-system aliases)
273             (princ (format " (alias of %s)" (car aliases))))))
274     (princ "\n")
275     (if (and doc-string
276              (setq doc-string (coding-system-doc-string coding-system)))
277         (princ (format "  %s\n" doc-string)))))
278
279 ;;;###autoload
280 (defun describe-current-coding-system ()
281   "Display coding systems currently used, in detail."
282   (interactive)
283   (with-output-to-temp-buffer "*Help*"
284     (let* ((proc (get-buffer-process (current-buffer)))
285            (process-coding-systems (if proc (process-coding-system proc))))
286       (princ "Coding system for saving this buffer:\n  ")
287       ;; local-variable-p of XEmacs requires 2 arguments.
288       (if (local-variable-p 'buffer-file-coding-system (current-buffer))
289           (print-coding-system-briefly buffer-file-coding-system)
290         (princ "Not set locally, use the default.\n"))
291       (princ "Default coding system (for new files):\n  ")
292       (print-coding-system-briefly default-buffer-file-coding-system)
293       (princ "Coding system for keyboard input:\n  ")
294       (print-coding-system-briefly (keyboard-coding-system))
295       (princ "Coding system for terminal output:\n  ")
296       (print-coding-system-briefly (terminal-coding-system))
297       (when (get-buffer-process (current-buffer))
298         (princ "Coding systems for process I/O:\n")
299         (princ "  encoding input to the process: ")
300         (print-coding-system-briefly (cdr process-coding-systems))
301         (princ "  decoding output from the process: ")
302         (print-coding-system-briefly (car process-coding-systems)))
303       ;;(princ "Defaults for subprocess I/O:\n")
304       ;;(princ "  decoding: ")
305       ;;(print-coding-system-briefly (car default-process-coding-system))
306       ;;(princ "  encoding: ")
307       ;;(print-coding-system-briefly (cdr default-process-coding-system))
308       )
309     (save-excursion
310       (set-buffer standard-output)
311
312       (princ
313        "\nPriority order for recognizing coding systems when reading files:\n")
314       (let ((l (coding-priority-list)) ; It is function in XEmacs.
315             (i 1)
316             (coding-list nil)
317             coding aliases)
318         (while l
319           (setq coding (coding-category-system (car l))) ; for XEmacs
320           ;; Do not list up the same coding system twice.
321           (when (and coding (not (memq coding coding-list)))
322             (setq coding-list (cons coding coding-list))
323             (princ (format "  %d. %s " i coding))
324             (setq aliases (coding-system-get coding 'alias-coding-systems))
325             (if (eq coding (car aliases))
326                 (if (cdr aliases)
327                     (princ (cons 'alias: (cdr aliases))))
328               (if (memq coding aliases)
329                   (princ (list 'alias 'of (car aliases)))))
330             (terpri)
331             (setq i (1+ i)))
332           (setq l (cdr l))))
333
334       (princ "\n  Other coding systems cannot be distinguished automatically
335   from these, and therefore cannot be recognized automatically
336   with the present coding system priorities.\n\n")
337
338       (let ((categories '(iso-7)) ; for XEmacs
339             ;; '(coding-category-iso-7 coding-category-iso-7-else))
340             coding-system codings)
341         (while categories
342           ;; for XEmacs
343           (setq coding-system (coding-category-system (car categories)))
344           (mapcar
345            (function
346             (lambda (x)
347               (if (and (not (eq x coding-system))
348                        (coding-system-get x 'no-initial-designation)
349                        (let ((flags (coding-system-flags x)))
350                          (not (or (aref flags 10) (aref flags 11)))))
351                   (setq codings (cons x codings)))))
352            (get (car categories) 'coding-systems))
353           (if codings
354               (let ((max-col (frame-width))
355                     pos)
356                 (princ (format "  The followings are decoded correctly but recognized as %s:\n   " coding-system))
357                 (while codings
358                   (setq pos (point))
359                   (insert (format " %s" (car codings)))
360                   (when (> (current-column) max-col)
361                     (goto-char pos)
362                     (insert "\n   ")
363                     (goto-char (point-max)))
364                   (setq codings (cdr codings)))
365                 (insert "\n\n")))
366           (setq categories (cdr categories))))
367
368       (princ "Particular coding systems specified for certain file names:\n")
369       (terpri)
370       (princ "  OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
371       (princ "  ---------\t--------------\t\t----------------\n")
372       (let ((func (lambda (operation alist)
373                     (princ "  ")
374                     (princ operation)
375                     (if (not alist)
376                         (princ "\tnothing specified\n")
377                       (while alist
378                         (indent-to 16)
379                         (prin1 (car (car alist)))
380                         (if (>= (current-column) 40)
381                             (newline))
382                         (indent-to 40)
383                         (princ (cdr (car alist)))
384                         (princ "\n")
385                         (setq alist (cdr alist)))))))
386         (funcall func "File I/O" file-coding-system-alist)
387         (funcall func "Process I/O" process-coding-system-alist)
388         (funcall func "Network I/O" network-coding-system-alist))
389       (help-mode))))
390
391 ;; Print detailed information on CODING-SYSTEM.
392 (defun print-coding-system (coding-system)
393   (princ coding-system)
394   ;; aliases for coding system are not supported in XEmacs 21.1.x
395   (if (and (functionp 'coding-system-alias-p) (coding-system-alias-p coding-system))
396       (princ (format " (alias of %s)\n" (coding-system-aliasee coding-system)))
397     (let ((type (coding-system-type coding-system))
398           (eol-type (coding-system-eol-type coding-system)))
399       (princ (format ";%s;%s;%s;"
400                      type
401                      (coding-system-mnemonic coding-system)
402                      (symbol-name eol-type)))
403       (let ((flags '()))
404         (cond ((eq type 'iso2022)               ; ISO-2022
405                ;; G0, G1, G2, G3
406                ;; probably this should be implemented with (defmacro)?
407                (mapcar*
408                 (lambda (GX charset force-charset)
409                   (let ((charset-name (coding-system-get coding-system (intern charset))))
410                     (if charset-name
411                         (let (flag)
412                            (if (coding-system-property coding-system (intern force-charset))
413                                (setq flag (concat GX ":[" (symbol-name charset-name) "]"))
414                              (setq flag (concat GX ":" (symbol-name charset-name))))
415                            (setq flags (append (list flag) flags))))))
416
417                 '("G0" "G1" "G2" "G3")
418                 '("charset-g0" "charset-g1" "charset-g2" "charset-g3")
419                 '("force-g0-on-output" "force-g1-on-output"
420                                       "force-g2-on-output" "force-g3-on-output"))
421
422                ;; various other flags
423              (if (coding-system-get coding-system 'short)
424                  (setq flags (append '("SHORT-FORM") flags)))
425
426              (unless (coding-system-get coding-system 'no-ascii-eol)
427                (setq flags (append '("ASCII-EOL") flags)))
428
429              (unless (coding-system-get coding-system 'no-ascii-cntl)
430                (setq flags (append '("ASCII-CNTL") flags)))
431
432              (if (coding-system-get coding-system 'seven)
433                  (setq flags (append '("SEVEN") flags)))
434
435              (if (coding-system-get coding-system 'lock-shift)
436                  (setq flags (append '("LOCKING-SHIFT") flags)))
437
438              (if (coding-system-get coding-system 'no-iso6429)
439                  (setq flags (append '("NO-ISO6429") flags))))
440
441             ((eq type 'ccl)             ; CCL
442              (princ (format "%s, %s"
443                             (coding-system-get coding-system 'encode)
444                             (coding-system-get coding-system 'decode) flags))))
445         (setq flags (reverse flags))
446         (if (car flags)
447             (progn
448               (princ (format "%s" (car flags)))
449               (mapc
450                (lambda (flag)
451                  (princ (format ", %s" flag)))
452                (cdr flags))))
453         ))
454       (princ ";")
455       (princ (coding-system-doc-string coding-system))
456       (princ "\n")))
457
458 ;;;###autoload
459 (defun list-coding-systems (&optional arg)
460   "Display a list of all coding systems.
461 This shows the mnemonic letter, name, and description of each coding system.
462
463 With prefix arg, the output format gets more cryptic,
464 but still contains full information about each coding system."
465   (interactive "P")
466   (with-displaying-help-buffer
467    (lambda ()
468      (with-current-buffer standard-output
469        (list-coding-systems-1 arg)))))
470
471
472 (defun list-coding-systems-1 (arg)
473   (if (null arg)
474       (princ "\
475 ###############################################
476 # List of coding systems in the following format:
477 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
478 #       DOC-STRING
479 ")
480     (princ "\
481 #########################
482 ## LIST OF CODING SYSTEMS
483 ## Each line corresponds to one coding system
484 ## Format of a line is:
485 ##   NAME[,ALIAS...];TYPE;MNEMONIC;EOL;FLAGS;POST-READ-CONVERSION
486 ##      ;PRE-WRITE-CONVERSION;DOC-STRING,
487 ## where
488 ##  NAME = coding system name
489 ##  ALIAS = alias of the coding system
490 ##  TYPE = nil (no conversion), t (undecided or automatic detection),
491 ##         0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
492 ##  EOL = lf (LF), crlf (CRLF), cr (CR), or nil (Automatic detection)
493 ##  FLAGS =
494 ##    if TYPE = 'ISO2022 then
495 ##      comma (`,') separated data of the followings:
496 ##        G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
497 ##        LOCKING-SHIFT, NO-ISO6429
498 ##    else if TYPE = 'CCL then
499 ##      comma (`,') separated CCL programs for read and write
500 ##    else
501 ##      0
502 ##  POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
503 ##
504 "))
505   (if (null arg)
506       ;; print only base coding systems (w/o "-dos", "-unix", "-mac")
507       (let ((bases (make-hash-table)))
508         ;; put base coding systems into hash-table
509         (mapc
510          (lambda (coding-system)
511            (let* ((base (coding-system-base coding-system))
512                   (base-name (coding-system-name base)))
513
514              (unless (gethash base-name bases)
515                  (puthash base-name base bases))))
516          (coding-system-list))
517
518         ;; traverse hash-table and print each coding system
519         (maphash 
520          (lambda (key value) (print-coding-system-briefly value 'doc-string))
521          bases))
522          
523     ;; print all coding systems in details
524     (mapc
525      '(lambda (coding-system)
526         (print-coding-system coding-system))
527      (coding-system-list))))
528
529 ;;;###autoload
530 (defun list-coding-categories ()
531   "Display a list of all coding categories."
532   (interactive)
533   (with-output-to-temp-buffer "*Help*"
534     (princ "\
535 ############################
536 ## LIST OF CODING CATEGORIES (ordered by priority)
537 ## CATEGORY:CODING-SYSTEM
538 ##
539 ")
540     (let ((l (coding-priority-list)))
541       (while l
542         (princ (format "%s:%s\n" (car l) (coding-category-system (car l))))
543         (setq l (cdr l))))))
544 \f
545 ;;; FONT
546
547 ;; Print information of a font in FONTINFO.
548 (defun describe-font-internal (font-info &optional verbose)
549   (print-list "name (opened by):" (aref font-info 0))
550   (print-list "       full name:" (aref font-info 1))
551   (let ((charset (aref font-info 2)))
552     (print-list "   charset:"
553                 (format "%s (%s)" charset (charset-description charset))))
554   (print-list "            size:" (format "%d" (aref font-info 3)))
555   (print-list "          height:" (format "%d" (aref font-info 4)))
556   (print-list " baseline-offset:" (format "%d" (aref font-info 5)))
557   (print-list "relative-compose:" (format "%d" (aref font-info 6))))
558
559 ;;;###autoload
560 (defun describe-font (fontname)
561   "Display information about fonts which partially match FONTNAME."
562   (interactive "sFontname (default, current choice for ASCII chars): ")
563   (or (and window-system (boundp 'global-fontset-alist))
564       (error "No fontsets being used"))
565   (when (or (not fontname) (= (length fontname) 0))
566     (setq fontname (cdr (assq 'font (frame-parameters))))
567     (if (query-fontset fontname)
568         (setq fontname
569               (nth 2 (assq 'ascii (aref (fontset-info fontname) 2))))))
570   (let ((font-info (font-info fontname)))
571     (if (null font-info)
572         (message "No matching font")
573       (with-output-to-temp-buffer "*Help*"
574         (describe-font-internal font-info 'verbose)))))
575
576 ;; Print information of FONTSET.  If optional arg PRINT-FONTS is
577 ;; non-nil, print also names of all fonts in FONTSET.  This function
578 ;; actually INSERT such information in the current buffer.
579 (defun print-fontset (fontset &optional print-fonts)
580   (let* ((fontset-info (fontset-info fontset))
581          (size (aref fontset-info 0))
582          (height (aref fontset-info 1))
583          (fonts (and print-fonts (aref fontset-info 2)))
584          (xlfd-fields (x-decompose-font-name fontset))
585          style)
586     (if xlfd-fields
587         (let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum))
588               (slant  (aref xlfd-fields xlfd-regexp-slant-subnum)))
589           (if (string-match "^bold$\\|^demibold$" weight)
590               (setq style (concat weight " "))
591             (setq style "medium "))
592           (cond ((string-match "^i$" slant)
593                  (setq style (concat style "italic")))
594                 ((string-match "^o$" slant)
595                  (setq style (concat style "slant")))
596                 ((string-match "^ri$" slant)
597                  (setq style (concat style "reverse italic")))
598                 ((string-match "^ro$" slant)
599                  (setq style (concat style "reverse slant")))))
600       (setq style " ? "))
601     (beginning-of-line)
602     (insert fontset)
603     (indent-to 58)
604     (insert (if (> size 0) (format "%2dx%d" size height) "  -"))
605     (indent-to 64)
606     (insert style "\n")
607     (when print-fonts
608       (insert "  O Charset / Fontname\n"
609               "  - ------------------\n")
610       (sort-charset-list)
611       (let ((l charset-list)
612             charset font-info opened fontname)
613         (while l
614           (setq charset (car l) l (cdr l))
615           (setq font-info (assq charset fonts))
616           (if (null font-info)
617               (setq opened ?? fontname "not specified")
618             (if (nth 2 font-info)
619                 (if (stringp (nth 2 font-info))
620                     (setq opened ?o fontname (nth 2 font-info))
621                   (setq opened ?- fontname (nth 1 font-info)))
622               (setq opened ?x fontname (nth 1 font-info))))
623           (insert (format "  %c %s\n    %s\n"
624                           opened charset fontname)))))))
625
626 ;;;###autoload
627 (defun describe-fontset (fontset)
628   "Display information of FONTSET.
629 This shows the name, size, and style of FONTSET, and the list of fonts
630 contained in FONTSET.
631
632 The column WDxHT contains width and height (pixels) of each fontset
633 \(i.e. those of ASCII font in the fontset).  The letter `-' in this
634 column means that the corresponding fontset is not yet used in any
635 frame.
636
637 The O column for each font contains one of the following letters:
638  o -- font already opened
639  - -- font not yet opened
640  x -- font can't be opened
641  ? -- no font specified
642
643 The Charset column for each font contains a name of character set
644 displayed (for this fontset) using that font."
645   (interactive
646    (if (not (and window-system (boundp 'global-fontset-alist)))
647        (error "No fontsets being used")
648      (let ((fontset-list (mapcar '(lambda (x) (list x)) (fontset-list)))
649            (completion-ignore-case t))
650        (list (completing-read
651               "Fontset (default, used by the current frame): "
652               fontset-list nil t)))))
653   (if (= (length fontset) 0)
654       (setq fontset (cdr (assq 'font (frame-parameters)))))
655   (if (not (query-fontset fontset))
656       (error "Current frame is using font, not fontset"))
657   (let ((fontset-info (fontset-info fontset)))
658     (with-output-to-temp-buffer "*Help*"
659       (save-excursion
660         (set-buffer standard-output)
661         (insert "Fontset-Name\t\t\t\t\t\t  WDxHT Style\n")
662         (insert "------------\t\t\t\t\t\t  ----- -----\n")
663         (print-fontset fontset t)))))
664
665 ;;;###autoload
666 (defun list-fontsets (arg)
667   "Display a list of all fontsets.
668 This shows the name, size, and style of each fontset.
669 With prefix arg, it also list the fonts contained in each fontset;
670 see the function `describe-fontset' for the format of the list."
671   (interactive "P")
672   (if (not (and window-system (boundp 'global-fontset-alist)))
673       (error "No fontsets being used")
674     (with-output-to-temp-buffer "*Help*"
675       (save-excursion
676         ;; This code is duplicated near the end of mule-diag.
677         (set-buffer standard-output)
678         (insert "Fontset-Name\t\t\t\t\t\t  WDxHT Style\n")
679         (insert "------------\t\t\t\t\t\t  ----- -----\n")
680         (let ((fontsets
681                (sort (fontset-list)
682                      (function (lambda (x y)
683                                  (string< (fontset-plain-name x)
684                                           (fontset-plain-name y)))))))
685           (while fontsets
686             (print-fontset (car fontsets) arg)
687             (setq fontsets (cdr fontsets))))))))
688 \f
689 ;;;###autoload
690 (defun list-input-methods ()
691   "Display information about all input methods."
692   (interactive)
693   (with-displaying-help-buffer
694    (lambda ()
695      (with-current-buffer standard-output
696        (list-input-methods-1)))))
697
698
699 (defun list-input-methods-1 ()
700   (if (not input-method-alist)
701       (progn
702         (princ "
703 No input method is available, perhaps because you have not yet
704 installed LEIM (Libraries of Emacs Input Method).
705
706 LEIM is available from the same ftp directory as Emacs.  For instance,
707 if there exists an archive file `emacs-20.N.tar.gz', there should also
708 be a file `leim-20.N.tar.gz'.  When you extract this file, LEIM files
709 are put under the subdirectory `emacs-20.N/leim'.  When you install
710 Emacs again, you should be able to use various input methods."))
711     (princ "LANGUAGE\n  NAME (`TITLE' in mode line)\n")
712     (princ "    SHORT-DESCRIPTION\n------------------------------\n")
713     (setq input-method-alist
714           (sort input-method-alist
715                 (function (lambda (x y) (string< (nth 1 x) (nth 1 y))))))
716     (let ((l input-method-alist)
717           language elt)
718       (while l
719         (setq elt (car l) l (cdr l))
720         (when (not (equal language (nth 1 elt)))
721           (setq language (nth 1 elt))
722           (princ language)
723           (terpri))
724         (princ (format "  %s (`%s' in mode line)\n    %s\n"
725                        (car elt)
726                        (let ((title (nth 3 elt)))
727                          (if (and (consp title) (stringp (car title)))
728                              (car title)
729                            title))
730                        (let ((description (nth 4 elt)))
731                          (string-match ".*" description)
732                          (match-string 0 description))))))))
733 \f
734 ;;; DIAGNOSIS
735
736 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
737 (defun insert-section (section-number title)
738   (insert "########################################\n"
739           "# Section " (format "%d" section-number) ".  " title "\n"
740           "########################################\n\n"))
741
742 ;;;###autoload
743 (defun mule-diag ()
744   "Display diagnosis of the multilingual environment (Mule).
745
746 This shows various information related to the current multilingual
747 environment, including lists of input methods, coding systems,
748 character sets, and fontsets (if Emacs is running under a window
749 system which uses fontsets)."
750   (interactive)
751   (with-output-to-temp-buffer "*Mule-Diagnosis*"
752     (save-excursion
753       (set-buffer standard-output)
754       (insert "###############################################\n"
755               "### Current Status of Multilingual Features ###\n"
756               "###############################################\n\n"
757               "CONTENTS: Section 1.  General Information\n"
758               "          Section 2.  Display\n"
759               "          Section 3.  Input methods\n"
760               "          Section 4.  Coding systems\n"
761               "          Section 5.  Character sets\n")
762       (if (and window-system (boundp 'global-fontset-alist))
763           (insert "          Section 6.  Fontsets\n"))
764       (insert "\n")
765
766       (insert-section 1 "General Information")
767       (insert "Version of this emacs:\n  " (emacs-version) "\n\n")
768
769       (insert-section 2 "Display")
770       (if window-system
771           (insert "Window-system: "
772                   (symbol-name window-system)
773                   (format "%s" window-system-version))
774         (insert "Terminal: " (getenv "TERM")))
775       (insert "\n\n")
776
777       (if (eq window-system 'x)
778           (let ((font (cdr (assq 'font (frame-parameters)))))
779             (insert "The selected frame is using the "
780                     (if (query-fontset font) "fontset" "font")
781                     ":\n\t" font))
782         (insert "Coding system of the terminal: "
783                 (symbol-name (terminal-coding-system))))
784       (insert "\n\n")
785
786       (insert-section 3 "Input methods")
787       (list-input-methods-1)
788       (insert "\n")
789       (if default-input-method
790           (insert "Default input method: " default-input-method "\n")
791         (insert "No default input method is specified\n"))
792
793       (insert-section 4 "Coding systems")
794       (list-coding-systems-1 t)
795       (princ "\
796 ############################
797 ## LIST OF CODING CATEGORIES (ordered by priority)
798 ## CATEGORY:CODING-SYSTEM
799 ##
800 ")
801       (let ((l (coding-priority-list)))
802         (while l
803           (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
804           (setq l (cdr l))))
805       (insert "\n")
806
807       (insert-section 5 "Character sets")
808       (list-character-sets-1 t)
809       (insert "\n")
810
811       (when (and window-system (boundp 'global-fontset-alist))
812         ;; This code duplicates most of list-fontsets.
813         (insert-section 6 "Fontsets")
814         (insert "Fontset-Name\t\t\t\t\t\t  WDxHT Style\n")
815         (insert "------------\t\t\t\t\t\t  ----- -----\n")
816         (let ((fontsets (fontset-list)))
817           (while fontsets
818             (print-fontset (car fontsets) t)
819             (setq fontsets (cdr fontsets)))))
820       (print-help-return-message))))
821
822 \f
823 ;;; DUMP DATA FILE
824
825 ;;;###autoload
826 (defun dump-charsets ()
827   "Dump information about all charsets into the file `CHARSETS'.
828 The file is saved in the directory `data-directory'."
829   (let ((file (expand-file-name "CHARSETS" data-directory))
830         buf)
831     (or (file-writable-p file)
832         (error "Can't write to file %s" file))
833     (setq buf (find-file-noselect file))
834     (save-window-excursion
835       (save-excursion
836         (set-buffer buf)
837         (setq buffer-read-only nil)
838         (erase-buffer)
839         (list-character-sets t)
840         (insert-buffer-substring "*Help*")
841         (let (make-backup-files
842               coding-system-for-write)
843           (save-buffer))))
844     (kill-buffer buf))
845   (if noninteractive
846       (kill-emacs)))
847
848 ;;;###autoload
849 (defun dump-codings ()
850   "Dump information about all coding systems into the file `CODINGS'.
851 The file is saved in the directory `data-directory'."
852   (let ((file (expand-file-name "CODINGS" data-directory))
853         buf)
854     (or (file-writable-p file)
855         (error "Can't write to file %s" file))
856     (setq buf (find-file-noselect file))
857     (save-window-excursion
858       (save-excursion
859         (set-buffer buf)
860         (setq buffer-read-only nil)
861         (erase-buffer)
862         (list-coding-systems t)
863         (insert-buffer-substring "*Help*")
864         (list-coding-categories)
865         (insert-buffer-substring "*Help*")
866         (let (make-backup-files
867               coding-system-for-write)
868           (save-buffer))))
869     (kill-buffer buf))
870   (if noninteractive
871       (kill-emacs)))
872
873 ;;; mule-diag.el ends here