comparison lisp/international/mule.el @ 20112:6e6838a12511

The summary of the following changes: (1) Make all coding systems (including aliases and subsidiaries) directly have coding-spec vector in `coding-system' property. (2) Properties of a coding system (except for `coding-system' and `eol-type') is embeded in PLIST slot of coding-spec vector. (coding-spec-plist-idx): Initialize to 3. (coding-system-spec-ref): Deleted. (coding-system-spec): Moved from src/coding.c. (coding-system-type): Adjusted for the above change. (coding-system-mnemonic): Likewise. (coding-system-doc-string): Likewise. (coding-system-flags): Likewise. (coding-system-eol-type): Likewise. (coding-system-category): Likewise. (coding-system-get, coding-system-put, coding-system-category): New functions. (coding-system-base): Moved from mule-util.el and adjusted for the above change. (coding-system-parent): Make it obsolete alias of coding-system-base. (make-subsidiary-coding-system): Adjusted for the above change. Update coding-system-list and coding-system-alist. (make-coding-system): Likewise. (set-buffer-file-coding-system): Typo in doc-string fixed. (after-insert-file-set-buffer-file-coding-system): Change enable-multibyte-characters only when find-new-buffer-file-coding-system returns non-nil value. (find-new-buffer-file-coding-system): Adjusted for the abobe change.
author Kenichi Handa <handa@m17n.org>
date Tue, 21 Oct 1997 10:47:35 +0000
parents cc81b9c8ae20
children 0d9c6ccdc45c
comparison
equal deleted inserted replaced
20111:761a83f7cb4e 20112:6e6838a12511
245 See also the documentation of make-char." 245 See also the documentation of make-char."
246 (let ((l (split-char char))) 246 (let ((l (split-char char)))
247 (and (or (= (nth 1 l) 0) (eq (nth 2 l) 0)) 247 (and (or (= (nth 1 l) 0) (eq (nth 2 l) 0))
248 (not (eq (car l) 'composition))))) 248 (not (eq (car l) 'composition)))))
249 249
250
250 ;; Coding system staffs 251 ;; Coding system staffs
251 252
252 ;; Coding system is a symbol that has the property `coding-system'. 253 ;; Coding system is a symbol that has the property `coding-system'.
253 ;; 254 ;;
254 ;; The value of the property `coding-system' is a vector of the 255 ;; The value of the property `coding-system' is a vector of the
258 ;; for more detail. 259 ;; for more detail.
259 260
260 (defconst coding-spec-type-idx 0) 261 (defconst coding-spec-type-idx 0)
261 (defconst coding-spec-mnemonic-idx 1) 262 (defconst coding-spec-mnemonic-idx 1)
262 (defconst coding-spec-doc-string-idx 2) 263 (defconst coding-spec-doc-string-idx 2)
263 (defconst coding-spec-plist-idx 2) 264 (defconst coding-spec-plist-idx 3)
264 (defconst coding-spec-flags-idx 4) 265 (defconst coding-spec-flags-idx 4)
265 266
266 ;; Coding system may have property `eol-type'. The value of the 267 ;; PLIST is a property list of a coding system. A coding system has
267 ;; property `eol-type' is integer 0..2 or a vector of three coding 268 ;; PLIST in coding-spec instead of having it in normal proper list of
268 ;; systems. The integer value 0, 1, and 2 indicate the format of 269 ;; Lisp symbol to share PLIST among alias coding systems. Here's a
269 ;; end-of-line LF, CRLF, and CR respectively. The vector value 270 ;; list of properties to be held in PLIST.
271 ;;
272 ;; o coding-category
273 ;;
274 ;; The value is a coding category the coding system belongs to. The
275 ;; function `make-coding-system' and `define-coding-system-alias' sets
276 ;; this value automatically.
277 ;;
278 ;; o alias-coding-systems
279 ;;
280 ;; The value is a list of coding systems of the same alias group. The
281 ;; first element is the coding system made at first, which we call as
282 ;; `base coding system'. The function `make-coding-system' and
283 ;; `define-coding-system-alias' set this value automatically.
284 ;;
285 ;; o post-read-conversion
286 ;;
287 ;; The value is a function to call after some text is inserted and
288 ;; decoded by the coding system itself and before any functions in
289 ;; `after-insert-functions' are called. The arguments to this
290 ;; function is the same as those of a function in
291 ;; `after-insert-functions', i.e. LENGTH of a text while putting point
292 ;; at the head of the text to be decoded
293 ;;
294 ;; o pre-write-conversion
295 ;;
296 ;; The value is a function to call after all functions in
297 ;; `write-region-annotate-functions' and `buffer-file-format' are
298 ;; called, and before the text is encoded by the coding system itself.
299 ;; The arguments to this function is the same as those of a function
300 ;; in `write-region-annotate-functions', i.e. FROM and TO specifying
301 ;; region of a text.
302 ;;
303 ;; o character-unification-table-for-decode
304 ;;
305 ;; The value is a unification table to be applied on decoding. See
306 ;; the function `make-unification-table' for the format of unification
307 ;; table.
308 ;;
309 ;; o character-unification-table-for-encode
310 ;;
311 ;; The value is a unification table to be applied on encoding.
312
313 ;; Return coding-spec of CODING-SYSTEM
314 (defsubst coding-system-spec (coding-system)
315 (get (check-coding-system coding-system) 'coding-system))
316
317 (defun coding-system-type (coding-system)
318 "Return the coding type of CODING-SYSTEM.
319 A coding type is an integer value indicating the encoding method
320 of CODING-SYSTEM. See the function `make-coding-system' for more detail."
321 (aref (coding-system-spec coding-system) coding-spec-type-idx))
322
323 (defun coding-system-mnemonic (coding-system)
324 "Return the mnemonic character of CODING-SYSTEM.
325 A mnemonic character of a coding system is used in mode line
326 to indicate the coding system."
327 (or (aref (coding-system-spec coding-system) coding-spec-mnemonic-idx)
328 ?-))
329
330 (defun coding-system-doc-string (coding-system)
331 "Return the documentation string for CODING-SYSTEM."
332 (aref (coding-system-spec coding-system) coding-spec-doc-string-idx))
333
334 (defun coding-system-plist (coding-system)
335 "Return the property list of CODING-SYSTEM."
336 (aref (coding-system-spec coding-system) coding-spec-plist-idx))
337
338 (defun coding-system-flags (coding-system)
339 "Return `flags' of CODING-SYSTEM.
340 A `flags' of a coding system is a vector of length 32 indicating detailed
341 information of a coding system. See the function `make-coding-system'
342 for more detail."
343 (aref (coding-system-spec coding-system) coding-spec-flags-idx))
344
345 (defun coding-system-get (coding-system prop)
346 "Extract a value from CODING-SYSTEM's property list for property PROP."
347 (plist-get (coding-system-plist coding-system) prop))
348
349 (defun coding-system-put (coding-system prop val)
350 "Change value in CODING-SYSTEM's property list PROP to VAL."
351 (let ((plist (coding-system-plist coding-system)))
352 (if plist
353 (plist-put plist prop val)
354 (aset (coding-system-spec coding-system) coding-spec-plist-idx
355 (list prop val)))))
356
357 (defun coding-system-category (coding-system)
358 "Return the coding category of CODING-SYSTEM."
359 (coding-system-get coding-system 'coding-category))
360
361 (defun coding-system-base (coding-system)
362 "Return the base coding system of CODING-SYSTEM.
363 A base coding system is what made by `make-coding-system',
364 not what made by `define-coding-system-alias'."
365 (car (coding-system-get coding-system 'alias-coding-systems)))
366
367 (defalias 'coding-system-parent 'coding-system-base)
368 (make-obsolete 'coding-system-parent 'coding-system-base)
369
370 ;; Coding system also has a property `eol-type'.
371 ;;
372 ;; This property indicates how the coding system handles end-of-line
373 ;; format. The value is integer 0, 1, 2, or a vector of three coding
374 ;; systems. Each integer value 0, 1, and 2 indicates the format of
375 ;; end-of-line LF, CRLF, and CR respectively. A vector value
270 ;; indicates that the format of end-of-line should be detected 376 ;; indicates that the format of end-of-line should be detected
271 ;; automatically. Nth element of the vector is the subsidiary coding 377 ;; automatically. Nth element of the vector is the subsidiary coding
272 ;; system whose `eol-type' property is N. 378 ;; system whose `eol-type' property is N.
273 ;;
274 ;; Coding system may also have properties `post-read-conversion' and
275 ;; `pre-write-conversion. Values of these properties are functions.
276 ;;
277 ;; The function in `post-read-conversion' is called after some text is
278 ;; inserted and decoded along the coding system and before any
279 ;; functions in `after-insert-functions' are called. The arguments to
280 ;; this function is the same as those of a function in
281 ;; `after-insert-functions', i.e. LENGTH of a text while putting point
282 ;; at the head of the text to be decoded
283 ;;
284 ;; The function in `pre-write-conversion' is called after all
285 ;; functions in `write-region-annotate-functions' and
286 ;; `buffer-file-format' are called, and before the text is encoded by
287 ;; the coding system. The arguments to this function is the same as
288 ;; those of a function in `write-region-annotate-functions', i.e. FROM
289 ;; and TO specifying region of a text.
290
291 ;; Return Nth element of coding-spec of CODING-SYSTEM.
292 (defun coding-system-spec-ref (coding-system n)
293 (check-coding-system coding-system)
294 (let ((vec (coding-system-spec coding-system)))
295 (and vec (aref vec n))))
296
297 (defun coding-system-type (coding-system)
298 "Return TYPE element in coding-spec of CODING-SYSTEM."
299 (coding-system-spec-ref coding-system coding-spec-type-idx))
300
301 (defun coding-system-mnemonic (coding-system)
302 "Return MNEMONIC element in coding-spec of CODING-SYSTEM."
303 (or (coding-system-spec-ref coding-system coding-spec-mnemonic-idx)
304 ?-))
305
306 (defun coding-system-doc-string (coding-system)
307 "Return DOC-STRING element in coding-spec of CODING-SYSTEM."
308 (coding-system-spec-ref coding-system coding-spec-doc-string-idx))
309
310 (defun coding-system-plist (coding-system)
311 "Return PLIST element in coding-spec of CODING-SYSTEM."
312 (coding-system-spec-ref coding-system coding-spec-plist-idx))
313
314 (defun coding-system-flags (coding-system)
315 "Return FLAGS element in coding-spec of CODING-SYSTEM."
316 (coding-system-spec-ref coding-system coding-spec-flags-idx))
317 379
318 (defun coding-system-eol-type (coding-system) 380 (defun coding-system-eol-type (coding-system)
319 "Return eol-type property of CODING-SYSTEM." 381 "Return eol-type of CODING-SYSTEM.
320 (check-coding-system coding-system) 382 An eol-type is integer 0, 1, 2, or a vector of coding systems.
321 (and coding-system 383
322 (or (get coding-system 'eol-type) 384 Integer values 0, 1, and 2 indicate a format of end-of-line; LF,
323 (coding-system-eol-type (get coding-system 'coding-system))))) 385 CRLF, and CR respectively.
324 386
325 (defun coding-system-category (coding-system) 387 A vector value indicates that a format of end-of-line should be
326 "Return coding category of CODING-SYSTEM." 388 detected automatically. Nth element of the vector is the subsidiary
327 (and coding-system 389 coding system whose eol-type is N."
328 (symbolp coding-system) 390 (get coding-system 'eol-type))
329 (or (get coding-system 'coding-category)
330 (coding-system-category (get coding-system 'coding-system)))))
331
332 (defun coding-system-parent (coding-system)
333 "Return parent of CODING-SYSTEM."
334 (let ((parent (get coding-system 'parent-coding-system)))
335 (and parent
336 (or (coding-system-parent parent)
337 parent))))
338 391
339 ;; Make subsidiary coding systems (eol-type variants) of CODING-SYSTEM. 392 ;; Make subsidiary coding systems (eol-type variants) of CODING-SYSTEM.
340 (defun make-subsidiary-coding-system (coding-system) 393 (defun make-subsidiary-coding-system (coding-system)
341 (let ((subsidiaries (vector (intern (format "%s-unix" coding-system)) 394 (let ((coding-spec (coding-system-spec coding-system))
395 (subsidiaries (vector (intern (format "%s-unix" coding-system))
342 (intern (format "%s-dos" coding-system)) 396 (intern (format "%s-dos" coding-system))
343 (intern (format "%s-mac" coding-system)))) 397 (intern (format "%s-mac" coding-system))))
344 (i 0)) 398 (i 0)
399 temp)
345 (while (< i 3) 400 (while (< i 3)
346 (put (aref subsidiaries i) 'coding-system coding-system) 401 (put (aref subsidiaries i) 'coding-system coding-spec)
347 (put (aref subsidiaries i) 'eol-type i) 402 (put (aref subsidiaries i) 'eol-type i)
348 (put (aref subsidiaries i) 'eol-variant t) 403 (setq coding-system-list
404 (cons (aref subsidiaries i) coding-system-list))
405 (setq coding-system-alist
406 (cons (list (symbol-name (aref subsidiaries i)))
407 coding-system-alist))
349 (setq i (1+ i))) 408 (setq i (1+ i)))
350 subsidiaries)) 409 subsidiaries))
351 410
352 (defun make-coding-system (coding-system type mnemonic doc-string 411 (defun make-coding-system (coding-system type mnemonic doc-string
353 &optional flags) 412 &optional flags)
354 "Define a new CODING-SYSTEM (symbol). 413 "Define a new CODING-SYSTEM (symbol).
355 Remaining arguments are TYPE, MNEMONIC, DOC-STRING, and FLAGS (optional) which 414 Remaining arguments are TYPE, MNEMONIC, DOC-STRING, and FLAGS (optional) which
356 construct a coding-spec of CODING-SYSTEM in the following format: 415 construct a coding-spec of CODING-SYSTEM in the following format:
357 [TYPE MNEMONIC DOC-STRING nil FLAGS] 416 [TYPE MNEMONIC DOC-STRING PLIST FLAGS]
358 TYPE is an integer value indicating the type of coding-system as follows: 417 TYPE is an integer value indicating the type of coding-system as follows:
359 0: Emacs internal format, 418 0: Emacs internal format,
360 1: Shift-JIS (or MS-Kanji) used mainly on Japanese PC, 419 1: Shift-JIS (or MS-Kanji) used mainly on Japanese PC,
361 2: ISO-2022 including many variants, 420 2: ISO-2022 including many variants,
362 3: Big5 used mainly on Chinese PC, 421 3: Big5 used mainly on Chinese PC,
363 4: private, CCL programs provide encoding/decoding algorithm, 422 4: private, CCL programs provide encoding/decoding algorithm,
364 5: Raw-text, which means that text contains random 8-bit codes. 423 5: Raw-text, which means that text contains random 8-bit codes.
424
365 MNEMONIC is a character to be displayed on mode line for the coding-system. 425 MNEMONIC is a character to be displayed on mode line for the coding-system.
426
366 DOC-STRING is a documentation string for the coding-system. 427 DOC-STRING is a documentation string for the coding-system.
428
429 PLIST is the propert list for CODING-SYSTEM. This function sets
430 properties coding-category and alias-coding-systems.
431
367 FLAGS specifies more precise information of each TYPE. 432 FLAGS specifies more precise information of each TYPE.
368 433
369 If TYPE is 2 (ISO-2022), FLAGS should be a list of: 434 If TYPE is 2 (ISO-2022), FLAGS should be a list of:
370 CHARSET0, CHARSET1, CHARSET2, CHARSET3, SHORT-FORM, 435 CHARSET0, CHARSET1, CHARSET2, CHARSET3, SHORT-FORM,
371 ASCII-EOL, ASCII-CNTL, SEVEN, LOCKING-SHIFT, SINGLE-SHIFT, 436 ASCII-EOL, ASCII-CNTL, SEVEN, LOCKING-SHIFT, SINGLE-SHIFT,
397 code of the coding system. 462 code of the coding system.
398 463
399 If TYPE is 4 (private), FLAGS should be a cons of CCL programs, 464 If TYPE is 4 (private), FLAGS should be a cons of CCL programs,
400 for decoding and encoding. See the documentation of CCL for more detail." 465 for decoding and encoding. See the documentation of CCL for more detail."
401 466
402 ;; At first, set a value of `coding-system' property. 467 (if (memq coding-system coding-system-list)
468 (error "Coding system %s already exists"))
469
470 ;; Set a value of `coding-system' property.
403 (let ((coding-spec (make-vector 5 nil)) 471 (let ((coding-spec (make-vector 5 nil))
472 (no-initial-designation nil)
404 coding-category) 473 coding-category)
405 (if (or (not (integerp type)) (< type 0) (> type 5)) 474 (if (or (not (integerp type)) (< type 0) (> type 5))
406 (error "TYPE argument must be 0..4")) 475 (error "TYPE argument must be 0..5"))
407 (if (or (not (integerp mnemonic)) (<= mnemonic ? ) (> mnemonic 127)) 476 (if (or (not (integerp mnemonic)) (<= mnemonic ? ) (> mnemonic 127))
408 (error "MNEMONIC arguemnt must be a printable character.")) 477 (error "MNEMONIC arguemnt must be an ASCII printable character."))
409 (aset coding-spec 0 type) 478 (aset coding-spec coding-spec-type-idx type)
410 (aset coding-spec 1 mnemonic) 479 (aset coding-spec coding-spec-mnemonic-idx mnemonic)
411 (aset coding-spec 2 (if (stringp doc-string) doc-string "")) 480 (aset coding-spec coding-spec-doc-string-idx
412 (aset coding-spec 3 nil) ; obsolete element 481 (if (stringp doc-string) doc-string ""))
413 (cond ((= type 0) 482 (cond ((= type 0)
414 (setq coding-category 'coding-category-emacs-mule)) 483 (setq coding-category 'coding-category-emacs-mule))
415 ((= type 1) 484 ((= type 1)
416 (setq coding-category 'coding-category-sjis)) 485 (setq coding-category 'coding-category-sjis))
417 ((= type 2) ; ISO2022 486 ((= type 2) ; ISO2022
418 (let ((i 0) 487 (let ((i 0)
419 (vec (make-vector 32 nil)) 488 (vec (make-vector 32 nil))
420 (no-initial-designation t)
421 (g1-designation nil)) 489 (g1-designation nil))
490 (setq no-initial-designation t)
422 (while (< i 4) 491 (while (< i 4)
423 (let ((charset (car flags))) 492 (let ((charset (car flags)))
424 (if (and no-initial-designation 493 (if (and no-initial-designation
425 (> i 0) 494 (> i 0)
426 (or (charsetp charset) 495 (or (charsetp charset)
444 (setq flags (cdr flags) i (1+ i))) 513 (setq flags (cdr flags) i (1+ i)))
445 (while (and (< i 32) flags) 514 (while (and (< i 32) flags)
446 (aset vec i (car flags)) 515 (aset vec i (car flags))
447 (setq flags (cdr flags) i (1+ i))) 516 (setq flags (cdr flags) i (1+ i)))
448 (aset coding-spec 4 vec) 517 (aset coding-spec 4 vec)
449 (if no-initial-designation
450 (put coding-system 'no-initial-designation t))
451 (setq coding-category 518 (setq coding-category
452 (if (aref vec 8) ; Use locking-shift. 519 (if (aref vec 8) ; Use locking-shift.
453 (or (and (aref vec 7) 'coding-category-iso-7-else) 520 (or (and (aref vec 7) 'coding-category-iso-7-else)
454 'coding-category-iso-8-else) 521 'coding-category-iso-8-else)
455 (if (aref vec 7) ; 7-bit only. 522 (if (aref vec 7) ; 7-bit only.
471 (vectorp (cdr flags))) 538 (vectorp (cdr flags)))
472 (aset coding-spec 4 flags) 539 (aset coding-spec 4 flags)
473 (error "Invalid FLAGS argument for TYPE 4 (CCL)"))) 540 (error "Invalid FLAGS argument for TYPE 4 (CCL)")))
474 (t ; i.e. (= type 5) 541 (t ; i.e. (= type 5)
475 (setq coding-category 'coding-category-raw-text))) 542 (setq coding-category 'coding-category-raw-text)))
543
544 (let ((plist (list 'coding-category coding-category
545 'alias-coding-systems (list coding-system))))
546 (if no-initial-designation
547 (setq plist (cons 'no-initial-designation
548 (cons no-initial-designation plist))))
549 (aset coding-spec coding-spec-plist-idx plist))
476 (put coding-system 'coding-system coding-spec) 550 (put coding-system 'coding-system coding-spec)
477 (put coding-system 'coding-category coding-category)
478 (put coding-category 'coding-systems 551 (put coding-category 'coding-systems
479 (cons coding-system (get coding-category 'coding-systems)))) 552 (cons coding-system (get coding-category 'coding-systems))))
480 553
481 ;; Next, set a value of `eol-type' property. The value is a vector 554 ;; Next, set a value of `eol-type' property. The value is a vector
482 ;; of subsidiary coding systems, each corresponds to a coding system 555 ;; of subsidiary coding systems, each corresponds to a coding system
483 ;; for the detected end-of-line format. 556 ;; for the detected end-of-line format.
484 (put coding-system 'eol-type 557 (put coding-system 'eol-type
485 (if (or (<= type 3) (= type 5)) 558 (if (or (<= type 3) (= type 5))
486 (make-subsidiary-coding-system coding-system) 559 (make-subsidiary-coding-system coding-system)
487 0))) 560 0))
561
562 ;; At last, register CODING-SYSTEM in `coding-system-list' and
563 ;; `coding-system-alist'.
564 (setq coding-system-list (cons coding-system coding-system-list))
565 (setq coding-system-alist (cons (list (symbol-name coding-system))
566 coding-system-alist)))
488 567
489 (defun define-coding-system-alias (alias coding-system) 568 (defun define-coding-system-alias (alias coding-system)
490 "Define ALIAS as an alias for coding system CODING-SYSTEM." 569 "Define ALIAS as an alias for coding system CODING-SYSTEM."
491 (check-coding-system coding-system) 570 (put alias 'coding-system (coding-system-spec coding-system))
492 (let ((parent (coding-system-parent coding-system))) 571 (nconc (coding-system-get alias 'alias-coding-systems) (list alias))
493 (if parent 572 (setq coding-system-list (cons alias coding-system-list))
494 (setq coding-system parent))) 573 (setq coding-system-alist (cons (list (symbol-name alias))
495 (put alias 'coding-system coding-system) 574 coding-system-alist))
496 (put alias 'parent-coding-system coding-system) 575 (let ((eol-type (coding-system-eol-type coding-system)))
497 (put coding-system 'alias-coding-systems 576 (if (vectorp eol-type)
498 (cons alias (get coding-system 'alias-coding-systems))) 577 (put alias 'eol-type (make-subsidiary-coding-system alias))
499 (let ((eol-variants (coding-system-eol-type coding-system)) 578 (put alias 'eol-type eol-type))))
500 subsidiaries)
501 (if (vectorp eol-variants)
502 (let ((i 0))
503 (setq subsidiaries (make-subsidiary-coding-system alias))
504 (while (< i 3)
505 (put (aref subsidiaries i) 'parent-coding-system
506 (aref eol-variants i))
507 (put (aref eol-variants i) 'alias-coding-systems
508 (cons (aref subsidiaries i) (get (aref eol-variants i)
509 'alias-coding-systems)))
510 (setq i (1+ i)))))))
511 579
512 (defun set-buffer-file-coding-system (coding-system &optional force) 580 (defun set-buffer-file-coding-system (coding-system &optional force)
513 "Set the file coding-system of the current buffer to CODING-SYSTEM. 581 "Set the file coding-system of the current buffer to CODING-SYSTEM.
514 This means that when you save the buffer, it will be converted 582 This means that when you save the buffer, it will be converted
515 according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM, 583 according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM,
517 585
518 If the buffer's previous file coding-system value specifies end-of-line 586 If the buffer's previous file coding-system value specifies end-of-line
519 conversion, and CODING-SYSTEM does not specify one, CODING-SYSTEM is 587 conversion, and CODING-SYSTEM does not specify one, CODING-SYSTEM is
520 merged with the already-specified end-of-line conversion. 588 merged with the already-specified end-of-line conversion.
521 However, if the optional prefix argument FORCE is non-nil, 589 However, if the optional prefix argument FORCE is non-nil,
522 them CODING-SYSTEM is used exactly as specified." 590 then CODING-SYSTEM is used exactly as specified."
523 (interactive "zCoding system for visited file: \nP") 591 (interactive "zCoding system for visited file: \nP")
524 (check-coding-system coding-system) 592 (check-coding-system coding-system)
525 (if (null force) 593 (if (null force)
526 (let ((x (coding-system-eol-type buffer-file-coding-system)) 594 (let ((x (coding-system-eol-type buffer-file-coding-system))
527 (y (coding-system-eol-type coding-system))) 595 (y (coding-system-eol-type coding-system)))
705 (defun after-insert-file-set-buffer-file-coding-system (inserted) 773 (defun after-insert-file-set-buffer-file-coding-system (inserted)
706 (if last-coding-system-used 774 (if last-coding-system-used
707 (let ((coding-system 775 (let ((coding-system
708 (find-new-buffer-file-coding-system last-coding-system-used)) 776 (find-new-buffer-file-coding-system last-coding-system-used))
709 (modified-p (buffer-modified-p))) 777 (modified-p (buffer-modified-p)))
710 (if coding-system 778 (when coding-system
711 (set-buffer-file-coding-system coding-system)) 779 (set-buffer-file-coding-system coding-system)
712 (if (or (eq coding-system 'no-conversion) 780 (if (or (eq coding-system 'no-conversion)
713 (eq (coding-system-type coding-system) 5)) 781 (eq (coding-system-type coding-system) 5))
714 ;; It seems that random 8-bit codes are read. We had 782 ;; It seems that random 8-bit codes are read. We had
715 ;; better edit this buffer without multibyte character 783 ;; better edit this buffer without multibyte character
716 ;; facility. 784 ;; facility.
717 (setq enable-multibyte-characters nil)) 785 (setq enable-multibyte-characters nil))
718 (set-buffer-modified-p modified-p))) 786 (set-buffer-modified-p modified-p))))
719 nil) 787 nil)
720 788
721 (setq after-insert-file-functions 789 (setq after-insert-file-functions
722 (cons 'after-insert-file-set-buffer-file-coding-system 790 (cons 'after-insert-file-set-buffer-file-coding-system
723 after-insert-file-functions)) 791 after-insert-file-functions))
743 ;; and LOCAL-CODING. 811 ;; and LOCAL-CODING.
744 (setq local-eol (coding-system-eol-type buffer-file-coding-system)) 812 (setq local-eol (coding-system-eol-type buffer-file-coding-system))
745 (if (null (numberp local-eol)) 813 (if (null (numberp local-eol))
746 ;; But eol-type is not yet set. 814 ;; But eol-type is not yet set.
747 (setq local-eol nil)) 815 (setq local-eol nil))
748 (when (and buffer-file-coding-system 816 (if (and buffer-file-coding-system
749 (not (eq (coding-system-type buffer-file-coding-system) t))) 817 (not (eq (coding-system-type buffer-file-coding-system) t)))
750 ;; This is not `undecided'. 818 ;; This is not `undecided'.
751 (setq local-coding buffer-file-coding-system) 819 (setq local-coding (coding-system-base buffer-file-coding-system)))
752 (while (symbolp (get local-coding 'coding-system))
753 (setq local-coding (get local-coding 'coding-system))))
754 820
755 (if (and (local-variable-p 'buffer-file-coding-system) 821 (if (and (local-variable-p 'buffer-file-coding-system)
756 local-eol local-coding) 822 local-eol local-coding)
757 ;; The current buffer has already set full coding-system, we 823 ;; The current buffer has already set full coding-system, we
758 ;; had better not change it. 824 ;; had better not change it.
760 826
761 (setq found-eol (coding-system-eol-type coding)) 827 (setq found-eol (coding-system-eol-type coding))
762 (if (null (numberp found-eol)) 828 (if (null (numberp found-eol))
763 ;; But eol-type is not found. 829 ;; But eol-type is not found.
764 (setq found-eol nil)) 830 (setq found-eol nil))
765 (unless (eq (coding-system-type coding) t) 831 (if (not (eq (coding-system-type coding) t))
766 ;; This is not `undecided'. 832 ;; This is not `undecided'.
767 (setq found-coding coding) 833 (setq found-coding (coding-system-base coding)))
768 (while (symbolp (get found-coding 'coding-system))
769 (setq found-coding (get found-coding 'coding-system))))
770 834
771 ;; The local setting takes precedence over the found one. 835 ;; The local setting takes precedence over the found one.
772 (setq new-coding (or (and (local-variable-p 'buffer-file-coding-system) 836 (setq new-coding (or (and (local-variable-p 'buffer-file-coding-system)
773 local-coding) 837 local-coding)
774 found-coding 838 found-coding