mule-diag.el 42 KB

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