• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/international/

Lines Matching +defs:coding +defs:system +defs:flags

10 ;; Keywords: mule, multilingual, character set, coding system
73 (set-auto-coding-for-load t)
80 ;; raw-text coding system, make the buffer unibyte.
84 (or (eq (coding-system-type last-coding-system-used) 5)
85 (eq last-coding-system-used 'no-conversion)))
152 while encoding to variants of ISO 2022 coding system, one of the
411 ;; Coding system stuff
413 ;; Coding system is a symbol that has the property `coding-system'.
415 ;; The value of the property `coding-system' is a vector of the
418 ;; We call this vector as coding-spec. See comments in src/coding.c
421 (defconst coding-spec-type-idx 0)
422 (defconst coding-spec-mnemonic-idx 1)
423 (defconst coding-spec-doc-string-idx 2)
424 (defconst coding-spec-plist-idx 3)
425 (defconst coding-spec-flags-idx 4)
427 ;; PLIST is a property list of a coding system. To share PLIST among
428 ;; alias coding systems, a coding system has PLIST in coding-spec
430 ;; Here's a list of coding system properties currently being used.
432 ;; o coding-category
434 ;; The value is a coding category the coding system belongs to. The
435 ;; function `make-coding-system' sets this value automatically
438 ;; o alias-coding-systems
440 ;; The value is a list of coding systems of the same alias group. The
441 ;; first element is the coding system made at first, which we call as
442 ;; `base coding system'. The function `make-coding-system' sets this
443 ;; value automatically and `define-coding-system-alias' updates it.
445 ;; See the documentation of make-coding-system for the meanings of the
455 ;; o valid-codes (meaningful only for a coding system based on CCL)
458 (defsubst coding-system-spec (coding-system)
459 "Return coding-spec of CODING-SYSTEM."
460 (get (check-coding-system coding-system) 'coding-system))
462 (defun coding-system-type (coding-system)
463 "Return the coding type of CODING-SYSTEM.
464 A coding type is an integer value indicating the encoding method
465 of CODING-SYSTEM. See the function `make-coding-system' for more detail."
466 (aref (coding-system-spec coding-system) coding-spec-type-idx))
468 (defun coding-system-mnemonic (coding-system)
470 The mnemonic character of a coding system is used in mode line
471 to indicate the coding system. If the arg is nil, return ?-."
472 (let ((spec (coding-system-spec coding-system)))
473 (if spec (aref spec coding-spec-mnemonic-idx) ?-)))
475 (defun coding-system-doc-string (coding-system)
477 (aref (coding-system-spec coding-system) coding-spec-doc-string-idx))
479 (defun coding-system-plist (coding-system)
481 (aref (coding-system-spec coding-system) coding-spec-plist-idx))
483 (defun coding-system-flags (coding-system)
484 "Return `flags' of CODING-SYSTEM.
485 A `flags' of a coding system is a vector of length 32 indicating detailed
486 information of a coding system. See the function `make-coding-system'
488 (aref (coding-system-spec coding-system) coding-spec-flags-idx))
490 (defun coding-system-get (coding-system prop)
492 (plist-get (coding-system-plist coding-system) prop))
494 (defun coding-system-put (coding-system prop val)
496 (let ((plist (coding-system-plist coding-system)))
499 (aset (coding-system-spec coding-system) coding-spec-plist-idx
502 (defun coding-system-category (coding-system)
503 "Return the coding category of CODING-SYSTEM.
504 See also `coding-category-list'."
505 (coding-system-get coding-system 'coding-category))
507 (defun coding-system-base (coding-system)
508 "Return the base coding system of CODING-SYSTEM.
509 A base coding system is what made by `make-coding-system'.
510 Any alias nor subsidiary coding systems are not base coding system."
511 (car (coding-system-get coding-system 'alias-coding-systems)))
513 ;; Coding system also has a property `eol-type'.
515 ;; This property indicates how the coding system handles end-of-line
516 ;; format. The value is integer 0, 1, 2, or a vector of three coding
520 ;; automatically. Nth element of the vector is the subsidiary coding
521 ;; system whose `eol-type' property is N.
523 (defun coding-system-eol-type (coding-system)
525 An eol-type is integer 0, 1, 2, or a vector of coding systems.
532 coding system whose eol-type is N."
533 (get coding-system 'eol-type))
535 (defun coding-system-eol-type-mnemonic (coding-system)
537 (let* ((eol-type (coding-system-eol-type coding-system))
546 (defun coding-system-lessp (x y)
553 (t (let ((c1 (coding-system-mnemonic x))
554 (c2 (coding-system-mnemonic y)))
559 (defun coding-system-equal (coding-system-1 coding-system-2)
561 Two coding systems are identical if two symbols are equal
563 (or (eq coding-system-1 coding-system-2)
564 (and (equal (coding-system-spec coding-system-1)
565 (coding-system-spec coding-system-2))
566 (let ((eol-type-1 (coding-system-eol-type coding-system-1))
567 (eol-type-2 (coding-system-eol-type coding-system-2)))
571 (defun add-to-coding-system-list (coding-system)
572 "Add CODING-SYSTEM to `coding-system-list' while keeping it sorted."
573 (if (or (null coding-system-list)
574 (coding-system-lessp coding-system (car coding-system-list)))
575 (setq coding-system-list (cons coding-system coding-system-list))
576 (let ((len (length coding-system-list))
577 mid (tem coding-system-list))
580 (if (coding-system-lessp (car mid) coding-system)
584 (setcdr tem (cons coding-system (cdr tem))))))
586 (defun coding-system-list (&optional base-only)
587 "Return a list of all existing non-subsidiary coding systems.
588 If optional arg BASE-ONLY is non-nil, only base coding systems are listed.
589 The value doesn't include subsidiary coding systems which are what
592 (let* ((codings (copy-sequence coding-system-list))
594 ;; Remove subsidiary coding systems (eol variants) and alias
595 ;; coding systems (if necessary).
597 (let* ((coding (car (cdr tail)))
598 (aliases (coding-system-get coding 'alias-coding-systems)))
601 (not (memq coding aliases))
603 (and base-only (not (eq coding (car aliases)))))
631 (defconst char-coding-system-table nil
635 (defun make-subsidiary-coding-system (coding-system)
636 "Make subsidiary coding systems (eol-type variants) of CODING-SYSTEM."
637 (let ((coding-spec (coding-system-spec coding-system))
638 (subsidiaries (vector (intern (format "%s-unix" coding-system))
639 (intern (format "%s-dos" coding-system))
640 (intern (format "%s-mac" coding-system))))
644 (put elt 'coding-system coding-spec)
646 (put elt 'coding-system-define-form nil)
647 (add-to-coding-system-list elt)
648 (or (assoc (symbol-name elt) coding-system-alist)
649 (setq coding-system-alist
650 (cons (list (symbol-name elt)) coding-system-alist))))
653 (defun transform-make-coding-system-args (name type &optional doc-string props)
655 Transform XEmacs style args for `make-coding-system' to Emacs style.
731 (error "unsupported XEmacs style make-coding-style arguments: %S"
734 (defun make-coding-system (coding-system type mnemonic doc-string
736 flags
739 "Define a new coding system CODING-SYSTEM (symbol).
741 and PROPERTIES (optional) which construct a coding-spec of CODING-SYSTEM
745 TYPE is an integer value indicating the type of the coding system as follows:
753 MNEMONIC is a character to be displayed on mode line for the coding system.
755 DOC-STRING is a documentation string for the coding system.
757 FLAGS specifies more detailed information of the coding system as follows:
789 code of the coding system.
801 decoded by the coding system itself and before any functions in
811 called, and before the text is encoded by the coding system itself.
820 table. This is not applicable to type 4 (CCL-based) coding systems.
825 not applicable to type 4 (CCL-based) coding systems.
830 the character is safely supported by the coding system. This
835 The value is a list of charsets safely supported by the coding
836 system. The value t means that all charsets Emacs handles are
838 mean that the charset can't be encoded in the coding system;
840 in the coding system won't be able to handle that charset.
845 the coding system.
852 o valid-codes (meaningful only for a coding system based on CCL)
861 If the value is non-nil, the coding system preserves composition
866 If the value is non-nil, the coding system is not compatible
871 also sets properties `coding-category' and `alias-coding-systems'
874 EOL-TYPE specifies the EOL type of the coding-system in one of the
887 o vector of coding-systems of length 3
889 The EOL type is detected automatically for the coding system.
890 And, according to the detected EOL type, one of the coding
908 (let ((args (transform-make-coding-system-args coding-system type
910 (setq coding-system (car args)
914 flags (nth 4 args)
918 ;; Set a value of `coding-system' property.
919 (let ((coding-spec (make-vector 5 nil))
923 coding-category)
928 (aset coding-spec coding-spec-type-idx type)
929 (aset coding-spec coding-spec-mnemonic-idx mnemonic)
930 (aset coding-spec coding-spec-doc-string-idx
933 (setq coding-category 'coding-category-emacs-mule))
935 (setq coding-category 'coding-category-sjis))
940 (fl flags))
974 (aset coding-spec 4 vec)
975 (setq coding-category
977 (or (and (aref vec 7) 'coding-category-iso-7-else)
978 'coding-category-iso-8-else)
981 'coding-category-iso-7-else
983 'coding-category-iso-7-tight
984 'coding-category-iso-7))
987 'coding-category-iso-8-else
990 'coding-category-iso-8-2
991 'coding-category-iso-8-1)))))))
993 (setq coding-category 'coding-category-big5))
995 (setq coding-category 'coding-category-ccl)
996 (if (not (consp flags))
999 (car flags)
1000 (intern (format "%s-decoder" coding-system))))
1002 (cdr flags)
1003 (intern (format "%s-encoder" coding-system)))))
1005 (aset coding-spec 4 (cons decoder encoder))
1008 (setq coding-category 'coding-category-raw-text)))
1010 (let ((plist (list 'coding-category coding-category
1011 'alias-coding-systems (list coding-system))))
1066 ;; The property `coding-category' may have been set differently
1068 (setq coding-category (plist-get plist 'coding-category))
1069 (aset coding-spec coding-spec-plist-idx plist))
1070 (put coding-system 'coding-system coding-spec)
1071 (put coding-system 'coding-system-define-form nil)
1072 (put coding-category 'coding-systems
1073 (cons coding-system (get coding-category 'coding-systems))))
1077 ;; If EOL-TYPE is nil, set a vector of subsidiary coding
1078 ;; systems, each corresponds to a coding system for the detected
1080 (setq eol-type (make-subsidiary-coding-system coding-system)))
1096 (put coding-system 'eol-type eol-type)
1098 (define-coding-system-internal coding-system)
1100 ;; At last, register CODING-SYSTEM in `coding-system-list' and
1101 ;; `coding-system-alist'.
1102 (add-to-coding-system-list coding-system)
1103 (or (assoc (symbol-name coding-system) coding-system-alist)
1104 (setq coding-system-alist (cons (list (symbol-name coding-system))
1105 coding-system-alist)))
1107 ;; For a coding system of cateogory iso-8-1 and iso-8-2, create
1109 (let ((coding-category (coding-system-category coding-system)))
1110 (if (or (eq coding-category 'coding-category-iso-8-1)
1111 (eq coding-category 'coding-category-iso-8-2))
1112 (let ((esc (intern (concat (symbol-name coding-system) "-with-esc")))
1113 (doc (format "Same as %s but can handle any charsets by ISO's escape sequences." coding-system))
1121 (make-coding-system esc type mnemonic doc
1122 (if (listp (car flags))
1123 (cons (append (car flags) '(t)) (cdr flags))
1124 (cons (list (car flags) t) (cdr flags)))
1127 coding-system)
1131 (defun define-coding-system-alias (alias coding-system)
1132 "Define ALIAS as an alias for coding system CODING-SYSTEM."
1133 (put alias 'coding-system (coding-system-spec coding-system))
1134 (put alias 'coding-system-define-form nil)
1135 (add-to-coding-system-list alias)
1136 (or (assoc (symbol-name alias) coding-system-alist)
1137 (setq coding-system-alist (cons (list (symbol-name alias))
1138 coding-system-alist)))
1139 (let ((eol-type (coding-system-eol-type coding-system)))
1142 (nconc (coding-system-get alias 'alias-coding-systems) (list alias))
1143 (put alias 'eol-type (make-subsidiary-coding-system alias)))
1146 (defun merge-coding-systems (first second)
1147 "Fill in any unspecified aspects of coding system FIRST from SECOND.
1148 Return the resulting coding system."
1149 (let ((base (coding-system-base second))
1150 (eol (coding-system-eol-type second)))
1152 (if (eq (coding-system-base first) 'undecided)
1153 (setq first (coding-system-change-text-conversion first base)))
1155 (if (and (vectorp (coding-system-eol-type first))
1157 (setq first (coding-system-change-eol-conversion
1161 (defun autoload-coding-system (symbol form)
1162 "Define SYMBOL as a coding-system that is defined on demand.
1164 FROM is a form to evaluate to define the coding-system."
1165 (put symbol 'coding-system-define-form form)
1166 (setq coding-system-alist (cons (list (symbol-name symbol))
1167 coding-system-alist))
1170 (put (intern name) 'coding-system-define-form form)
1171 (setq coding-system-alist (cons (list name) coding-system-alist)))))
1173 (defun set-buffer-file-coding-system (coding-system &optional force nomodify)
1174 "Set the file coding-system of the current buffer to CODING-SYSTEM.
1177 use \\[list-coding-systems].
1182 buffer's previous `buffer-file-coding-system' value (if it is
1188 If you know exactly what coding system you want to use,
1189 just set the variable `buffer-file-coding-system' directly."
1190 (interactive "zCoding system for saving file (default nil): \nP")
1191 (check-coding-system coding-system)
1192 (if (and coding-system buffer-file-coding-system (null force))
1193 (setq coding-system
1194 (merge-coding-systems coding-system buffer-file-coding-system)))
1195 (setq buffer-file-coding-system coding-system)
1204 (defun revert-buffer-with-coding-system (coding-system &optional force)
1205 "Visit the current buffer's file again using coding system CODING-SYSTEM.
1206 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
1211 buffer's previous `buffer-file-coding-system' value (if it is
1214 (interactive "zCoding system for visited file (default nil): \nP")
1215 (check-coding-system coding-system)
1216 (if (and coding-system buffer-file-coding-system (null force))
1217 (setq coding-system
1218 (merge-coding-systems coding-system buffer-file-coding-system)))
1219 (let ((coding-system-for-read coding-system))
1222 (defun set-file-name-coding-system (coding-system)
1223 "Set coding system for decoding and encoding file names to CODING-SYSTEM.
1224 It actually just set the variable `file-name-coding-system' (which
1226 (interactive "zCoding system for file names (default nil): ")
1227 (check-coding-system coding-system)
1228 (if (and coding-system
1229 (coding-system-get coding-system 'ascii-incompatible))
1230 (error "%s is not ASCII-compatible" coding-system))
1231 (setq file-name-coding-system coding-system))
1233 (defvar default-terminal-coding-system nil
1234 "Default value for the terminal coding system.
1236 See also the command `set-terminal-coding-system'.")
1238 (defun set-terminal-coding-system (coding-system)
1239 "Set coding system of your terminal to CODING-SYSTEM.
1241 with the specified coding system.
1242 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
1246 (list (let ((default (if (and (not (terminal-coding-system))
1247 default-terminal-coding-system)
1248 default-terminal-coding-system)))
1249 (read-coding-system
1250 (format "Coding system for terminal display (default %s): "
1253 (if (and (not coding-system)
1254 (not (terminal-coding-system)))
1255 (setq coding-system default-terminal-coding-system))
1256 (if coding-system
1257 (setq default-terminal-coding-system coding-system))
1258 (set-terminal-coding-system-internal coding-system)
1261 (defvar default-keyboard-coding-system nil
1262 "Default value of the keyboard coding system.
1264 See also the command `set-keyboard-coding-system'.")
1266 (defun set-keyboard-coding-system (coding-system)
1267 "Set coding system for keyboard input to CODING-SYSTEM.
1271 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
1275 (list (let ((default (if (and (not (keyboard-coding-system))
1276 default-keyboard-coding-system)
1277 default-keyboard-coding-system)))
1278 (read-coding-system
1279 (format "Coding system for keyboard input (default %s): "
1282 (if (and (not coding-system)
1283 (not (keyboard-coding-system)))
1284 (setq coding-system default-keyboard-coding-system))
1285 (if coding-system
1286 (setq default-keyboard-coding-system coding-system))
1287 (if (and coding-system
1288 (coding-system-get coding-system 'ascii-incompatible))
1289 (error "%s is not ASCII-compatible" coding-system))
1290 (set-keyboard-coding-system-internal coding-system)
1291 (setq keyboard-coding-system coding-system)
1292 (encoded-kbd-mode (if coding-system 1 0)))
1294 (defcustom keyboard-coding-system nil
1295 "Specify coding system for keyboard input.
1303 use either \\[customize] or \\[set-keyboard-coding-system]."
1304 :type '(coding-system :tag "Coding system")
1310 (set-keyboard-coding-system value)
1311 (set-default 'keyboard-coding-system nil))) ; must initialize
1316 (defun set-buffer-process-coding-system (decoding encoding)
1317 "Set coding systems for the process associated with the current buffer.
1318 DECODING is the coding system to be used to decode input from the process,
1319 ENCODING is the coding system to be used to encode output to the process.
1321 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems]."
1323 "zCoding-system for output from the process: \nzCoding-system for input to the process: ")
1327 (check-coding-system decoding)
1328 (check-coding-system encoding)
1329 (set-process-coding-system proc decoding encoding)))
1332 (defalias 'set-clipboard-coding-system 'set-selection-coding-system)
1334 (defun set-selection-coding-system (coding-system)
1338 (interactive "zCoding system for X selection: ")
1339 (check-coding-system coding-system)
1340 (setq selection-coding-system coding-system))
1342 ;; Coding system lastly specified by the command
1343 ;; set-next-selection-coding-system.
1344 (defvar last-next-selection-coding-system nil)
1346 (defun set-next-selection-coding-system (coding-system)
1350 (list (read-coding-system
1351 (if last-next-selection-coding-system
1352 (format "Coding system for the next X selection (default %S): "
1353 last-next-selection-coding-system)
1354 "Coding system for the next X selection: ")
1355 last-next-selection-coding-system)))
1356 (if coding-system
1357 (setq last-next-selection-coding-system coding-system)
1358 (setq coding-system last-next-selection-coding-system))
1359 (check-coding-system coding-system)
1361 (setq next-selection-coding-system coding-system))
1363 (defun set-coding-priority (arg)
1364 "Set priority of coding categories according to ARG.
1365 ARG is a list of coding categories ordered by priority."
1367 (current-list (copy-sequence coding-category-list)))
1368 ;; Check the validity of ARG while deleting coding categories in
1370 ;; contains all coding categories.
1372 (if (or (null (get (car l) 'coding-category-index))
1377 ;; Update `coding-category-list' and return it.
1378 (setq coding-category-list (append arg current-list))
1379 (set-coding-priority-internal)))
1390 by the coding system `compound-text-with-extensions'.
1396 CODING-SYSTEM is the coding-system to encode (or decode) the
1441 last-coding-system-used
1458 (coding (if encoding-info
1461 (and (coding-system-p encoding)
1465 (when coding
1468 (decode-coding-region (- (point) bytes) (point) coding)))
1472 (decode-coding-region pos (point) 'utf-8))))
1508 by encode-coding-string, generate a new temp buffer, insert the
1528 last-coding-system-used
1549 (coding-system (nth 1 last-encoding-info))
1552 (encode-coding-region last-pos (point) coding-system)
1566 (encode-coding-region last-pos (point) 'mule-utf-8)
1583 (defcustom auto-coding-alist
1593 "Alist of filename patterns vs corresponding coding systems.
1597 The settings in this alist take priority over `coding:' tags
1598 in the file (see the function `set-auto-coding')
1599 and the contents of `file-coding-system-alist'."
1603 (symbol :tag "Coding system"))))
1605 (defcustom auto-coding-regexp-alist
1610 "Alist of patterns vs corresponding coding systems.
1614 The settings in this alist take priority over `coding:' tags
1615 in the file (see the function `set-auto-coding')
1616 and the contents of `file-coding-system-alist'."
1620 (symbol :tag "Coding system"))))
1622 (defun auto-coding-regexp-alist-lookup (from to)
1623 "Lookup `auto-coding-regexp-alist' for the contents of the current buffer.
1624 The value is a coding system is specified for the region FROM and TO,
1628 (let ((alist auto-coding-regexp-alist)
1629 coding-system)
1630 (while (and alist (not coding-system))
1635 (setq coding-system (cdr (car alist)))
1637 coding-system)))
1639 ;; See the bottom of this file for built-in auto coding functions.
1640 (defcustom auto-coding-functions '(sgml-xml-auto-coding-function
1641 sgml-html-meta-auto-coding-function)
1642 "A list of functions which attempt to determine a coding system.
1650 If one of these functions succeeds in determining a coding
1651 system, it should return that coding system. Otherwise, it
1654 If a file has a `coding:' tag, that takes precedence over these
1660 (defvar set-auto-coding-for-load nil
1661 "Non-nil means look for `load-coding' property instead of `coding'.
1664 (defun auto-coding-alist-lookup (filename)
1665 "Return the coding system specified by `auto-coding-alist' for FILENAME."
1666 (let ((alist auto-coding-alist)
1667 (case-fold-search (memq system-type '(vax-vms windows-nt ms-dos cygwin)))
1668 coding-system)
1669 (while (and alist (not coding-system))
1671 (setq coding-system (cdr (car alist)))
1673 coding-system))
1678 (defun find-auto-coding (filename size)
1679 "Find a coding system for a file FILENAME of which SIZE bytes follow point.
1683 The function checks FILENAME against the variable `auto-coding-alist'.
1686 `auto-coding-regexp-alist'. If no match is found, it checks for a
1687 `coding:' tag in the first one or two lines following point. If no
1688 `coding:' tag is found, it checks any local variables list in the last
1690 succeed, it checks to see if any function in `auto-coding-functions'
1693 If a coding system is specifed, the return value is a
1694 cons (CODING . SOURCE), where CODING is the specified coding
1695 system and SOURCE is a symbol `auto-coding-alist',
1696 `auto-coding-regexp-alist', `coding:', or `auto-coding-functions'
1701 (or (let ((coding-system (auto-coding-alist-lookup filename)))
1702 (if coding-system
1703 (cons coding-system 'auto-coding-alist)))
1704 ;; Try using `auto-coding-regexp-alist'.
1705 (let ((coding-system (auto-coding-regexp-alist-lookup (point)
1707 (if coding-system
1708 (cons coding-system 'auto-coding-regexp-alist)))
1714 coding-system head-found tail-found pos char-trans)
1715 ;; Try a short cut by searching for the string "coding:"
1717 (setq head-found (or (search-forward "coding:" head-end t)
1725 (setq tail-found (or (search-forward "coding:" tail-end t)
1737 (when (and set-auto-coding-for-load
1741 (setq coding-system 'raw-text))
1742 (when (and (not coding-system)
1744 "\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)"
1746 (setq coding-system (intern (match-string 2))))
1752 ;; If no coding: tag in the head, check the tail.
1755 (when (and tail-found (or (not coding-system) (not char-trans)))
1766 (re-coding
1771 "[ \t]*coding[ \t]*:[ \t]*\\([^ \t\r\n]+\\)[ \t]*"
1791 (when (and set-auto-coding-for-load
1793 (setq coding-system 'raw-text))
1794 (when (and (not coding-system)
1795 (re-search-forward re-coding tail-end t))
1796 (setq coding-system (intern (match-string 1))))
1800 (if coding-system
1801 ;; If the coding-system name ends with "!", remove it and
1803 (let ((name (symbol-name coding-system)))
1805 (setq coding-system (intern (substring name 0 -1))
1811 (if coding-system
1812 (cons coding-system :coding)))
1813 ;; Finally, try all the `auto-coding-functions'.
1814 (let ((funcs auto-coding-functions)
1815 (coding-system nil))
1816 (while (and funcs (not coding-system))
1817 (setq coding-system (condition-case e
1822 (if coding-system
1823 (cons coding-system 'auto-coding-functions)))))
1825 (defun set-auto-coding (filename size)
1826 "Return coding system for a file FILENAME of which SIZE bytes follow point.
1827 See `find-auto-coding' for how the coding system is found.
1828 Return nil if an invalid coding system is found.
1830 The variable `set-auto-coding-function' (which see) is set to this
1832 (let ((found (find-auto-coding filename size)))
1833 (if (and found (coding-system-p (car found)))
1836 (setq set-auto-coding-function 'set-auto-coding)
1839 ;; (1) A file is read by a coding system specified explicitly.
1840 ;; after-insert-file-set-coding sets this value to
1841 ;; coding-system-for-read.
1844 ;; last-coding-system-used.
1846 (defvar buffer-file-coding-system-explicit nil
1847 "The file coding system explicitly specified for the current buffer.
1849 (make-variable-buffer-local 'buffer-file-coding-system-explicit)
1850 (put 'buffer-file-coding-system-explicit 'permanent-local t)
1852 (defun after-insert-file-set-coding (inserted &optional visit)
1853 "Set `buffer-file-coding-system' of current buffer after text is inserted.
1860 coding-system-for-read
1861 (not (eq coding-system-for-read 'auto-save-coding)))
1862 (setq buffer-file-coding-system-explicit coding-system-for-read))
1863 (if last-coding-system-used
1864 (let ((coding-system
1865 (find-new-buffer-file-coding-system last-coding-system-used))
1867 (when coding-system
1868 ;; Tell set-buffer-file-coding-system not to mark the file
1872 (set-buffer-file-coding-system coding-system t t)
1874 (or (eq coding-system 'no-conversion)
1875 (eq (coding-system-type coding-system) 5))
1880 ;; For coding systems no-conversion and raw-text...,
1896 ;; The coding-spec and eol-type of coding-system returned is decided
1898 ;; 1. That of buffer-file-coding-system locally bound.
1901 (defun find-new-buffer-file-coding-system (coding)
1902 "Return a coding system for a buffer when a file of CODING is inserted.
1903 The local variable `buffer-file-coding-system' of the current buffer
1905 Return nil if there's no need to set `buffer-file-coding-system'."
1906 (let (local-coding local-eol
1907 found-coding found-eol
1908 new-coding new-eol)
1909 (if (null coding)
1910 ;; Nothing found about coding.
1913 ;; Get information of `buffer-file-coding-system' in LOCAL-EOL
1915 (setq local-eol (coding-system-eol-type buffer-file-coding-system))
1919 (if (and buffer-file-coding-system
1920 (not (eq (coding-system-type buffer-file-coding-system) t)))
1922 (setq local-coding (coding-system-base buffer-file-coding-system)))
1924 (if (and (local-variable-p 'buffer-file-coding-system)
1925 local-eol local-coding)
1926 ;; The current buffer has already set full coding-system, we
1930 (setq found-eol (coding-system-eol-type coding))
1935 (if (eq (coding-system-type coding) t)
1936 (setq found-coding 'undecided)
1937 (setq found-coding (coding-system-base coding)))
1939 (if (and (not found-eol) (eq found-coding 'undecided))
1940 ;; No valid coding information found.
1943 ;; Some coding information (eol or text) found.
1946 (setq new-coding (if (local-variable-p 'buffer-file-coding-system)
1947 (or local-coding found-coding)
1948 (or found-coding local-coding)))
1949 (setq new-eol (if (local-variable-p 'buffer-file-coding-system)
1953 (let ((eol-type (coding-system-eol-type new-coding)))
1956 new-coding)))))))
1958 (defun modify-coding-system-alist (target-type regexp coding-system)
1959 "Modify one of look up tables for finding a coding system on I/O operation.
1960 There are three of such tables, `file-coding-system-alist',
1961 `process-coding-system-alist', and `network-coding-system-alist'.
1964 If it is `file', it affects `file-coding-system-alist' (which see).
1965 If it is `process', it affects `process-coding-system-alist' (which see).
1966 If it is `network', it affects `network-coding-system-alist' (which see).
1973 CODING-SYSTEM is a coding system to perform code conversion on the I/O
1974 operation, or a cons cell (DECODING . ENCODING) specifying the coding systems
1982 (if (symbolp coding-system)
1983 (if (not (fboundp coding-system))
1985 (check-coding-system coding-system)
1986 (setq coding-system (cons coding-system coding-system))))
1987 (check-coding-system (car coding-system))
1988 (check-coding-system (cdr coding-system)))
1990 (let ((slot (assoc regexp file-coding-system-alist)))
1992 (setcdr slot coding-system)
1993 (setq file-coding-system-alist
1994 (cons (cons regexp coding-system)
1995 file-coding-system-alist)))))
1997 (let ((slot (assoc regexp process-coding-system-alist)))
1999 (setcdr slot coding-system)
2000 (setq process-coding-system-alist
2001 (cons (cons regexp coding-system)
2002 process-coding-system-alist)))))
2004 (let ((slot (assoc regexp network-coding-system-alist)))
2006 (setcdr slot coding-system)
2007 (setq network-coding-system-alist
2008 (cons (cons regexp coding-system)
2009 network-coding-system-alist)))))))
2011 (defun decode-coding-inserted-region (from to filename
2020 (let ((coding coding-system-for-read)
2035 (or coding
2036 (setq coding (funcall set-auto-coding-function
2038 (or coding
2039 (setq coding (car (find-operation-coding-system
2043 (if (coding-system-p coding)
2045 (setq coding
2046 (coding-system-change-text-conversion coding 'raw-text)))
2047 (setq coding nil))
2048 (if coding
2049 (decode-coding-region (point-min) (point-max) coding)
2050 (setq last-coding-system-used coding))
2061 (defun recode-region (start end new-coding coding)
2065 (read-coding-system "Text was really in: ")
2066 (let ((coding (or buffer-file-coding-system last-coding-system-used)))
2067 (read-coding-system
2069 (if coding (format " (default %S): " coding) ": "))
2070 coding))))
2071 (or (and new-coding coding)
2072 (error "Coding system not specified"))
2074 (check-coding-system new-coding)
2077 (encode-coding-region (point-min) (point-max) coding)
2078 (decode-coding-region (point-min) (point-max) new-coding)))
2284 ;;; Built-in auto-coding-functions:
2286 (defun sgml-xml-auto-coding-function (size)
2288 This function is intended to be added to `auto-coding-functions'."
2298 (if (coding-system-p sym)
2300 (message "Warning: unknown coding system \"%s\"" match)
2304 (defun sgml-html-meta-auto-coding-function (size)
2306 This function is intended to be added to `auto-coding-functions'."
2322 (if (coding-system-p sym)
2324 (message "Warning: unknown coding system \"%s\"" match)