Source

mule-base / mule-diag.el

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
;;; mule-diag.el --- Show diagnosis of multilingual environment (Mule)

;; Copyright (C) 1995,1999 Electrotechnical Laboratory, JAPAN.
;; Licensed to the Free Software Foundation.
;; Copyright (C) 1997 MORIOKA Tomohiko

;; Keywords: multilingual, charset, coding system, fontset, diagnosis

;; This file is part of XEmacs.

;; XEmacs is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; XEmacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; General utility function

(eval-when-compile (load "mule-util"))

;; Print all arguments with single space separator in one line.
(defun print-list (&rest args)
  (while (cdr args)
    (when (car args)
      (princ (car args))
      (princ " "))
    (setq args (cdr args)))
  (princ (car args))
  (princ "\n"))

;; Re-order the elements of charset-list.
;; (defun sort-charset-list ()
;;   (setq charset-list
;;         (sort charset-list
;;               (function (lambda (x y) (< (charset-id x) (charset-id y)))))))
(defun sorted-charset-list ()
  (sort (charset-list)
	(function (lambda (x y) (< (charset-id x) (charset-id y))))))

;;; CHARSET

;;;###autoload
(defun list-character-sets (&optional arg)
  "Display a list of all character sets.

The ID column contains a charset identification number for internal use.
The B column contains a number of bytes occupied in a buffer
  by any character in this character set.
The W column contains a number of columns occupied on the screen
  by any character in this character set.

With prefix arg, the output format gets more cryptic,
but still shows the full information."
  (interactive "P")
  ;; (sort-charset-list)
  (with-output-to-temp-buffer "*Help*"
    (save-excursion
      (set-buffer standard-output)
      (list-character-sets-1 arg)
      (help-mode)
      (setq truncate-lines t))))

(defun list-character-sets-1 (arg)
  (let ((l (sorted-charset-list))
	charset)
    (if (null arg)
	(progn
	  (insert "ID  Name		    B W Description\n")
	  (insert "--  ----		    - - -----------\n")
	  (while l
	    (setq charset (car l) l (cdr l))
	    (insert (format "%03d %s" (charset-id charset) charset))
	    (indent-to 28)
	    (insert (format "%d %d %s\n"
			    (charset-bytes charset)
			    (charset-width charset)
			    (charset-description charset)))))
      (insert "\
#########################
## LIST OF CHARSETS
## Each line corresponds to one charset.
## The following attributes are listed in this order
## separated by a colon `:' in one line.
##	CHARSET-ID,
##	CHARSET-SYMBOL-NAME,
##	DIMENSION (1 or 2)
##	CHARS (94 or 96)
##	BYTES (of multibyte form: 1, 2, 3, or 4),
##	WIDTH (occupied column numbers: 1 or 2),
##	DIRECTION (0:left-to-right, 1:right-to-left),
##	ISO-FINAL-CHAR (character code of ISO-2022's final character)
##	ISO-GRAPHIC-PLANE (ISO-2022's graphic plane, 0:GL, 1:GR)
##	DESCRIPTION (describing string of the charset)
")
      (while l
	(setq charset (car l) l (cdr l))
	(princ (format "%03d:%s:%d:%d:%d:%d:%d:%d:%d:%s\n" 
		       (charset-id charset)
		       charset
		       (charset-dimension charset)
		       (charset-chars charset)
		       (charset-bytes charset)
		       (charset-width charset)
		       (charset-direction charset)
		       (charset-iso-final-char charset)
		       (charset-iso-graphic-plane charset)
		       (charset-description charset)))))))

;;; CODING-SYSTEM

(defun describe-designation (cs register)
  (let ((charset
	 (coding-system-property
	  cs (intern (format "charset-g%d" register))))
	(force
	 (coding-system-property
	  cs (intern (format "force-g%d-on-output" register)))))
    (princ
     (format
      "  G%d: %s%s\n"
      register
      (cond ((null charset) "never used")
	    ((eq t charset) "none")
	    (t (charset-name charset)))
      (if force " (explicit designation required)" "")))))

;;;###autoload
(defun describe-coding-system (coding-system)
  "Display information about CODING-SYSTEM."
  (interactive "zDescribe coding system (default, current choices): ")
  (if (or (null coding-system)
	  (string= (symbol-name coding-system) ""))
      (describe-current-coding-system)
    (with-output-to-temp-buffer "*Help*"
      (print-coding-system-briefly coding-system 'doc-string)
      (let ((type (coding-system-type coding-system)))
	(princ (format "Type: %s" type))
	(when (eq type 'iso2022)
	  (princ " (variant of ISO-2022)\n")
	  (princ "Initial designations:\n")
	  ;;(print-designation flags)
	  (describe-designation coding-system 0)
	  (describe-designation coding-system 1)
	  (describe-designation coding-system 2)
	  (describe-designation coding-system 3)
	  (princ "Other Form: \n  ")
	  (princ (if (coding-system-short coding-system)
		     "short-form"
		   "long-form"))
	  (if (coding-system-no-ascii-eol coding-system)
	      (princ ", ASCII@EOL"))
	  (if (coding-system-no-ascii-cntl coding-system)
	      (princ ", ASCII@CNTL"))
	  (princ (if (coding-system-seven coding-system)
		     ", 7-bit"
		   ", 8-bit"))
	  (if (coding-system-lock-shift coding-system)
	      (princ ", use-locking-shift")
	    (princ ", use-single-shift"))
	  ;; (if (aref flags 10) (princ ", use-roman"))
          ;; (if (aref flags 11) (princ ", use-old-jis"))
	  (if (coding-system-no-iso6429 coding-system)
	      (princ ", no-ISO6429"))
          ;; (if (aref flags 13) (princ ", init-bol"))
          ;; (if (aref flags 14) (princ ", designation-bol"))
          ;; (if (aref flags 15) (princ ", convert-unsafe"))
          ;; (if (aref flags 16) (princ ", accept-latin-extra-code"))
	  )
	(princ "\nEOL type:")
	(let ((eol-type (coding-system-eol-type coding-system)))
	  (cond ((null eol-type)
		 (princ "\n  Automatic selection from\n    ")
		 (princ (format "%s-unix, %s-dos or %s-mac.\n"
				coding-system coding-system coding-system))
		 )
		((symbolp eol-type)
		 (princ " ")
		 (princ eol-type))
		(t (princ "invalid\n")))))
      (let ((postread (coding-system-get coding-system 'post-read-conversion)))
	(when postread
	  (princ "After decoding a text normally,")
	  (princ " perform post-conversion by the function: ")
	  (princ "\n  ")
	  (princ postread)
	  (princ "\n")))
      (let ((prewrite (coding-system-get coding-system 'pre-write-conversion)))
	(when prewrite
	  (princ "Before encoding a text normally,")
	  (princ " perform pre-conversion by the function: ")
	  (princ "\n  ")
	  (princ prewrite)
	  (princ "\n")))
      (let ((charsets (coding-system-get coding-system 'safe-charsets)))
	(when charsets
	  (if (eq charsets t)
	      (princ "This coding system can encode all charsets.\n")
	    (princ "This coding system encode the following charsets:\n")
	    (princ " ")
	    (while charsets
	      (princ " ")
	      (princ (car charsets))
	      (setq charsets (cdr charsets))))))
      (save-excursion
	(set-buffer standard-output)
	(help-mode)))))

;;;###autoload
(defun describe-current-coding-system-briefly ()
  "Display coding systems currently used in a brief format in echo area.

The format is \"F[..],K[..],T[..], default F[..]\",
where mnemonics of the following coding systems come in this order
at the place of `..':
  `buffer-file-coding-system` (of the current buffer)
  eol-type of buffer-file-coding-system (of the current buffer)
  Value returned by `keyboard-coding-system'
  eol-type of (keyboard-coding-system)
  Value returned by `terminal-coding-system.
  eol-type of (terminal-coding-system)
  `default-buffer-file-coding-system'
  eol-type of default-buffer-file-coding-system"
  (interactive)
  (let* ((proc (get-buffer-process (current-buffer)))
	 (process-coding-systems (if proc (process-coding-system proc))))
    (message
     ;; "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]"
     "F[%s%s],K[%s%s],T[%s%s], default F[%s%s]"
     (coding-system-mnemonic buffer-file-coding-system)
     (coding-system-eol-type-mnemonic buffer-file-coding-system)
     (coding-system-mnemonic (keyboard-coding-system))
     (coding-system-eol-type-mnemonic (keyboard-coding-system))
     (coding-system-mnemonic (terminal-coding-system))
     (coding-system-eol-type-mnemonic (terminal-coding-system))
     ;; (coding-system-mnemonic (car process-coding-systems))
     ;; (coding-system-eol-type-mnemonic (car process-coding-systems))
     ;; (coding-system-mnemonic (cdr process-coding-systems))
     ;; (coding-system-eol-type-mnemonic (cdr process-coding-systems))
     (coding-system-mnemonic default-buffer-file-coding-system)
     (coding-system-eol-type-mnemonic default-buffer-file-coding-system)
     ;; (coding-system-mnemonic (car default-process-coding-system))
     ;; (coding-system-eol-type-mnemonic (car default-process-coding-system))
     ;; (coding-system-mnemonic (cdr default-process-coding-system))
     ;; (coding-system-eol-type-mnemonic (cdr default-process-coding-system))
     )))

;; Print symbol name and mnemonic letter of CODING-SYSTEM with `princ'.
(defun print-coding-system-briefly (coding-system &optional doc-string)
  (if (not coding-system)
      (princ "nil\n")
    ;; In XEmacs, coding-system has own type.
    (if (coding-system-p coding-system)
	(setq coding-system (coding-system-name coding-system))
      )
    ;; In XEmacs, coding-system-mnemonic returns string.
    (princ (format "%s -- %s"
		   (coding-system-mnemonic coding-system)
		   coding-system))
    (let ((aliases (coding-system-get coding-system 'alias-coding-systems)))
      (if (eq coding-system (car aliases))
	  (if (cdr aliases)
	      (princ (format " %S" (cons 'alias: (cdr aliases)))))
	(if (memq coding-system aliases)
	    (princ (format " (alias of %s)" (car aliases))))))
    (princ "\n")
    (if (and doc-string
	     (setq doc-string (coding-system-doc-string coding-system)))
	(princ (format "  %s\n" doc-string)))))

;;;###autoload
(defun describe-current-coding-system ()
  "Display coding systems currently used, in detail."
  (interactive)
  (with-output-to-temp-buffer "*Help*"
    (let* ((proc (get-buffer-process (current-buffer)))
	   (process-coding-systems (if proc (process-coding-system proc))))
      (princ "Coding system for saving this buffer:\n  ")
      ;; local-variable-p of XEmacs requires 2 arguments.
      (if (local-variable-p 'buffer-file-coding-system (current-buffer))
	  (print-coding-system-briefly buffer-file-coding-system)
	(princ "Not set locally, use the default.\n"))
      (princ "Default coding system (for new files):\n  ")
      (print-coding-system-briefly default-buffer-file-coding-system)
      (princ "Coding system for keyboard input:\n  ")
      (print-coding-system-briefly (keyboard-coding-system))
      (princ "Coding system for terminal output:\n  ")
      (print-coding-system-briefly (terminal-coding-system))
      (when (get-buffer-process (current-buffer))
	(princ "Coding systems for process I/O:\n")
	(princ "  encoding input to the process: ")
	(print-coding-system-briefly (cdr process-coding-systems))
	(princ "  decoding output from the process: ")
	(print-coding-system-briefly (car process-coding-systems)))
      ;;(princ "Defaults for subprocess I/O:\n")
      ;;(princ "  decoding: ")
      ;;(print-coding-system-briefly (car default-process-coding-system))
      ;;(princ "  encoding: ")
      ;;(print-coding-system-briefly (cdr default-process-coding-system))
      )
    (save-excursion
      (set-buffer standard-output)

      (princ
       "\nPriority order for recognizing coding systems when reading files:\n")
      (let ((l (coding-priority-list)) ; It is function in XEmacs.
	    (i 1)
	    (coding-list nil)
	    coding aliases)
	(while l
	  (setq coding (coding-category-system (car l))) ; for XEmacs
	  ;; Do not list up the same coding system twice.
	  (when (and coding (not (memq coding coding-list)))
	    (setq coding-list (cons coding coding-list))
	    (princ (format "  %d. %s " i coding))
	    (setq aliases (coding-system-get coding 'alias-coding-systems))
	    (if (eq coding (car aliases))
		(if (cdr aliases)
		    (princ (cons 'alias: (cdr aliases))))
	      (if (memq coding aliases)
		  (princ (list 'alias 'of (car aliases)))))
	    (terpri)
	    (setq i (1+ i)))
	  (setq l (cdr l))))

      (princ "\n  Other coding systems cannot be distinguished automatically
  from these, and therefore cannot be recognized automatically
  with the present coding system priorities.\n\n")

      (let ((categories '(iso-7)) ; for XEmacs
	    ;; '(coding-category-iso-7 coding-category-iso-7-else))
	    coding-system codings)
	(while categories
	  ;; for XEmacs
	  (setq coding-system (coding-category-system (car categories)))
	  (mapcar
	   (function
	    (lambda (x)
	      (if (and (not (eq x coding-system))
		       (coding-system-get x 'no-initial-designation)
		       (let ((flags (coding-system-flags x)))
			 (not (or (aref flags 10) (aref flags 11)))))
		  (setq codings (cons x codings)))))
	   (get (car categories) 'coding-systems))
	  (if codings
	      (let ((max-col (frame-width))
		    pos)
		(princ (format "  The followings are decoded correctly but recognized as %s:\n   " coding-system))
		(while codings
		  (setq pos (point))
		  (insert (format " %s" (car codings)))
		  (when (> (current-column) max-col)
		    (goto-char pos)
		    (insert "\n   ")
		    (goto-char (point-max)))
		  (setq codings (cdr codings)))
		(insert "\n\n")))
	  (setq categories (cdr categories))))

      (princ "Particular coding systems specified for certain file names:\n")
      (terpri)
      (princ "  OPERATION\tTARGET PATTERN\t\tCODING SYSTEM(s)\n")
      (princ "  ---------\t--------------\t\t----------------\n")
      (let ((func (lambda (operation alist)
		    (princ "  ")
		    (princ operation)
		    (if (not alist)
			(princ "\tnothing specified\n")
		      (while alist
			(indent-to 16)
			(prin1 (car (car alist)))
			(if (>= (current-column) 40)
			    (newline))
			(indent-to 40)
			(princ (cdr (car alist)))
			(princ "\n")
			(setq alist (cdr alist)))))))
	(funcall func "File I/O" file-coding-system-alist)
	(funcall func "Process I/O" process-coding-system-alist)
	(funcall func "Network I/O" network-coding-system-alist))
      (help-mode))))

;; Print detailed information on CODING-SYSTEM.
(defun print-coding-system (coding-system)
  (princ coding-system)
  ;; aliases for coding system are not supported in XEmacs 21.1.x
  (if (and (functionp 'coding-system-alias-p) (coding-system-alias-p coding-system))
      (princ (format " (alias of %s)\n" (coding-system-aliasee coding-system)))
    (let ((type (coding-system-type coding-system))
	  (eol-type (coding-system-eol-type coding-system)))
      (princ (format ";%s;%s;%s;"
		     type
		     (coding-system-mnemonic coding-system)
		     (symbol-name eol-type)))
      (let ((flags '()))
	(cond ((eq type 'iso2022)		; ISO-2022
	       ;; G0, G1, G2, G3
	       ;; probably this should be implemented with (defmacro)?
	       (mapcar*
		(lambda (GX charset force-charset)
		  (let ((charset-name (coding-system-get coding-system (intern charset))))
		    (if charset-name
			(let (flag)
			   (if (coding-system-property coding-system (intern force-charset))
			       (setq flag (concat GX ":[" (symbol-name charset-name) "]"))
			     (setq flag (concat GX ":" (symbol-name charset-name))))
			   (setq flags (append (list flag) flags))))))

		'("G0" "G1" "G2" "G3")
		'("charset-g0" "charset-g1" "charset-g2" "charset-g3")
		'("force-g0-on-output" "force-g1-on-output"
				      "force-g2-on-output" "force-g3-on-output"))

	       ;; various other flags
	     (if (coding-system-get coding-system 'short)
		 (setq flags (append '("SHORT-FORM") flags)))

	     (unless (coding-system-get coding-system 'no-ascii-eol)
	       (setq flags (append '("ASCII-EOL") flags)))

	     (unless (coding-system-get coding-system 'no-ascii-cntl)
	       (setq flags (append '("ASCII-CNTL") flags)))

	     (if (coding-system-get coding-system 'seven)
		 (setq flags (append '("SEVEN") flags)))

	     (if (coding-system-get coding-system 'lock-shift)
		 (setq flags (append '("LOCKING-SHIFT") flags)))

	     (if (coding-system-get coding-system 'no-iso6429)
		 (setq flags (append '("NO-ISO6429") flags))))

 	    ((eq type 'ccl)		; CCL
	     (princ (format "%s, %s"
			    (coding-system-get coding-system 'encode)
			    (coding-system-get coding-system 'decode) flags))))
	(setq flags (reverse flags))
	(if (car flags)
	    (progn
	      (princ (format "%s" (car flags)))
	      (mapc
	       (lambda (flag)
		 (princ (format ", %s" flag)))
	       (cdr flags))))
	))
      (princ ";")
      (princ (coding-system-doc-string coding-system))
      (princ "\n")))

;;;###autoload
(defun list-coding-systems (&optional arg)
  "Display a list of all coding systems.
This shows the mnemonic letter, name, and description of each coding system.

With prefix arg, the output format gets more cryptic,
but still contains full information about each coding system."
  (interactive "P")
  (with-displaying-help-buffer
   (lambda ()
     (with-current-buffer standard-output
       (list-coding-systems-1 arg)))))


(defun list-coding-systems-1 (arg)
  (if (null arg)
      (princ "\
###############################################
# List of coding systems in the following format:
# MNEMONIC-LETTER -- CODING-SYSTEM-NAME
#	DOC-STRING
")
    (princ "\
#########################
## LIST OF CODING SYSTEMS
## Each line corresponds to one coding system
## Format of a line is:
##   NAME[,ALIAS...];TYPE;MNEMONIC;EOL;FLAGS;POST-READ-CONVERSION
##	;PRE-WRITE-CONVERSION;DOC-STRING,
## where
##  NAME = coding system name
##  ALIAS = alias of the coding system
##  TYPE = nil (no conversion), t (undecided or automatic detection),
##         0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
##  EOL = lf (LF), crlf (CRLF), cr (CR), or nil (Automatic detection)
##  FLAGS =
##    if TYPE = 'ISO2022 then
##      comma (`,') separated data of the followings:
##        G0, G1, G2, G3, SHORT-FORM, ASCII-EOL, ASCII-CNTL, SEVEN,
##        LOCKING-SHIFT, NO-ISO6429
##    else if TYPE = 'CCL then
##      comma (`,') separated CCL programs for read and write
##    else
##      0
##  POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
##
"))
  (if (null arg)
      ;; print only base coding systems (w/o "-dos", "-unix", "-mac")
      (let ((bases (make-hash-table)))
	;; put base coding systems into hash-table
	(mapc
	 (lambda (coding-system)
	   (let* ((base (coding-system-base coding-system))
		  (base-name (coding-system-name base)))

	     (unless (gethash base-name bases)
		 (puthash base-name base bases))))
	 (coding-system-list))

	;; traverse hash-table and print each coding system
	(maphash 
	 (lambda (key value) (print-coding-system-briefly value 'doc-string))
	 bases))
	 
    ;; print all coding systems in details
    (mapc
     '(lambda (coding-system)
	(print-coding-system coding-system))
     (coding-system-list))))

;;;###autoload
(defun list-coding-categories ()
  "Display a list of all coding categories."
  (interactive)
  (with-output-to-temp-buffer "*Help*"
    (princ "\
############################
## LIST OF CODING CATEGORIES (ordered by priority)
## CATEGORY:CODING-SYSTEM
##
")
    (let ((l (coding-priority-list)))
      (while l
	(princ (format "%s:%s\n" (car l) (coding-category-system (car l))))
	(setq l (cdr l))))))

;;; FONT

;; Print information of a font in FONTINFO.
(defun describe-font-internal (font-info &optional verbose)
  (print-list "name (opened by):" (aref font-info 0))
  (print-list "       full name:" (aref font-info 1))
  (let ((charset (aref font-info 2)))
    (print-list "   charset:"
		(format "%s (%s)" charset (charset-description charset))))
  (print-list "            size:" (format "%d" (aref font-info 3)))
  (print-list "          height:" (format "%d" (aref font-info 4)))
  (print-list " baseline-offset:" (format "%d" (aref font-info 5)))
  (print-list "relative-compose:" (format "%d" (aref font-info 6))))

;;;###autoload
(defun describe-font (fontname)
  "Display information about fonts which partially match FONTNAME."
  (interactive "sFontname (default, current choice for ASCII chars): ")
  (or (and window-system (boundp 'global-fontset-alist))
      (error "No fontsets being used"))
  (when (or (not fontname) (= (length fontname) 0))
    (setq fontname (cdr (assq 'font (frame-parameters))))
    (if (query-fontset fontname)
	(setq fontname
	      (nth 2 (assq 'ascii (aref (fontset-info fontname) 2))))))
  (let ((font-info (font-info fontname)))
    (if (null font-info)
	(message "No matching font")
      (with-output-to-temp-buffer "*Help*"
	(describe-font-internal font-info 'verbose)))))

;; Print information of FONTSET.  If optional arg PRINT-FONTS is
;; non-nil, print also names of all fonts in FONTSET.  This function
;; actually INSERT such information in the current buffer.
(defun print-fontset (fontset &optional print-fonts)
  (let* ((fontset-info (fontset-info fontset))
	 (size (aref fontset-info 0))
	 (height (aref fontset-info 1))
	 (fonts (and print-fonts (aref fontset-info 2)))
	 (xlfd-fields (x-decompose-font-name fontset))
	 style)
    (if xlfd-fields
	(let ((weight (aref xlfd-fields xlfd-regexp-weight-subnum))
	      (slant  (aref xlfd-fields xlfd-regexp-slant-subnum)))
	  (if (string-match "^bold$\\|^demibold$" weight)
	      (setq style (concat weight " "))
	    (setq style "medium "))
	  (cond ((string-match "^i$" slant)
		 (setq style (concat style "italic")))
		((string-match "^o$" slant)
		 (setq style (concat style "slant")))
		((string-match "^ri$" slant)
		 (setq style (concat style "reverse italic")))
		((string-match "^ro$" slant)
		 (setq style (concat style "reverse slant")))))
      (setq style " ? "))
    (beginning-of-line)
    (insert fontset)
    (indent-to 58)
    (insert (if (> size 0) (format "%2dx%d" size height) "  -"))
    (indent-to 64)
    (insert style "\n")
    (when print-fonts
      (insert "  O Charset / Fontname\n"
	      "  - ------------------\n")
      (sort-charset-list)
      (let ((l charset-list)
	    charset font-info opened fontname)
	(while l
	  (setq charset (car l) l (cdr l))
	  (setq font-info (assq charset fonts))
	  (if (null font-info)
	      (setq opened ?? fontname "not specified")
	    (if (nth 2 font-info)
		(if (stringp (nth 2 font-info))
		    (setq opened ?o fontname (nth 2 font-info))
		  (setq opened ?- fontname (nth 1 font-info)))
	      (setq opened ?x fontname (nth 1 font-info))))
	  (insert (format "  %c %s\n    %s\n"
			  opened charset fontname)))))))

;;;###autoload
(defun describe-fontset (fontset)
  "Display information of FONTSET.
This shows the name, size, and style of FONTSET, and the list of fonts
contained in FONTSET.

The column WDxHT contains width and height (pixels) of each fontset
\(i.e. those of ASCII font in the fontset).  The letter `-' in this
column means that the corresponding fontset is not yet used in any
frame.

The O column for each font contains one of the following letters:
 o -- font already opened
 - -- font not yet opened
 x -- font can't be opened
 ? -- no font specified

The Charset column for each font contains a name of character set
displayed (for this fontset) using that font."
  (interactive
   (if (not (and window-system (boundp 'global-fontset-alist)))
       (error "No fontsets being used")
     (let ((fontset-list (mapcar '(lambda (x) (list x)) (fontset-list)))
	   (completion-ignore-case t))
       (list (completing-read
	      "Fontset (default, used by the current frame): "
	      fontset-list nil t)))))
  (if (= (length fontset) 0)
      (setq fontset (cdr (assq 'font (frame-parameters)))))
  (if (not (query-fontset fontset))
      (error "Current frame is using font, not fontset"))
  (let ((fontset-info (fontset-info fontset)))
    (with-output-to-temp-buffer "*Help*"
      (save-excursion
	(set-buffer standard-output)
	(insert "Fontset-Name\t\t\t\t\t\t  WDxHT Style\n")
	(insert "------------\t\t\t\t\t\t  ----- -----\n")
	(print-fontset fontset t)))))

;;;###autoload
(defun list-fontsets (arg)
  "Display a list of all fontsets.
This shows the name, size, and style of each fontset.
With prefix arg, it also list the fonts contained in each fontset;
see the function `describe-fontset' for the format of the list."
  (interactive "P")
  (if (not (and window-system (boundp 'global-fontset-alist)))
      (error "No fontsets being used")
    (with-output-to-temp-buffer "*Help*"
      (save-excursion
	;; This code is duplicated near the end of mule-diag.
	(set-buffer standard-output)
	(insert "Fontset-Name\t\t\t\t\t\t  WDxHT Style\n")
	(insert "------------\t\t\t\t\t\t  ----- -----\n")
	(let ((fontsets
	       (sort (fontset-list)
		     (function (lambda (x y)
				 (string< (fontset-plain-name x)
					  (fontset-plain-name y)))))))
	  (while fontsets
	    (print-fontset (car fontsets) arg)
	    (setq fontsets (cdr fontsets))))))))

;;;###autoload
(defun list-input-methods ()
  "Display information about all input methods."
  (interactive)
  (with-displaying-help-buffer
   (lambda ()
     (with-current-buffer standard-output
       (list-input-methods-1)))))


(defun list-input-methods-1 ()
  (if (not input-method-alist)
      (progn
	(princ "
No input method is available, perhaps because you have not yet
installed LEIM (Libraries of Emacs Input Method).

LEIM is available from the same ftp directory as Emacs.  For instance,
if there exists an archive file `emacs-20.N.tar.gz', there should also
be a file `leim-20.N.tar.gz'.  When you extract this file, LEIM files
are put under the subdirectory `emacs-20.N/leim'.  When you install
Emacs again, you should be able to use various input methods."))
    (princ "LANGUAGE\n  NAME (`TITLE' in mode line)\n")
    (princ "    SHORT-DESCRIPTION\n------------------------------\n")
    (setq input-method-alist
	  (sort input-method-alist
		(function (lambda (x y) (string< (nth 1 x) (nth 1 y))))))
    (let ((l input-method-alist)
	  language elt)
      (while l
	(setq elt (car l) l (cdr l))
	(when (not (equal language (nth 1 elt)))
	  (setq language (nth 1 elt))
	  (princ language)
	  (terpri))
	(princ (format "  %s (`%s' in mode line)\n    %s\n"
		       (car elt)
		       (let ((title (nth 3 elt)))
			 (if (and (consp title) (stringp (car title)))
			     (car title)
			   title))
		       (let ((description (nth 4 elt)))
			 (string-match ".*" description)
			 (match-string 0 description))))))))

;;; DIAGNOSIS

;; Insert a header of a section with SECTION-NUMBER and TITLE.
(defun insert-section (section-number title)
  (insert "########################################\n"
	  "# Section " (format "%d" section-number) ".  " title "\n"
	  "########################################\n\n"))

;;;###autoload
(defun mule-diag ()
  "Display diagnosis of the multilingual environment (Mule).

This shows various information related to the current multilingual
environment, including lists of input methods, coding systems,
character sets, and fontsets (if Emacs is running under a window
system which uses fontsets)."
  (interactive)
  (with-output-to-temp-buffer "*Mule-Diagnosis*"
    (save-excursion
      (set-buffer standard-output)
      (insert "###############################################\n"
	      "### Current Status of Multilingual Features ###\n"
	      "###############################################\n\n"
	      "CONTENTS: Section 1.  General Information\n"
	      "          Section 2.  Display\n"
	      "          Section 3.  Input methods\n"
	      "          Section 4.  Coding systems\n"
	      "          Section 5.  Character sets\n")
      (if (and window-system (boundp 'global-fontset-alist))
	  (insert "          Section 6.  Fontsets\n"))
      (insert "\n")

      (insert-section 1 "General Information")
      (insert "Version of this emacs:\n  " (emacs-version) "\n\n")

      (insert-section 2 "Display")
      (if window-system
	  (insert "Window-system: "
		  (symbol-name window-system)
		  (format "%s" window-system-version))
	(insert "Terminal: " (getenv "TERM")))
      (insert "\n\n")

      (if (eq window-system 'x)
	  (let ((font (cdr (assq 'font (frame-parameters)))))
	    (insert "The selected frame is using the "
		    (if (query-fontset font) "fontset" "font")
		    ":\n\t" font))
	(insert "Coding system of the terminal: "
		(symbol-name (terminal-coding-system))))
      (insert "\n\n")

      (insert-section 3 "Input methods")
      (list-input-methods-1)
      (insert "\n")
      (if default-input-method
	  (insert "Default input method: " default-input-method "\n")
	(insert "No default input method is specified\n"))

      (insert-section 4 "Coding systems")
      (list-coding-systems-1 t)
      (princ "\
############################
## LIST OF CODING CATEGORIES (ordered by priority)
## CATEGORY:CODING-SYSTEM
##
")
      (let ((l (coding-priority-list)))
	(while l
	  (princ (format "%s:%s\n" (car l) (symbol-value (car l))))
	  (setq l (cdr l))))
      (insert "\n")

      (insert-section 5 "Character sets")
      (list-character-sets-1 t)
      (insert "\n")

      (when (and window-system (boundp 'global-fontset-alist))
	;; This code duplicates most of list-fontsets.
	(insert-section 6 "Fontsets")
	(insert "Fontset-Name\t\t\t\t\t\t  WDxHT Style\n")
	(insert "------------\t\t\t\t\t\t  ----- -----\n")
	(let ((fontsets (fontset-list)))
	  (while fontsets
	    (print-fontset (car fontsets) t)
	    (setq fontsets (cdr fontsets)))))
      (print-help-return-message))))


;;; DUMP DATA FILE

;;;###autoload
(defun dump-charsets ()
  "Dump information about all charsets into the file `CHARSETS'.
The file is saved in the directory `data-directory'."
  (let ((file (expand-file-name "CHARSETS" data-directory))
	buf)
    (or (file-writable-p file)
	(error "Can't write to file %s" file))
    (setq buf (find-file-noselect file))
    (save-window-excursion
      (save-excursion
	(set-buffer buf)
	(setq buffer-read-only nil)
	(erase-buffer)
	(list-character-sets t)
	(insert-buffer-substring "*Help*")
	(let (make-backup-files
	      coding-system-for-write)
	  (save-buffer))))
    (kill-buffer buf))
  (if noninteractive
      (kill-emacs)))

;;;###autoload
(defun dump-codings ()
  "Dump information about all coding systems into the file `CODINGS'.
The file is saved in the directory `data-directory'."
  (let ((file (expand-file-name "CODINGS" data-directory))
	buf)
    (or (file-writable-p file)
	(error "Can't write to file %s" file))
    (setq buf (find-file-noselect file))
    (save-window-excursion
      (save-excursion
	(set-buffer buf)
	(setq buffer-read-only nil)
	(erase-buffer)
	(list-coding-systems t)
	(insert-buffer-substring "*Help*")
	(list-coding-categories)
	(insert-buffer-substring "*Help*")
	(let (make-backup-files
	      coding-system-for-write)
	  (save-buffer))))
    (kill-buffer buf))
  (if noninteractive
      (kill-emacs)))

;;; mule-diag.el ends here
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.