comparison lisp/international/mule.el @ 46785:28581ef4c224

(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.
author Richard M. Stallman <rms@gnu.org>
date Fri, 02 Aug 2002 18:01:33 +0000
parents 80075b7b7612
children ed9f839eddc9
comparison
equal deleted inserted replaced
46784:546f1e0c46c9 46785:28581ef4c224
1112 (progn 1112 (progn
1113 (nconc (coding-system-get alias 'alias-coding-systems) (list alias)) 1113 (nconc (coding-system-get alias 'alias-coding-systems) (list alias))
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."
1148 (interactive "zCoding system for saving file (default, nil): \nP")
1149 (check-coding-system coding-system)
1150 (if (and coding-system buffer-file-coding-system (null force))
1151 (setq coding-system
1152 (merge-coding-systems coding-system buffer-file-coding-system)))
1153 (setq buffer-file-coding-system coding-system)
1154 (set-buffer-modified-p t)
1155 (force-mode-line-update))
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."
1138 (interactive "zCoding system for visited file (default, nil): \nP") 1167 (interactive "zCoding system for visited file (default, nil): \nP")
1139 (check-coding-system coding-system) 1168 (check-coding-system coding-system)
1140 (if (and coding-system buffer-file-coding-system (null force)) 1169 (if (and coding-system buffer-file-coding-system (null force))
1141 (let ((base (coding-system-base buffer-file-coding-system)) 1170 (setq coding-system
1142 (eol (coding-system-eol-type buffer-file-coding-system))) 1171 (merge-coding-systems coding-system buffer-file-coding-system)))
1143 ;; If CODING-SYSTEM doesn't specify text conversion, merge 1172 (let ((coding-system-for-read coding-system))
1144 ;; with that of buffer-file-coding-system. 1173 (revert-buffer)))
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)
1155 (set-buffer-modified-p t)
1156 (force-mode-line-update))
1157 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.
1161 See also the command `set-terminal-coding-system'.") 1178 See also the command `set-terminal-coding-system'.")