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