1137 |
(setq coding-system-alist (cons (list (symbol-name symbol)) |
(setq coding-system-alist (cons (list (symbol-name symbol)) |
1138 |
coding-system-alist))) |
coding-system-alist))) |
1139 |
|
|
1140 |
(defun set-buffer-file-coding-system (coding-system &optional force) |
(defun set-buffer-file-coding-system (coding-system &optional force nomodify) |
1141 |
"Set the file coding-system of the current buffer to CODING-SYSTEM. |
"Set the file coding-system of the current buffer to CODING-SYSTEM. |
1142 |
This means that when you save the buffer, it will be converted |
This means that when you save the buffer, it will be converted |
1143 |
according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM, |
according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM, |
1151 |
|
|
1152 |
This marks the buffer modified so that the succeeding \\[save-buffer] |
This marks the buffer modified so that the succeeding \\[save-buffer] |
1153 |
surely saves the buffer with CODING-SYSTEM. From a program, if you |
surely saves the buffer with CODING-SYSTEM. From a program, if you |
1154 |
don't want to mark the buffer modified, just set the variable |
don't want to mark the buffer modified, specify t for NOMODIFY. |
1155 |
`buffer-file-coding-system' directly." |
If you know exactly what coding system you want to use, |
1156 |
|
just set the variable `buffer-file-coding-system' directly." |
1157 |
(interactive "zCoding system for saving file (default, nil): \nP") |
(interactive "zCoding system for saving file (default, nil): \nP") |
1158 |
(check-coding-system coding-system) |
(check-coding-system coding-system) |
1159 |
(if (and coding-system buffer-file-coding-system (null force)) |
(if (and coding-system buffer-file-coding-system (null force)) |
1164 |
;; `set-buffer-major-mode-hook' take care of setting the table. |
;; `set-buffer-major-mode-hook' take care of setting the table. |
1165 |
(if (fboundp 'ucs-set-table-for-input) ; don't lose when building |
(if (fboundp 'ucs-set-table-for-input) ; don't lose when building |
1166 |
(ucs-set-table-for-input)) |
(ucs-set-table-for-input)) |
1167 |
(set-buffer-modified-p t) |
(unless nomodify |
1168 |
|
(set-buffer-modified-p t)) |
1169 |
(force-mode-line-update)) |
(force-mode-line-update)) |
1170 |
|
|
1171 |
(defun revert-buffer-with-coding-system (coding-system &optional force) |
(defun revert-buffer-with-coding-system (coding-system &optional force) |
1740 |
(find-new-buffer-file-coding-system last-coding-system-used)) |
(find-new-buffer-file-coding-system last-coding-system-used)) |
1741 |
(modified-p (buffer-modified-p))) |
(modified-p (buffer-modified-p))) |
1742 |
(when coding-system |
(when coding-system |
1743 |
(set-buffer-file-coding-system coding-system t) |
;; Tell set-buffer-file-coding-system not to mark the file |
1744 |
|
;; as modified; we just read it, and it's supposed to be unmodified. |
1745 |
|
;; Marking it modified would try to lock it, which would |
1746 |
|
;; check the modtime, and we don't want to do that again now. |
1747 |
|
(set-buffer-file-coding-system coding-system t t) |
1748 |
(if (and enable-multibyte-characters |
(if (and enable-multibyte-characters |
1749 |
(or (eq coding-system 'no-conversion) |
(or (eq coding-system 'no-conversion) |
1750 |
(eq (coding-system-type coding-system) 5)) |
(eq (coding-system-type coding-system) 5)) |
1754 |
(= (buffer-size) inserted)) |
(= (buffer-size) inserted)) |
1755 |
;; For coding systems no-conversion and raw-text..., |
;; For coding systems no-conversion and raw-text..., |
1756 |
;; edit the buffer as unibyte. |
;; edit the buffer as unibyte. |
1757 |
(let ((pos-marker (copy-marker (+ (point) inserted)))) |
(let ((pos-marker (copy-marker (+ (point) inserted))) |
1758 |
|
;; Prevent locking. |
1759 |
|
(buffer-file-name nil)) |
1760 |
(set-buffer-multibyte nil) |
(set-buffer-multibyte nil) |
1761 |
(setq inserted (- pos-marker (point))))) |
(setq inserted (- pos-marker (point))))) |
1762 |
(set-buffer-modified-p modified-p)))) |
(set-buffer-modified-p modified-p)))) |