cc-langs.el (c-nonlabel-token-key): Allow quoted character constants (as
[emacs.git] / lisp / international / mule-diag.el
blob8417a7c11426ffbd85515b656ed59621aacd7d66
1 ;;; mule-diag.el --- show diagnosis of multilingual environment (Mule)
3 ;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
4 ;; 2007, 2008, 2009 Free Software Foundation, Inc.
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
6 ;; 2005, 2006, 2007, 2008, 2009
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H14PRO021
9 ;; Copyright (C) 2003
10 ;; National Institute of Advanced Industrial Science and Technology (AIST)
11 ;; Registration Number H13PRO009
13 ;; Keywords: multilingual, charset, coding system, fontset, diagnosis, i18n
15 ;; This file is part of GNU Emacs.
17 ;; GNU Emacs is free software: you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
19 ;; the Free Software Foundation, either version 3 of the License, or
20 ;; (at your option) any later version.
22 ;; GNU Emacs is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 ;;; Commentary:
32 ;;; Code:
34 ;; Make sure the help-xref button type is defined.
35 (require 'help-fns)
37 ;;; General utility function
39 (defun print-list (&rest args)
40 "Print all arguments with single space separator in one line."
41 (princ (mapconcat (lambda (arg) (prin1-to-string arg t)) args " "))
42 (princ "\n"))
44 ;;; CHARSET
46 (define-button-type 'sort-listed-character-sets
47 'help-echo (purecopy "mouse-2, RET: sort on this column")
48 'face 'bold
49 'action #'(lambda (button)
50 (sort-listed-character-sets (button-get button 'sort-key))))
52 (define-button-type 'list-charset-chars
53 :supertype 'help-xref
54 'help-function #'list-charset-chars
55 'help-echo "mouse-2, RET: show table of characters for this character set")
57 ;;;###autoload
58 (defun list-character-sets (arg)
59 "Display a list of all character sets.
61 The D column contains the dimension of this character set. The CH
62 column contains the number of characters in a block of this character
63 set. The FINAL-BYTE column contains an ISO-2022 <final-byte> to use
64 in the designation escape sequence for this character set in
65 ISO-2022-based coding systems.
67 With prefix ARG, the output format gets more cryptic,
68 but still shows the full information."
69 (interactive "P")
70 (help-setup-xref (list #'list-character-sets arg) (interactive-p))
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 another charset or obsolete now
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 (decode-char (intern (format "cp%d" codepage)) code))
212 (make-obsolete 'decode-codepage-char 'decode-char "23.1")
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) (interactive-p))
318 (with-output-to-temp-buffer (help-buffer)
319 (with-current-buffer standard-output
320 (insert "Character set: " (symbol-name charset))
321 (let ((name (get-charset-property charset :name)))
322 (if (not (eq name charset))
323 (insert " (alias of " (symbol-name name) ?\))))
324 (insert "\n\n" (charset-description charset) "\n\n")
325 (insert "Number of contained characters: ")
326 (dotimes (i (charset-dimension charset))
327 (unless (= i 0)
328 (insert ?x))
329 (insert (format "%d" (charset-chars charset (1+ i)))))
330 (insert ?\n)
331 (let ((char (charset-iso-final-char charset)))
332 (when (> char 0)
333 (insert "Final char of ISO2022 designation sequence: ")
334 (insert (format "`%c'\n" char))))
335 (let (aliases)
336 (dolist (c charset-list)
337 (if (and (not (eq c charset))
338 (eq charset (get-charset-property c :name)))
339 (push c aliases)))
340 (if aliases
341 (insert "Aliases: " (mapconcat #'symbol-name aliases ", ") ?\n)))
343 (dolist (elt `((:ascii-compatible-p "ASCII compatible." nil)
344 (:map "Map file: " identity)
345 (:unify-map "Unification map file: " identity)
346 (:invalid-code
348 ,(lambda (c)
349 (format "Invalid character: %c (code %d)" c c)))
350 (:emacs-mule-id "Id in emacs-mule coding system: "
351 number-to-string)
352 (:parents "Parents: "
353 (lambda (parents)
354 (mapconcat ,(lambda (elt)
355 (format "%s" elt))
356 parents
357 ", ")))
358 (:code-space "Code space: " ,(lambda (c)
359 (format "%s" c)))
360 (:code-offset "Code offset: " number-to-string)
361 (:iso-revision-number "ISO revision number: "
362 number-to-string)
363 (:supplementary-p
364 "Used only as a parent of some other charset." nil)))
365 (let ((val (get-charset-property charset (car elt))))
366 (when val
367 (if (cadr elt) (insert (cadr elt)))
368 (if (nth 2 elt)
369 (insert (funcall (nth 2 elt) val)))
370 (insert ?\n)))))))
372 ;;; CODING-SYSTEM
374 (defvar graphic-register) ; dynamic bondage
376 ;; Print information about designation of each graphic register in
377 ;; DESIGNATIONS in human readable format. See the documentation of
378 ;; `define-coding-system' for the meaning of DESIGNATIONS
379 ;; (`:designation' property).
380 (defun print-designation (designations)
381 (let (charset)
382 (dotimes (graphic-register 4)
383 (setq charset (aref designations graphic-register))
384 (princ (format
385 " G%d -- %s\n"
386 graphic-register
387 (cond ((null charset)
388 "never used")
389 ((eq charset t)
390 "no initial designation, and used by any charsets")
391 ((symbolp charset)
392 (format "%s:%s"
393 charset (charset-description charset)))
394 ((listp charset)
395 (if (charsetp (car charset))
396 (format "%s:%s, and also used by the following:"
397 (car charset)
398 (charset-description (car charset)))
399 "no initial designation, and used by the following:"))
401 "invalid designation information"))))
402 (when (listp charset)
403 (setq charset (cdr charset))
404 (while charset
405 (cond ((eq (car charset) t)
406 (princ "\tany other charsets\n"))
407 ((charsetp (car charset))
408 (princ (format "\t%s:%s\n"
409 (car charset)
410 (charset-description (car charset)))))
412 "invalid designation information"))
413 (setq charset (cdr charset)))))))
415 ;;;###autoload
416 (defun describe-coding-system (coding-system)
417 "Display information about CODING-SYSTEM."
418 (interactive "zDescribe coding system (default current choices): ")
419 (if (null coding-system)
420 (describe-current-coding-system)
421 (help-setup-xref (list #'describe-coding-system coding-system)
422 (interactive-p))
423 (with-output-to-temp-buffer (help-buffer)
424 (print-coding-system-briefly coding-system 'doc-string)
425 (let ((type (coding-system-type coding-system))
426 ;; Fixme: use this
427 (extra-spec (coding-system-plist coding-system)))
428 (princ "Type: ")
429 (princ type)
430 (cond ((eq type 'undecided)
431 (princ " (do automatic conversion)"))
432 ((eq type 'utf-8)
433 (princ " (UTF-8: Emacs internal multibyte form)"))
434 ((eq type 'utf-16)
435 ;; (princ " (UTF-16)")
437 ((eq type 'shift-jis)
438 (princ " (Shift-JIS, MS-KANJI)"))
439 ((eq type 'iso-2022)
440 (princ " (variant of ISO-2022)\n")
441 (princ "Initial designations:\n")
442 (print-designation (coding-system-get coding-system
443 :designation))
445 (when (coding-system-get coding-system :flags)
446 (princ "Other specifications: \n ")
447 (apply #'print-list
448 (coding-system-get coding-system :flags))))
449 ((eq type 'charset)
450 (princ " (charset)"))
451 ((eq type 'ccl)
452 (princ " (do conversion by CCL program)"))
453 ((eq type 'raw-text)
454 (princ " (text with random binary characters)"))
455 ((eq type 'emacs-mule)
456 (princ " (Emacs 21 internal encoding)"))
457 ((eq type 'big5))
458 (t (princ ": invalid coding-system.")))
459 (princ "\nEOL type: ")
460 (let ((eol-type (coding-system-eol-type coding-system)))
461 (cond ((vectorp eol-type)
462 (princ "Automatic selection from:\n\t")
463 (princ eol-type)
464 (princ "\n"))
465 ((or (null eol-type) (eq eol-type 0)) (princ "LF\n"))
466 ((eq eol-type 1) (princ "CRLF\n"))
467 ((eq eol-type 2) (princ "CR\n"))
468 (t (princ "invalid\n")))))
469 (let ((postread (coding-system-get coding-system :post-read-conversion)))
470 (when postread
471 (princ "After decoding text normally,")
472 (princ " perform post-conversion using the function: ")
473 (princ "\n ")
474 (princ postread)
475 (princ "\n")))
476 (let ((prewrite (coding-system-get coding-system :pre-write-conversion)))
477 (when prewrite
478 (princ "Before encoding text normally,")
479 (princ " perform pre-conversion using the function: ")
480 (princ "\n ")
481 (princ prewrite)
482 (princ "\n")))
483 (with-current-buffer standard-output
484 (let ((charsets (coding-system-charset-list coding-system)))
485 (when (and (not (eq (coding-system-base coding-system) 'raw-text))
486 charsets)
487 (cond
488 ((eq charsets 'iso-2022)
489 (insert "This coding system can encode all ISO 2022 charsets."))
490 ((eq charsets 'emacs-mule)
491 (insert "This coding system can encode all emacs-mule charsets\
492 ."""))
494 (insert "This coding system encodes the following charsets:\n ")
495 (while charsets
496 (insert " " (symbol-name (car charsets)))
497 (search-backward (symbol-name (car charsets)))
498 (help-xref-button 0 'help-character-set (car charsets))
499 (goto-char (point-max))
500 (setq charsets (cdr charsets)))))))))))
502 ;;;###autoload
503 (defun describe-current-coding-system-briefly ()
504 "Display coding systems currently used in a brief format in echo area.
506 The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
507 where mnemonics of the following coding systems come in this order
508 in place of `..':
509 `buffer-file-coding-system' (of the current buffer)
510 eol-type of `buffer-file-coding-system' (of the current buffer)
511 Value returned by `keyboard-coding-system'
512 eol-type of `keyboard-coding-system'
513 Value returned by `terminal-coding-system'.
514 eol-type of `terminal-coding-system'
515 `process-coding-system' for read (of the current buffer, if any)
516 eol-type of `process-coding-system' for read (of the current buffer, if any)
517 `process-coding-system' for write (of the current buffer, if any)
518 eol-type of `process-coding-system' for write (of the current buffer, if any)
519 default `buffer-file-coding-system'
520 eol-type of default `buffer-file-coding-system'
521 `default-process-coding-system' for read
522 eol-type of `default-process-coding-system' for read
523 `default-process-coding-system' for write
524 eol-type of `default-process-coding-system'"
525 (interactive)
526 (let* ((proc (get-buffer-process (current-buffer)))
527 (process-coding-systems (if proc (process-coding-system proc))))
528 (message
529 "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]"
530 (coding-system-mnemonic buffer-file-coding-system)
531 (coding-system-eol-type-mnemonic buffer-file-coding-system)
532 (coding-system-mnemonic (keyboard-coding-system))
533 (coding-system-eol-type-mnemonic (keyboard-coding-system))
534 (coding-system-mnemonic (terminal-coding-system))
535 (coding-system-eol-type-mnemonic (terminal-coding-system))
536 (coding-system-mnemonic (car process-coding-systems))
537 (coding-system-eol-type-mnemonic (car process-coding-systems))
538 (coding-system-mnemonic (cdr process-coding-systems))
539 (coding-system-eol-type-mnemonic (cdr process-coding-systems))
540 (coding-system-mnemonic (default-value 'buffer-file-coding-system))
541 (coding-system-eol-type-mnemonic
542 (default-value 'buffer-file-coding-system))
543 (coding-system-mnemonic (car default-process-coding-system))
544 (coding-system-eol-type-mnemonic (car default-process-coding-system))
545 (coding-system-mnemonic (cdr default-process-coding-system))
546 (coding-system-eol-type-mnemonic (cdr default-process-coding-system))
549 (defun print-coding-system-briefly (coding-system &optional doc-string)
550 "Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
551 If DOC-STRING is non-nil, print also the docstring of CODING-SYSTEM.
552 If DOC-STRING is `tightly', don't print an empty line before the
553 docstring, and print only the first line of the docstring."
554 (if (not coding-system)
555 (princ "nil\n")
556 (princ (format "%c -- %s"
557 (coding-system-mnemonic coding-system)
558 coding-system))
559 (let ((aliases (coding-system-aliases coding-system)))
560 (cond ((eq coding-system (car aliases))
561 (if (cdr aliases)
562 (princ (format " %S" (cons 'alias: (cdr aliases))))))
563 ((memq coding-system aliases)
564 (princ (format " (alias of %s)" (car aliases))))
566 (let ((eol-type (coding-system-eol-type coding-system))
567 (base-eol-type (coding-system-eol-type (car aliases))))
568 (if (and (integerp eol-type)
569 (vectorp base-eol-type)
570 (not (eq coding-system (aref base-eol-type eol-type))))
571 (princ (format " (alias of %s)"
572 (aref base-eol-type eol-type))))))))
573 (princ "\n")
574 (or (eq doc-string 'tightly)
575 (princ "\n"))
576 (if doc-string
577 (let ((doc (or (coding-system-doc-string coding-system) "")))
578 (when (eq doc-string 'tightly)
579 (if (string-match "\n" doc)
580 (setq doc (substring doc 0 (match-beginning 0))))
581 (setq doc (concat " " doc)))
582 (princ (format "%s\n" doc))))))
584 ;;;###autoload
585 (defun describe-current-coding-system ()
586 "Display coding systems currently used, in detail."
587 (interactive)
588 (with-output-to-temp-buffer "*Help*"
589 (let* ((proc (get-buffer-process (current-buffer)))
590 (process-coding-systems (if proc (process-coding-system proc))))
591 (princ "Coding system for saving this buffer:\n ")
592 (if (local-variable-p 'buffer-file-coding-system)
593 (print-coding-system-briefly buffer-file-coding-system)
594 (princ "Not set locally, use the default.\n"))
595 (princ "Default coding system (for new files):\n ")
596 (print-coding-system-briefly (default-value 'buffer-file-coding-system))
597 (princ "Coding system for keyboard input:\n ")
598 (print-coding-system-briefly (keyboard-coding-system))
599 (princ "Coding system for terminal output:\n ")
600 (print-coding-system-briefly (terminal-coding-system))
601 (when (boundp 'selection-coding-system)
602 (princ "Coding system for inter-client cut and paste:\n ")
603 (print-coding-system-briefly selection-coding-system))
604 (when (get-buffer-process (current-buffer))
605 (princ "Coding systems for process I/O:\n")
606 (princ " encoding input to the process: ")
607 (print-coding-system-briefly (cdr process-coding-systems))
608 (princ " decoding output from the process: ")
609 (print-coding-system-briefly (car process-coding-systems)))
610 (princ "Defaults for subprocess I/O:\n")
611 (princ " decoding: ")
612 (print-coding-system-briefly (car default-process-coding-system))
613 (princ " encoding: ")
614 (print-coding-system-briefly (cdr default-process-coding-system)))
616 (with-current-buffer standard-output
618 (princ "
619 Priority order for recognizing coding systems when reading files:\n")
620 (let ((i 1))
621 (dolist (elt (coding-system-priority-list))
622 (princ (format " %d. %s " i elt))
623 (let ((aliases (coding-system-aliases elt)))
624 (if (eq elt (car aliases))
625 (if (cdr aliases)
626 (princ (cons 'alias: (cdr aliases))))
627 (princ (list 'alias 'of (car aliases))))
628 (terpri)
629 (setq i (1+ i)))))
631 (princ "\n Other coding systems cannot be distinguished automatically
632 from these, and therefore cannot be recognized automatically
633 with the present coding system priorities.\n\n")
635 ;; Fixme: should this be replaced or junked?
636 (if nil
637 (let ((categories '(coding-category-iso-7 coding-category-iso-7-else))
638 coding-system codings)
639 (while categories
640 (setq coding-system (symbol-value (car categories)))
641 (mapc
642 (lambda (x)
643 (if (and (not (eq x coding-system))
644 (let ((flags (coding-system-get :flags)))
645 (not (or (memq 'use-roman flags)
646 (memq 'use-oldjis flags)))))
647 (setq codings (cons x codings))))
648 (get (car categories) 'coding-systems))
649 (if codings
650 (let ((max-col (window-width))
651 pos)
652 (princ (format "\
653 The following are decoded correctly but recognized as %s:\n "
654 coding-system))
655 (while codings
656 (setq pos (point))
657 (insert (format " %s" (car codings)))
658 (when (> (current-column) max-col)
659 (goto-char pos)
660 (insert "\n ")
661 (goto-char (point-max)))
662 (setq codings (cdr codings)))
663 (insert "\n\n")))
664 (setq categories (cdr categories)))))
666 (princ "Particular coding systems specified for certain file names:\n")
667 (terpri)
668 (princ " OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
669 (princ " ---------\t--------------\t\t----------------\n")
670 (let ((func (lambda (operation alist)
671 (princ " ")
672 (princ operation)
673 (if (not alist)
674 (princ "\tnothing specified\n")
675 (while alist
676 (indent-to 16)
677 (prin1 (car (car alist)))
678 (if (>= (current-column) 40)
679 (newline))
680 (indent-to 40)
681 (princ (cdr (car alist)))
682 (princ "\n")
683 (setq alist (cdr alist)))))))
684 (funcall func "File I/O" file-coding-system-alist)
685 (funcall func "Process I/O" process-coding-system-alist)
686 (funcall func "Network I/O" network-coding-system-alist))
687 (help-mode))))
689 (defun print-coding-system (coding-system)
690 "Print detailed information on CODING-SYSTEM."
691 (let ((type (coding-system-type coding-system))
692 (eol-type (coding-system-eol-type coding-system))
693 (flags (coding-system-get coding-system :flags))
694 (aliases (coding-system-aliases coding-system)))
695 (if (not (eq (car aliases) coding-system))
696 (princ (format "%s (alias of %s)\n" coding-system (car aliases)))
697 (princ coding-system)
698 (dolist (alias (cdr aliases))
699 (princ ",")
700 (princ alias))
701 (princ (format ":%s:%c:%d:"
702 type
703 (coding-system-mnemonic coding-system)
704 (if (integerp eol-type) eol-type 3)))
705 (cond ((eq type 'iso2022)
706 (let ((idx 0)
707 charset)
708 (while (< idx 4)
709 (setq charset (aref flags idx))
710 (cond ((null charset)
711 (princ -1))
712 ((eq charset t)
713 (princ -2))
714 ((charsetp charset)
715 (princ charset))
716 ((listp charset)
717 (princ "(")
718 (princ (car charset))
719 (setq charset (cdr charset))
720 (while charset
721 (princ ",")
722 (princ (car charset))
723 (setq charset (cdr charset)))
724 (princ ")")))
725 (princ ",")
726 (setq idx (1+ idx)))
727 (while (< idx 12)
728 (princ (if (aref flags idx) 1 0))
729 (princ ",")
730 (setq idx (1+ idx)))
731 (princ (if (aref flags idx) 1 0))))
732 ((eq type 'ccl)
733 (let (i len)
734 (if (symbolp (car flags))
735 (princ (format " %s" (car flags)))
736 (setq i 0 len (length (car flags)))
737 (while (< i len)
738 (princ (format " %x" (aref (car flags) i)))
739 (setq i (1+ i))))
740 (princ ",")
741 (if (symbolp (cdr flags))
742 (princ (format "%s" (cdr flags)))
743 (setq i 0 len (length (cdr flags)))
744 (while (< i len)
745 (princ (format " %x" (aref (cdr flags) i)))
746 (setq i (1+ i))))))
747 (t (princ 0)))
748 (princ ":")
749 (princ (coding-system-doc-string coding-system))
750 (princ "\n"))))
752 ;;;###autoload
753 (defun list-coding-systems (&optional arg)
754 "Display a list of all coding systems.
755 This shows the mnemonic letter, name, and description of each coding system.
757 With prefix ARG, the output format gets more cryptic,
758 but still contains full information about each coding system."
759 (interactive "P")
760 (with-output-to-temp-buffer "*Help*"
761 (list-coding-systems-1 arg)))
763 (defun list-coding-systems-1 (arg)
764 (if (null arg)
765 (princ "\
766 ###############################################
767 # List of coding systems in the following format:
768 # MNEMONIC-LETTER -- CODING-SYSTEM-NAME
769 # DOC-STRING
771 (princ "\
772 #########################
773 ## LIST OF CODING SYSTEMS
774 ## Each line corresponds to one coding system
775 ## Format of a line is:
776 ## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
777 ## :PRE-WRITE-CONVERSION:DOC-STRING,
778 ## where
779 ## NAME = coding system name
780 ## ALIAS = alias of the coding system
781 ## TYPE = nil (no conversion), t (undecided or automatic detection),
782 ## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
783 ## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
784 ## FLAGS =
785 ## if TYPE = 2 then
786 ## comma (`,') separated data of the following:
787 ## G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
788 ## LOCKING-SHIFT, SINGLE-SHIFT, USE-ROMAN, USE-OLDJIS, NO-ISO6429
789 ## else if TYPE = 4 then
790 ## comma (`,') separated CCL programs for read and write
791 ## else
792 ## 0
793 ## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
796 (dolist (coding-system (sort-coding-systems (coding-system-list 'base-only)))
797 (if (null arg)
798 (print-coding-system-briefly coding-system 'tightly)
799 (print-coding-system coding-system))))
801 ;; Fixme: delete?
802 ;;;###autoload
803 (defun list-coding-categories ()
804 "Display a list of all coding categories."
805 (with-output-to-temp-buffer "*Help*"
806 (princ "\
807 ############################
808 ## LIST OF CODING CATEGORIES (ordered by priority)
809 ## CATEGORY:CODING-SYSTEM
812 (let ((l coding-category-list))
813 (while l
814 (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
815 (setq l (cdr l))))))
817 ;;; FONT
819 (declare-function font-info "font.c" (name &optional frame))
821 (defun describe-font-internal (font-info &optional ignored)
822 "Print information about a font in FONT-INFO.
823 The IGNORED argument is ignored."
824 (print-list "name (opened by):" (aref font-info 0))
825 (print-list " full name:" (aref font-info 1))
826 (print-list " size:" (format "%2d" (aref font-info 2)))
827 (print-list " height:" (format "%2d" (aref font-info 3)))
828 (print-list " baseline-offset:" (format "%2d" (aref font-info 4)))
829 (print-list "relative-compose:" (format "%2d" (aref font-info 5))))
831 ;;;###autoload
832 (defun describe-font (fontname)
833 "Display information about a font whose name is FONTNAME.
834 The font must be already used by Emacs."
835 (interactive "sFont name (default current choice for ASCII chars): ")
836 (or (and window-system (fboundp 'fontset-list))
837 (error "No fonts being used"))
838 (let (font-info)
839 (if (or (not fontname) (= (length fontname) 0))
840 (setq fontname (face-attribute 'default :font)))
841 (setq font-info (font-info fontname))
842 (if (null font-info)
843 (if (fontp fontname 'font-object)
844 ;; The font should be surely used. So, there's some
845 ;; problem about getting information about it. It is
846 ;; better to print the fontname to show which font has
847 ;; this problem.
848 (message "No information about \"%s\"" (font-xlfd-name fontname))
849 (message "No matching font found"))
850 (with-output-to-temp-buffer "*Help*"
851 (describe-font-internal font-info)))))
853 (defun print-fontset-element (val)
854 ;; VAL has this format:
855 ;; ((REQUESTED-FONT-NAME OPENED-FONT-NAME ...) ...)
856 ;; CHAR RANGE is already inserted. Get character codes from
857 ;; the current line.
858 (beginning-of-line)
859 (let ((from (following-char))
860 (to (if (looking-at "[^.]*[.]* ")
861 (char-after (match-end 0)))))
862 (if (re-search-forward "[ \t]*$" nil t)
863 (delete-region (match-beginning 0) (match-end 0)))
865 ;; For non-ASCII characters, insert also CODE RANGE.
866 (if (or (>= from 128) (and to (>= to 128)))
867 (if to
868 (insert (format " (#x%02X .. #x%02X)" from to))
869 (insert (format " (#x%02X)" from))))
871 ;; Insert a requested font name.
872 (dolist (elt val)
873 (if (not elt)
874 (insert "\n -- inhibit fallback fonts --")
875 (let ((requested (car elt)))
876 (if (stringp requested)
877 (insert "\n " requested)
878 (let (family registry weight slant width adstyle)
879 (if (and (fboundp 'fontp) (fontp requested))
880 (setq family (font-get requested :family)
881 registry (font-get requested :registry)
882 weight (font-get requested :weight)
883 slant (font-get requested :slant)
884 width (font-get requested :width)
885 adstyle (font-get requested :adstyle))
886 (setq family (aref requested 0)
887 registry (aref requested 5)
888 weight (aref requested 1)
889 slant (aref requested 2)
890 width (aref requested 3)
891 adstyle (aref requested 4)))
892 (if (not family)
893 (setq family "*-*")
894 (if (symbolp family)
895 (setq family (symbol-name family)))
896 (or (string-match "-" family)
897 (setq family (concat "*-" family))))
898 (if (not registry)
899 (setq registry "*-*")
900 (if (symbolp registry)
901 (setq registry (symbol-name registry)))
902 (or (string-match "-" registry)
903 (= (aref registry (1- (length registry))) ?*)
904 (setq registry (concat registry "*"))))
905 (insert (format"\n -%s-%s-%s-%s-%s-*-*-*-*-*-*-%s"
906 family (or weight "*") (or slant "*") (or width "*")
907 (or adstyle "*") registry)))))
909 ;; Insert opened font names (if any).
910 (if (and (boundp 'print-opened) (symbol-value 'print-opened))
911 (dolist (opened (cdr elt))
912 (insert "\n\t[" opened "]")))))))
914 (declare-function query-fontset "fontset.c" (pattern &optional regexpp))
915 (declare-function fontset-info "fontset.c" (fontset &optional frame))
917 (defun print-fontset (fontset &optional print-opened)
918 "Print information about FONTSET.
919 FONTSET nil means the fontset of the selected frame, t means the
920 default fontset.
921 If optional arg PRINT-OPENED is non-nil, also print names of all opened
922 fonts for FONTSET. This function actually inserts the information in
923 the current buffer."
924 (if (eq fontset t)
925 (setq fontset (query-fontset "fontset-default"))
926 (if (eq fontset nil)
927 (setq fontset (face-attribute 'default :fontset))))
928 (beginning-of-line)
929 (narrow-to-region (point) (point))
930 (insert "Fontset: " fontset "\n")
931 (insert (propertize "CHAR RANGE" 'face 'underline)
932 " (" (propertize "CODE RANGE" 'face 'underline) ")\n")
933 (insert " " (propertize "FONT NAME" 'face 'underline)
934 " (" (propertize "REQUESTED" 'face 'underline)
935 " and [" (propertize "OPENED" 'face 'underline) "])")
936 (let* ((info (fontset-info fontset))
937 (default-info (char-table-extra-slot info 0))
938 start1 end1 start2 end2)
939 (describe-vector info 'print-fontset-element)
940 (when (char-table-range info nil)
941 ;; The default of FONTSET is described.
942 (setq start1 (re-search-backward "^default"))
943 (delete-region (point) (line-end-position))
944 (insert "\n ---<fallback to the default of the specified fontset>---")
945 (put-text-property (line-beginning-position) (point) 'face 'highlight)
946 (goto-char (point-max))
947 (setq end1 (setq start2 (point))))
948 (when default-info
949 (insert "\n ---<fallback to the default fontset>---")
950 (put-text-property (line-beginning-position) (point) 'face 'highlight)
951 (describe-vector default-info 'print-fontset-element)
952 (when (char-table-range default-info nil)
953 ;; The default of the default fontset is described.
954 (setq end2 (re-search-backward "^default"))
955 (delete-region (point) (line-end-position))
956 (insert "\n ---<fallback to the default of the default fontset>---")
957 (put-text-property (line-beginning-position) (point) 'face 'highlight)))
958 (if (and start1 end2)
959 ;; Reoder the printed information to match with the font
960 ;; searching strategy; i.e. FONTSET, the default fontset,
961 ;; default of FONTSET, default of the default fontset.
962 (transpose-regions start1 end1 start2 end2))
963 (goto-char (point-max)))
964 (widen))
966 (defvar fontset-alias-alist)
967 (declare-function fontset-list "fontset.c" ())
969 ;;;###autoload
970 (defun describe-fontset (fontset)
971 "Display information about FONTSET.
972 This shows which font is used for which character(s)."
973 (interactive
974 (if (not (and window-system (fboundp 'fontset-list)))
975 (error "No fontsets being used")
976 (let ((fontset-list (nconc
977 (fontset-list)
978 (mapcar 'cdr fontset-alias-alist)))
979 (completion-ignore-case t))
980 (list (completing-read
981 "Fontset (default used by the current frame): "
982 fontset-list nil t)))))
983 (if (= (length fontset) 0)
984 (setq fontset (face-attribute 'default :fontset))
985 (setq fontset (query-fontset fontset)))
986 (help-setup-xref (list #'describe-fontset fontset) (interactive-p))
987 (with-output-to-temp-buffer (help-buffer)
988 (with-current-buffer standard-output
989 (print-fontset fontset t))))
991 (declare-function fontset-plain-name "fontset" (fontset))
993 ;;;###autoload
994 (defun list-fontsets (arg)
995 "Display a list of all fontsets.
996 This shows the name, size, and style of each fontset.
997 With prefix arg, also list the fonts contained in each fontset;
998 see the function `describe-fontset' for the format of the list."
999 (interactive "P")
1000 (if (not (and window-system (fboundp 'fontset-list)))
1001 (error "No fontsets being used")
1002 (help-setup-xref (list #'list-fontsets arg) (interactive-p))
1003 (with-output-to-temp-buffer (help-buffer)
1004 (with-current-buffer standard-output
1005 ;; This code is duplicated near the end of mule-diag.
1006 (let ((fontsets
1007 (sort (fontset-list)
1008 (lambda (x y)
1009 (string< (fontset-plain-name x)
1010 (fontset-plain-name y))))))
1011 (while fontsets
1012 (if arg
1013 (print-fontset (car fontsets) nil)
1014 (insert "Fontset: " (car fontsets) "\n"))
1015 (setq fontsets (cdr fontsets))))))))
1017 ;;;###autoload
1018 (defun list-input-methods ()
1019 "Display information about all input methods."
1020 (interactive)
1021 (help-setup-xref '(list-input-methods) (interactive-p))
1022 (with-output-to-temp-buffer (help-buffer)
1023 (list-input-methods-1)
1024 (with-current-buffer standard-output
1025 (save-excursion
1026 (goto-char (point-min))
1027 (while (re-search-forward
1028 "^ \\([^ ]+\\) (`.*' in mode line)$" nil t)
1029 (help-xref-button 1 'help-input-method (match-string 1)))))))
1031 (defun list-input-methods-1 ()
1032 (if (not input-method-alist)
1033 (princ "
1034 No input method is available, perhaps because you have not
1035 installed LEIM (Libraries of Emacs Input Methods).")
1036 (princ "LANGUAGE\n NAME (`TITLE' in mode line)\n")
1037 (princ " SHORT-DESCRIPTION\n------------------------------\n")
1038 (setq input-method-alist
1039 (sort input-method-alist
1040 (lambda (x y) (string< (nth 1 x) (nth 1 y)))))
1042 (let (language)
1043 (dolist (elt input-method-alist)
1044 (when (not (equal language (nth 1 elt)))
1045 (setq language (nth 1 elt))
1046 (princ language)
1047 (terpri))
1048 (princ (format " %s (`%s' in mode line)\n %s\n"
1049 (car elt)
1050 (let ((title (nth 3 elt)))
1051 (if (and (consp title) (stringp (car title)))
1052 (car title)
1053 title))
1054 (nth 4 elt)))))))
1056 ;;; DIAGNOSIS
1058 ;; Insert a header of a section with SECTION-NUMBER and TITLE.
1059 (defun insert-section (section-number title)
1060 (insert "########################################\n"
1061 "# Section " (format "%d" section-number) ". " title "\n"
1062 "########################################\n\n"))
1064 ;;;###autoload
1065 (defun mule-diag ()
1066 "Display diagnosis of the multilingual environment (Mule).
1068 This shows various information related to the current multilingual
1069 environment, including lists of input methods, coding systems,
1070 character sets, and fontsets (if Emacs is running under a window
1071 system which uses fontsets)."
1072 (interactive)
1073 (with-output-to-temp-buffer "*Mule-Diagnosis*"
1074 (with-current-buffer standard-output
1075 (insert "###############################################\n"
1076 "### Current Status of Multilingual Features ###\n"
1077 "###############################################\n\n"
1078 "CONTENTS: Section 1. General Information\n"
1079 " Section 2. Display\n"
1080 " Section 3. Input methods\n"
1081 " Section 4. Coding systems\n"
1082 " Section 5. Character sets\n")
1083 (if (and window-system (fboundp 'fontset-list))
1084 (insert " Section 6. Fontsets\n"))
1085 (insert "\n")
1087 (insert-section 1 "General Information")
1088 (insert "Version of this emacs:\n " (emacs-version) "\n\n")
1089 (insert "Configuration options:\n " system-configuration-options "\n\n")
1090 (insert "Multibyte characters awareness:\n"
1091 (format " default: %S\n" (default-value
1092 'enable-multibyte-characters))
1093 (format " current-buffer: %S\n\n" enable-multibyte-characters))
1094 (insert "Current language environment: " current-language-environment
1095 "\n\n")
1097 (insert-section 2 "Display")
1098 (if window-system
1099 (insert (format "Window-system: %s, version %s"
1100 window-system window-system-version))
1101 (insert "Terminal: " (getenv "TERM")))
1102 (insert "\n\n")
1104 (if window-system
1105 (let ((font (cdr (assq 'font (frame-parameters)))))
1106 (insert "The font and fontset of the selected frame are:\n"
1107 " font: " font "\n"
1108 " fontset: " (face-attribute 'default :fontset) "\n"))
1109 (insert "Coding system of the terminal: "
1110 (symbol-name (terminal-coding-system))))
1111 (insert "\n\n")
1113 (insert-section 3 "Input methods")
1114 (list-input-methods-1)
1115 (insert "\n")
1116 (if default-input-method
1117 (insert (format "Default input method: %s\n" default-input-method))
1118 (insert "No default input method is specified\n"))
1120 (insert-section 4 "Coding systems")
1121 (list-coding-systems-1 t)
1122 (insert "\n")
1124 (insert-section 5 "Character sets")
1125 (list-character-sets-2)
1126 (insert "\n")
1128 (when (and window-system (fboundp 'fontset-list))
1129 ;; This code duplicates most of list-fontsets.
1130 (insert-section 6 "Fontsets")
1131 (insert "Fontset-Name\t\t\t\t\t\t WDxHT Style\n")
1132 (insert "------------\t\t\t\t\t\t ----- -----\n")
1133 (dolist (fontset (fontset-list))
1134 (print-fontset fontset t)))
1135 (help-print-return-message))))
1137 ;;;###autoload
1138 (defun font-show-log (&optional limit)
1139 "Show log of font listing and opening.
1140 Prefix arg LIMIT says how many fonts to show for each listing.
1141 The default is 20. If LIMIT is negative, do not limit the listing."
1142 (interactive "P")
1143 (setq limit (if limit (prefix-numeric-value limit) 20))
1144 (if (eq font-log t)
1145 (message "Font logging is currently suppressed")
1146 (with-output-to-temp-buffer "*Help*"
1147 (set-buffer standard-output)
1148 (dolist (elt (reverse font-log))
1149 (insert (format "%s: %s\n" (car elt) (cadr elt)))
1150 (setq elt (nth 2 elt))
1151 (if (or (vectorp elt) (listp elt))
1152 (let ((i 0))
1153 (catch 'tag
1154 (mapc #'(lambda (x)
1155 (setq i (1+ i))
1156 (when (= i limit)
1157 (insert " ...\n")
1158 (throw 'tag nil))
1159 (insert (format " %s\n" x)))
1160 elt)))
1161 (insert (format " %s\n" elt)))))))
1164 (provide 'mule-diag)
1166 ;; arch-tag: cd3b607c-2893-45a0-a4fa-a6535754dbee
1167 ;;; mule-diag.el ends here