aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/international/mule-diag.el329
1 files changed, 189 insertions, 140 deletions
diff --git a/lisp/international/mule-diag.el b/lisp/international/mule-diag.el
index 5b5304cdce4..523ff7e260b 100644
--- a/lisp/international/mule-diag.el
+++ b/lisp/international/mule-diag.el
@@ -128,34 +128,27 @@
128(defun describe-coding-system (coding-system) 128(defun describe-coding-system (coding-system)
129 "Display information of CODING-SYSTEM." 129 "Display information of CODING-SYSTEM."
130 (interactive "zCoding-system: ") 130 (interactive "zCoding-system: ")
131 (check-coding-system coding-system)
132 (with-output-to-temp-buffer "*Help*" 131 (with-output-to-temp-buffer "*Help*"
133 (let ((coding-vector (coding-system-vector coding-system))) 132 (print-coding-system-briefly coding-system nil 'doc-string)
134 (princ "Coding-system ") 133 (let ((coding-spec (coding-system-spec coding-system)))
135 (princ coding-system) 134 (princ "Type: ")
136 (princ " [") 135 (let ((type (coding-system-type coding-system))
137 (princ (char-to-string (coding-vector-mnemonic coding-vector))) 136 (flags (coding-system-flags coding-system)))
138 (princ "]: \n")
139 (princ " ")
140 (princ (coding-vector-docstring coding-vector))
141 (princ "\nType: ")
142 (let ((type (coding-vector-type coding-vector))
143 (flags (coding-vector-flags coding-vector)))
144 (princ type) 137 (princ type)
145 (princ ", which means ") 138 (princ " (")
146 (cond ((eq type nil) 139 (cond ((eq type nil)
147 (princ "do no conversion.")) 140 (princ "do no conversion)"))
148 ((eq type t) 141 ((eq type t)
149 (princ "do automatic conversion.")) 142 (princ "do automatic conversion)"))
150 ((eq type 0) 143 ((eq type 0)
151 (princ "Emacs internal multibyte form.")) 144 (princ "Emacs internal multibyte form)"))
152 ((eq type 1) 145 ((eq type 1)
153 (princ "Shift-JIS (MS-KANJI).")) 146 (princ "Shift-JIS, MS-KANJI)"))
154 ((eq type 2) 147 ((eq type 2)
155 (princ "a variant of ISO-2022.\n") 148 (princ "variant of ISO-2022)\n")
156 (princ "Initial designations:\n") 149 (princ "Initial designations:\n")
157 (print-designation flags) 150 (print-designation flags)
158 (princ "Other Form: \n") 151 (princ "Other Form: \n ")
159 (princ (if (aref flags 4) "short-form" "long-form")) 152 (princ (if (aref flags 4) "short-form" "long-form"))
160 (if (aref flags 5) (princ ", ASCII@EOL")) 153 (if (aref flags 5) (princ ", ASCII@EOL"))
161 (if (aref flags 6) (princ ", ASCII@CNTL")) 154 (if (aref flags 6) (princ ", ASCII@CNTL"))
@@ -171,10 +164,10 @@
171 ((eq type 4) 164 ((eq type 4)
172 (princ "do conversion by CCL program.")) 165 (princ "do conversion by CCL program."))
173 (t (princ "invalid coding-system.")))) 166 (t (princ "invalid coding-system."))))
174 (princ "\nEOL-Type: ") 167 (princ "\nEOL type:\n ")
175 (let ((eol-type (coding-system-eoltype coding-system))) 168 (let ((eol-type (coding-system-eol-type coding-system)))
176 (cond ((vectorp eol-type) 169 (cond ((vectorp eol-type)
177 (princ "Automatic selection from ") 170 (princ "Automatic selection from:\n\t")
178 (princ eol-type) 171 (princ eol-type)
179 (princ "\n")) 172 (princ "\n"))
180 ((or (null eol-type) (eq eol-type 0)) (princ "LF\n")) 173 ((or (null eol-type) (eq eol-type 0)) (princ "LF\n"))
@@ -185,53 +178,73 @@
185 178
186;;;###autoload 179;;;###autoload
187(defun describe-current-coding-system-briefly () 180(defun describe-current-coding-system-briefly ()
188 "Display coding systems currently used in a brief format in mini-buffer. 181 "Display coding systems currently used in a brief format in echo area.
189 182
190The format is \"current: [FKTPp=........] default: [FPp=......]\", 183The format is \"F[..],K[..],T[..],P>[..],P<[..], default F[..],P<[..],P<[..]\",
191where mnemonics of the following coding systems come in this order 184where mnemonics of the following coding systems come in this order
192at the place of `...': 185at the place of `..':
193 buffer-file-coding-system (of the current buffer) 186 buffer-file-coding-system (of the current buffer)
194 eol-type of buffer-file-coding-system (of the current buffer) 187 eol-type of buffer-file-coding-system (of the current buffer)
195 keyboard-coding-system 188 (keyboard-coding-system)
189 eol-type of (keyboard-coding-system)
196 terminal-coding-system 190 terminal-coding-system
191 eol-type of (terminal-coding-system)
197 process-coding-system for read (of the current buffer, if any) 192 process-coding-system for read (of the current buffer, if any)
198 eol-type of process-coding-system for read (of the current buffer, if any) 193 eol-type of process-coding-system for read (of the current buffer, if any)
199 process-coding-system for write (of the current buffer, if any) 194 process-coding-system for write (of the current buffer, if any)
200 eol-type of process-coding-system for write (of the current buffer, if any) 195 eol-type of process-coding-system for write (of the current buffer, if any)
201 default buffer-file-coding-system 196 default-buffer-file-coding-system
202 eol-type of default buffer-file-coding-system 197 eol-type of default-buffer-file-coding-system
203 default process-coding-system for read 198 default-process-coding-system for read
204 default eol-type of process-coding-system for read 199 eol-type of default-process-coding-system for read
205 default process-coding-system for write 200 default-process-coding-system for write
206 default eol-type of process-coding-system" 201 eol-type of default-process-coding-system"
207 (interactive) 202 (interactive)
208 (let* ((proc (get-buffer-process (current-buffer))) 203 (let* ((proc (get-buffer-process (current-buffer)))
209 (process-coding-systems (if proc (process-coding-system proc)))) 204 (process-coding-systems (if proc (process-coding-system proc))))
210 (message 205 (message
211 "current: [FKTPp=%c%c%c%c%c%c%c%c] default: [FPp=%c%c%c%c%c%c]" 206 "F[%c%c],K[%c%c],T[%c%c],P>[%c%c],P<[%c%c], default F[%c%c],P>[%c%c],P<[%c%c]"
212 (coding-system-mnemonic buffer-file-coding-system) 207 (coding-system-mnemonic buffer-file-coding-system)
213 (coding-system-eoltype-mnemonic buffer-file-coding-system) 208 (coding-system-eol-type-mnemonic buffer-file-coding-system)
214 (coding-system-mnemonic (keyboard-coding-system)) 209 (coding-system-mnemonic (keyboard-coding-system))
210 (coding-system-eol-type-mnemonic (keyboard-coding-system))
215 (coding-system-mnemonic (terminal-coding-system)) 211 (coding-system-mnemonic (terminal-coding-system))
212 (coding-system-eol-type-mnemonic (terminal-coding-system))
216 (coding-system-mnemonic (car process-coding-systems)) 213 (coding-system-mnemonic (car process-coding-systems))
217 (coding-system-eoltype-mnemonic (car process-coding-systems)) 214 (coding-system-eol-type-mnemonic (car process-coding-systems))
218 (coding-system-mnemonic (cdr process-coding-systems)) 215 (coding-system-mnemonic (cdr process-coding-systems))
219 (coding-system-eoltype-mnemonic (cdr process-coding-systems)) 216 (coding-system-eol-type-mnemonic (cdr process-coding-systems))
220 (coding-system-mnemonic (default-value 'buffer-file-coding-system)) 217 (coding-system-mnemonic default-buffer-file-coding-system)
221 (coding-system-eoltype-mnemonic (default-value 'buffer-file-coding-system)) 218 (coding-system-eol-type-mnemonic default-buffer-file-coding-system)
222 (coding-system-mnemonic (car default-process-coding-system)) 219 (coding-system-mnemonic (car default-process-coding-system))
223 (coding-system-eoltype-mnemonic (car default-process-coding-system)) 220 (coding-system-eol-type-mnemonic (car default-process-coding-system))
224 (coding-system-mnemonic (cdr default-process-coding-system)) 221 (coding-system-mnemonic (cdr default-process-coding-system))
225 (coding-system-eoltype-mnemonic (cdr default-process-coding-system)) 222 (coding-system-eol-type-mnemonic (cdr default-process-coding-system))
226 ))) 223 )))
227 224
228;; Print symbol name and mnemonics of CODING-SYSTEM by `princ'. 225;; Print symbol name and mnemonic letter of CODING-SYSTEM by `princ'.
229(defsubst print-coding-system-briefly (coding-system) 226(defun print-coding-system-briefly (coding-system &optional aliases doc-string)
230 (print-list ":" 227 (if (not coding-system)
231 coding-system 228 (princ "nil\n")
232 (format "[%c%c]" 229 (princ (format "%c -- %s"
233 (coding-system-mnemonic coding-system) 230 (coding-system-mnemonic coding-system)
234 (coding-system-eoltype-mnemonic coding-system)))) 231 coding-system))
232 (if aliases
233 (progn
234 (princ (format " (alias: %s" (car aliases)))
235 (setq aliases (cdr aliases))
236 (while aliases
237 (princ " ")
238 (princ (car aliases))
239 (setq aliases (cdr aliases)))
240 (princ ")"))
241 (let ((base (coding-system-base coding-system)))
242 (if (not (eq base coding-system))
243 (princ (format " (alias of %s)" base)))))
244 (princ "\n")
245 (if (and doc-string
246 (setq doc-string (coding-system-doc-string coding-system)))
247 (princ (format " %s\n" doc-string)))))
235 248
236;;;###autoload 249;;;###autoload
237(defun describe-current-coding-system () 250(defun describe-current-coding-system ()
@@ -240,96 +253,140 @@ at the place of `...':
240 (with-output-to-temp-buffer "*Help*" 253 (with-output-to-temp-buffer "*Help*"
241 (let* ((proc (get-buffer-process (current-buffer))) 254 (let* ((proc (get-buffer-process (current-buffer)))
242 (process-coding-systems (if proc (process-coding-system proc)))) 255 (process-coding-systems (if proc (process-coding-system proc))))
243 (princ "Current:\n buffer-file-coding-system") 256 (princ "Current buffer file: buffer-file-coding-system\n ")
244 (print-coding-system-briefly buffer-file-coding-system) 257 (if (local-variable-p 'buffer-file-coding-system)
245 (princ " keyboard-coding-system") 258 (print-coding-system-briefly buffer-file-coding-system)
259 (princ "Not set locally, use the following default.\n"))
260 (princ "Default buffer file: default-buffer-file-coding-system\n ")
261 (print-coding-system-briefly default-buffer-file-coding-system)
262 (princ "Keyboard: (keyboard-coding-system)\n ")
246 (print-coding-system-briefly (keyboard-coding-system)) 263 (print-coding-system-briefly (keyboard-coding-system))
247 (princ " terminal-coding-system") 264 (princ "Terminal: (display-coding-system)\n ")
248 (print-coding-system-briefly (terminal-coding-system)) 265 (print-coding-system-briefly (terminal-coding-system))
249 (if process-coding-systems 266 (princ "Current buffer process: (process-coding-system)\n")
250 (progn (princ " process-coding-system (read)") 267 (if (not process-coding-systems)
251 (print-coding-system-briefly (car process-coding-systems)) 268 (princ " No process.\n")
252 (princ " process-coding-system (write)") 269 (princ " decoding: ")
253 (print-coding-system-briefly (cdr process-coding-systems)))) 270 (print-coding-system-briefly (car process-coding-systems))
254 (princ "Default:\n buffer-file-coding-system") 271 (princ " encoding: ")
255 (print-coding-system-briefly (default-value 'buffer-file-coding-system)) 272 (print-coding-system-briefly (cdr process-coding-systems)))
256 (princ " process-coding-system (read)") 273 (princ "Default process: default-process-coding-system\n")
274 (princ " decoding: ")
257 (print-coding-system-briefly (car default-process-coding-system)) 275 (print-coding-system-briefly (car default-process-coding-system))
258 (princ " process-coding-system (write)") 276 (princ " encoding: ")
259 (print-coding-system-briefly (cdr default-process-coding-system)) 277 (print-coding-system-briefly (cdr default-process-coding-system)))
260 (princ "coding-system-alist:\n") 278 (princ "\nCoding categories (in the order of priority):\n")
261 (pp coding-system-alist))
262 (let ((l coding-category-list)) 279 (let ((l coding-category-list))
263 (princ "\nCoding categories (in the order of priority):\n")
264 (while l 280 (while l
265 (princ (format "%s -> %s\n" (car l) (symbol-value (car l)))) 281 (princ (format " %-27s -> %s\n" (car l) (symbol-value (car l))))
266 (setq l (cdr l)))))) 282 (setq l (cdr l))))
283 (princ "\nLook up tables for finding a coding system on I/O operations:\n")
284 (let ((func (lambda (title alist)
285 (princ title)
286 (if (not alist)
287 (princ " Nothing specified.\n")
288 (while alist
289 (princ (format " %-27s -> %s\n"
290 (concat "\"" (car (car alist)) "\"")
291 (cdr (car alist))))
292 (setq alist (cdr alist)))))))
293 (funcall func " File I/O (FILENAME -> CODING-SYSTEM):\n"
294 file-coding-system-alist)
295 (funcall func " Process I/O (PROGRAM-NAME -> CODING-SYSTEM):\n"
296 process-coding-system-alist)
297 (funcall func " Network stream I/O (SERVICE-NAME -> CODING-SYSTEM):\n"
298 network-coding-system-alist))
299 ))
267 300
268;; Print detailed information on CODING-SYSTEM. 301;; Print detailed information on CODING-SYSTEM.
269(defun print-coding-system (coding-system) 302(defun print-coding-system (coding-system &optional aliases)
270 (let ((type (coding-system-type coding-system)) 303 (let ((type (coding-system-type coding-system))
271 (eol-type (coding-system-eoltype coding-system)) 304 (eol-type (coding-system-eol-type coding-system))
272 (flags (coding-system-flags coding-system))) 305 (flags (coding-system-flags coding-system))
273 (princ (format "%s:%s:%c:%d:" 306 (base (coding-system-base coding-system)))
274 coding-system 307 (if (not (eq base coding-system))
275 type 308 (princ (format "%s (alias of %s)\n" coding-system base))
276 (coding-system-mnemonic coding-system) 309 (princ coding-system)
277 (if (integerp eol-type) eol-type 3))) 310 (while aliases
278 (cond ((eq type 2) ; ISO-2022 311 (progn
279 (let ((idx 0) 312 (princ ",")
280 charset) 313 (princ (car aliases))
281 (while (< idx 4) 314 (setq aliases (cdr aliases))))
282 (setq charset (aref flags idx)) 315 (princ (format ":%s:%c:%d:"
283 (cond ((null charset) 316 type
284 (princ -1)) 317 (coding-system-mnemonic coding-system)
285 ((eq charset t) 318 (if (integerp eol-type) eol-type 3)))
286 (princ -2)) 319 (cond ((eq type 2) ; ISO-2022
287 ((charsetp charset) 320 (let ((idx 0)
288 (princ charset)) 321 charset)
289 ((listp charset) 322 (while (< idx 4)
290 (princ "(") 323 (setq charset (aref flags idx))
291 (princ (car charset)) 324 (cond ((null charset)
292 (setq charset (cdr charset)) 325 (princ -1))
293 (while charset 326 ((eq charset t)
294 (princ ",") 327 (princ -2))
328 ((charsetp charset)
329 (princ charset))
330 ((listp charset)
331 (princ "(")
295 (princ (car charset)) 332 (princ (car charset))
296 (setq charset (cdr charset))) 333 (setq charset (cdr charset))
297 (princ ")"))) 334 (while charset
335 (princ ",")
336 (princ (car charset))
337 (setq charset (cdr charset)))
338 (princ ")")))
339 (princ ",")
340 (setq idx (1+ idx)))
341 (while (< idx 12)
342 (princ (if (aref flags idx) 1 0))
343 (princ ",")
344 (setq idx (1+ idx)))
345 (princ (if (aref flags idx) 1 0))))
346 ((eq type 4) ; CCL
347 (let (i len)
348 (setq i 0 len (length (car flags)))
349 (while (< i len)
350 (princ (format " %x" (aref (car flags) i)))
351 (setq i (1+ i)))
298 (princ ",") 352 (princ ",")
299 (setq idx (1+ idx))) 353 (setq i 0 len (length (cdr flags)))
300 (while (< idx 12) 354 (while (< i len)
301 (princ (if (aref flags idx) 1 0)) 355 (princ (format " %x" (aref (cdr flags) i)))
302 (princ ",") 356 (setq i (1+ i)))))
303 (setq idx (1+ idx))) 357 (t (princ 0)))
304 (princ (if (aref flags idx) 1 0)))) 358 (princ ":")
305 ((eq type 4) ; CCL 359 (princ (coding-system-doc-string coding-system))
306 (let (i len) 360 (princ "\n"))))
307 (setq i 0 len (length (car flags)))
308 (while (< i len)
309 (princ (format " %x" (aref (car flags) i)))
310 (setq i (1+ i)))
311 (princ ",")
312 (setq i 0 len (length (cdr flags)))
313 (while (< i len)
314 (princ (format " %x" (aref (cdr flags) i)))
315 (setq i (1+ i)))))
316 (t (princ 0)))
317 (princ ":")
318 (princ (coding-system-docstring coding-system))
319 (princ "\n")))
320 361
362;;;###autoload
321(defun list-coding-systems () 363(defun list-coding-systems ()
322 "Print information on all coding systems in a machine readable format." 364 "Print information of all base coding systems.
365If called interactive, it prints name, mnemonic letter, and doc-string
366of each coding system.
367If not, it prints whole information of each coding system
368with the format which is more suitable for being read by a machine."
369 (interactive)
323 (with-output-to-temp-buffer "*Help*" 370 (with-output-to-temp-buffer "*Help*"
324 (princ "\ 371 (if (interactive-p)
372 (princ "\
373###############################################
374# List of coding systems in the following format:
375# MNEMONIC-LETTER -- CODING-SYSTEM-NAME
376# DOC-STRING
377")
378 (princ "\
325######################### 379#########################
326## LIST OF CODING SYSTEMS 380## LIST OF CODING SYSTEMS
327## Each line corresponds to one coding system 381## Each line corresponds to one coding system
328## Format of a line is: 382## Format of a line is:
329## NAME:TYPE:MNEMONIC:EOL:FLAGS:DOCSTRING, 383## NAME[,ALIAS...]:TYPE:MNEMONIC:EOL:FLAGS:POST-READ-CONVERSION
384## :PRE-WRITE-CONVERSION:DOC-STRING,
330## where 385## where
331## TYPE = nil (no conversion), t (auto conversion), 386## NAME = coding system name
332## 0 (Mule internal), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL) 387## ALIAS = alias of the coding system
388## TYPE = nil (no conversion), t (undecided or automatic detection),
389## 0 (EMACS-MULE), 1 (SJIS), 2 (ISO2022), 3 (BIG5), or 4 (CCL)
333## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection) 390## EOL = 0 (LF), 1 (CRLF), 2 (CR), or 3 (Automatic detection)
334## FLAGS = 391## FLAGS =
335## if TYPE = 2 then 392## if TYPE = 2 then
@@ -340,28 +397,19 @@ at the place of `...':
340## comma (`,') separated CCL programs for read and write 397## comma (`,') separated CCL programs for read and write
341## else 398## else
342## 0 399## 0
400## POST-READ-CONVERSION, PRE-WRITE-CONVERSION = function name to be called
343## 401##
344") 402"))
345 (let ((codings (make-vector 7 nil))) 403 (let ((bases (coding-system-list 'base-only))
346 (mapatoms 404 base coding-system aliases)
347 (function 405 (while bases
348 (lambda (arg) 406 (setq base (car bases) bases (cdr bases))
349 (if (and arg 407 (if (consp base)
350 (coding-system-p arg) 408 (setq coding-system (car base) aliases (cdr base))
351 (null (get arg 'pre-write-conversion)) 409 (setq coding-system base aliases nil))
352 (null (get arg 'post-read-conversion))) 410 (if (interactive-p)
353 (let* ((type (coding-system-type arg)) 411 (print-coding-system-briefly coding-system aliases 'doc-string)
354 (idx (if (null type) 0 (if (eq type t) 1 (+ type 2))))) 412 (print-coding-system coding-system aliases))))
355 (if (or (= idx 0)
356 (vectorp (coding-system-eoltype arg)))
357 (aset codings idx (cons arg (aref codings idx)))))))))
358 (let ((idx 0) elt)
359 (while (< idx 7)
360 (setq elt (aref codings idx))
361 (while elt
362 (print-coding-system (car elt))
363 (setq elt (cdr elt)))
364 (setq idx (1+ idx)))))
365 (princ "\ 413 (princ "\
366############################ 414############################
367## LIST OF CODING CATEGORIES (ordered by priority) 415## LIST OF CODING CATEGORIES (ordered by priority)
@@ -564,3 +612,4 @@ at the place of `...':
564 (write-region (point-min) (point-max) "codings.dat")) 612 (write-region (point-min) (point-max) "codings.dat"))
565 (kill-emacs)) 613 (kill-emacs))
566 614
615;;; mule-diag.el ends here