summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2009-12-07 19:21:57 +0000
committerEli Zaretskii <eliz@gnu.org>2009-12-07 19:21:57 +0000
commit5e7a90229a1c32ded160a6d27f4ad9f3c66f60c3 (patch)
tree16af8c5ed66737a0bdc89114085c9671805ca6e7
parent9136e895236df7ca44c13aca1cc0bdc3408186ab (diff)
downloademacs-5e7a90229a1c32ded160a6d27f4ad9f3c66f60c3.tar.gz
Prevent save-buffer in Rmail buffers from using the coding-system
of the current message, and from clobbering the encoding mnemonics in the mode line (Bug#4623). (rmail-swap-buffers): Swap encoding and modified flag, too. (rmail-message-encoding): New variable. (rmail-write-region-annotate): Record the encoding of the current message in rmail-message-encoding. (rmail-after-save-hook): New function, restores the encoding of the current message after the message collection is saved.
-rw-r--r--lisp/ChangeLog14
-rw-r--r--lisp/mail/rmail.el35
2 files changed, 42 insertions, 7 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 01096305437..9a13c3d51d8 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
+2009-12-07 Eli Zaretskii <eliz@gnu.org>
+
+ Prevent save-buffer in Rmail buffers from using the coding-system
+ of the current message, and from clobbering the encoding mnemonics
+ in the mode line (Bug#4623).
+
+ * mail/rmail.el (rmail-swap-buffers): Swap encoding and modified
+ flag, too.
+ (rmail-message-encoding): New variable.
+ (rmail-write-region-annotate): Record the encoding of the current
+ message in rmail-message-encoding.
+ (rmail-after-save-hook): New function, restores the encoding of
+ the current message after the message collection is saved.
+
2009-12-07 Juri Linkov <juri@jurta.org>
* progmodes/grep.el (grep-read-files): Use `completing-read'
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 18fd1f6f727..21be36fae38 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -1316,13 +1316,19 @@ Create the buffer if necessary."
This function preserves the current buffer's modified flag, and also
sets the current buffer's `buffer-file-coding-system' to that of
`rmail-view-buffer'."
- (let ((modp (buffer-modified-p))
- (coding
+ (let ((modp-this (buffer-modified-p))
+ (modp-that
+ (with-current-buffer rmail-view-buffer (buffer-modified-p)))
+ (coding-this buffer-file-coding-system)
+ (coding-that
(with-current-buffer rmail-view-buffer
buffer-file-coding-system)))
(buffer-swap-text rmail-view-buffer)
- (setq buffer-file-coding-system coding)
- (restore-buffer-modified-p modp)))
+ (setq buffer-file-coding-system coding-that)
+ (with-current-buffer rmail-view-buffer
+ (setq buffer-file-coding-system coding-this)
+ (restore-buffer-modified-p modp-that))
+ (restore-buffer-modified-p modp-this)))
(defun rmail-buffers-swapped-p ()
"Return non-nil if the message collection is in `rmail-view-buffer'."
@@ -4179,16 +4185,31 @@ encoded string (and the same mask) will decode the string."
(add-to-list 'desktop-buffer-mode-handlers
'(rmail-mode . rmail-restore-desktop-buffer))
+;; We use this to record the encoding of the current message before
+;; saving the message collection.
+(defvar rmail-message-encoding nil)
+
;; Used in `write-region-annotate-functions' to write rmail files.
(defun rmail-write-region-annotate (start end)
(when (and (null start) (rmail-buffers-swapped-p))
+ (setq rmail-message-encoding buffer-file-coding-system)
(set-buffer rmail-view-buffer)
- ;; Prevent viewing different messages from messing up the coding. (Bug#4623)
- ;; FIXME is there a better solution?
- (set (make-local-variable 'coding-system-for-write) 'no-conversion)
(widen)
nil))
+;; Used to restore the encoding of the buffer where we show the
+;; current message, after we save the message collection. This is
+;; needed because rmail-write-region-annotate switches buffers behind
+;; save-file's back, with the side effect that last-coding-system-used
+;; is assigned to buffer-file-coding-system of the wrong buffer.
+(defun rmail-after-save-hook ()
+ (if (or (eq rmail-view-buffer (current-buffer))
+ (eq rmail-buffer (current-buffer)))
+ (with-current-buffer
+ (if (rmail-buffers-swapped-p) rmail-buffer rmail-view-buffer)
+ (setq buffer-file-coding-system rmail-message-encoding))))
+(add-hook 'after-save-hook 'rmail-after-save-hook)
+
;;; Start of automatically extracted autoloads.