diff options
| author | Richard M. Stallman | 2002-08-02 18:01:33 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-08-02 18:01:33 +0000 |
| commit | bbdea9488cc24c7636c74f2bb22073b44724e4a7 (patch) | |
| tree | 6685749fb9f8b6b7975fd64ca86185ff1404d244 | |
| parent | 1f1b7f93c2a13d2e14e5520ac589d035b5742034 (diff) | |
| download | emacs-bbdea9488cc24c7636c74f2bb22073b44724e4a7.tar.gz emacs-bbdea9488cc24c7636c74f2bb22073b44724e4a7.zip | |
(merge-coding-systems): New function.
(set-buffer-file-coding-system): Use merge-coding-systems.
Change prompt for args.
(revert-buffer-with-coding-system): New command.
| -rw-r--r-- | lisp/international/mule.el | 65 |
1 files changed, 41 insertions, 24 deletions
diff --git a/lisp/international/mule.el b/lisp/international/mule.el index dc92d9fae98..6cc905603e4 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el | |||
| @@ -1114,47 +1114,64 @@ a value of `safe-charsets' in PLIST." | |||
| 1114 | (put alias 'eol-type (make-subsidiary-coding-system alias))) | 1114 | (put alias 'eol-type (make-subsidiary-coding-system alias))) |
| 1115 | (put alias 'eol-type eol-type)))) | 1115 | (put alias 'eol-type eol-type)))) |
| 1116 | 1116 | ||
| 1117 | (defun merge-coding-systems (first second) | ||
| 1118 | "Fill in any unspecified aspects of coding system FIRST from SECOND. | ||
| 1119 | Return the resulting coding system." | ||
| 1120 | (let ((base (coding-system-base second)) | ||
| 1121 | (eol (coding-system-eol-type second))) | ||
| 1122 | ;; If FIRST doesn't specify text conversion, merge with that of SECOND. | ||
| 1123 | (if (eq (coding-system-base first) 'undecided) | ||
| 1124 | (setq first (coding-system-change-text-conversion first base))) | ||
| 1125 | ;; If FIRST doesn't specify eol conversion, merge with that of SECOND. | ||
| 1126 | (if (and (vectorp (coding-system-eol-type first)) | ||
| 1127 | (numberp eol) (>= eol 0) (<= eol 2)) | ||
| 1128 | (setq first (coding-system-change-eol-conversion | ||
| 1129 | first eol))) | ||
| 1130 | first)) | ||
| 1131 | |||
| 1117 | (defun set-buffer-file-coding-system (coding-system &optional force) | 1132 | (defun set-buffer-file-coding-system (coding-system &optional force) |
| 1118 | "Set the file coding-system of the current buffer to CODING-SYSTEM. | 1133 | "Set the file coding-system of the current buffer to CODING-SYSTEM. |
| 1119 | This means that when you save the buffer, it will be converted | 1134 | This means that when you save the buffer, it will be converted |
| 1120 | according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM, | 1135 | according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM, |
| 1121 | use \\[list-coding-systems]. | 1136 | use \\[list-coding-systems]. |
| 1122 | 1137 | ||
| 1123 | If the buffer's previous file coding-system value specifies end-of-line | 1138 | If CODING-SYSTEM leaves the text conversion unspecified, or if it |
| 1124 | conversion, and CODING-SYSTEM does not specify one, CODING-SYSTEM is | 1139 | leaves the end-of-line conversion unspecified, FORCE controls what to |
| 1125 | merged with the already-specified end-of-line conversion. | 1140 | do. If FORCE is nil, get the unspecified aspect (or aspects) from the |
| 1126 | 1141 | buffer's previous `buffer-file-coding-system' value (if it is | |
| 1127 | If the buffer's previous file coding-system value specifies text | 1142 | specified there). Otherwise, levae it unspecified. |
| 1128 | conversion, and CODING-SYSTEM does not specify one, CODING-SYSTEM is | ||
| 1129 | merged with the already-specified text conversion. | ||
| 1130 | |||
| 1131 | However, if the optional prefix argument FORCE is non-nil, then | ||
| 1132 | CODING-SYSTEM is used exactly as specified. | ||
| 1133 | 1143 | ||
| 1134 | This marks the buffer modified so that the succeeding \\[save-buffer] | 1144 | This marks the buffer modified so that the succeeding \\[save-buffer] |
| 1135 | surely saves the buffer with CODING-SYSTEM. From a program, if you | 1145 | surely saves the buffer with CODING-SYSTEM. From a program, if you |
| 1136 | don't want to mark the buffer modified, just set the variable | 1146 | don't want to mark the buffer modified, just set the variable |
| 1137 | `buffer-file-coding-system' directly." | 1147 | `buffer-file-coding-system' directly." |
| 1138 | (interactive "zCoding system for visited file (default, nil): \nP") | 1148 | (interactive "zCoding system for saving file (default, nil): \nP") |
| 1139 | (check-coding-system coding-system) | 1149 | (check-coding-system coding-system) |
| 1140 | (if (and coding-system buffer-file-coding-system (null force)) | 1150 | (if (and coding-system buffer-file-coding-system (null force)) |
| 1141 | (let ((base (coding-system-base buffer-file-coding-system)) | 1151 | (setq coding-system |
| 1142 | (eol (coding-system-eol-type buffer-file-coding-system))) | 1152 | (merge-coding-systems coding-system buffer-file-coding-system))) |
| 1143 | ;; If CODING-SYSTEM doesn't specify text conversion, merge | ||
| 1144 | ;; with that of buffer-file-coding-system. | ||
| 1145 | (if (eq (coding-system-base coding-system) 'undecided) | ||
| 1146 | (setq coding-system (coding-system-change-text-conversion | ||
| 1147 | coding-system base))) | ||
| 1148 | ;; If CODING-SYSTEM doesn't specify eol conversion, merge with | ||
| 1149 | ;; that of buffer-file-coding-system. | ||
| 1150 | (if (and (vectorp (coding-system-eol-type coding-system)) | ||
| 1151 | (numberp eol) (>= eol 0) (<= eol 2)) | ||
| 1152 | (setq coding-system (coding-system-change-eol-conversion | ||
| 1153 | coding-system eol))))) | ||
| 1154 | (setq buffer-file-coding-system coding-system) | 1153 | (setq buffer-file-coding-system coding-system) |
| 1155 | (set-buffer-modified-p t) | 1154 | (set-buffer-modified-p t) |
| 1156 | (force-mode-line-update)) | 1155 | (force-mode-line-update)) |
| 1157 | 1156 | ||
| 1157 | (defun revert-buffer-with-coding-system (coding-system &optional force) | ||
| 1158 | "Visit the current buffer's file again using coding system CODING-SYSTEM. | ||
| 1159 | For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems]. | ||
| 1160 | |||
| 1161 | If CODING-SYSTEM leaves the text conversion unspecified, or if it | ||
| 1162 | leaves the end-of-line conversion unspecified, FORCE controls what to | ||
| 1163 | do. If FORCE is nil, get the unspecified aspect (or aspects) from the | ||
| 1164 | buffer's previous `buffer-file-coding-system' value (if it is | ||
| 1165 | specified there). Otherwise, determine it from the file contents as | ||
| 1166 | usual for visiting a file." | ||
| 1167 | (interactive "zCoding system for visited file (default, nil): \nP") | ||
| 1168 | (check-coding-system coding-system) | ||
| 1169 | (if (and coding-system buffer-file-coding-system (null force)) | ||
| 1170 | (setq coding-system | ||
| 1171 | (merge-coding-systems coding-system buffer-file-coding-system))) | ||
| 1172 | (let ((coding-system-for-read coding-system)) | ||
| 1173 | (revert-buffer))) | ||
| 1174 | |||
| 1158 | (defvar default-terminal-coding-system nil | 1175 | (defvar default-terminal-coding-system nil |
| 1159 | "Default value for the terminal coding system. | 1176 | "Default value for the terminal coding system. |
| 1160 | This is normally set according to the selected language environment. | 1177 | This is normally set according to the selected language environment. |