From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#4623: 23.1.50; rmail changes encoding of characters on save Date: Mon, 07 Dec 2009 21:22:29 +0200 Message-ID: <83vdgiio7e.fsf@gnu.org> References: <831vjalmrl.fsf@gnu.org> <83y6lik0ug.fsf@gnu.org> <83hbs5k4q6.fsf@gnu.org> <20091205201056.B56E31BA516@ada00.math.uni-bielefeld.de> <837ht1jdft.fsf@gnu.org> <83zl5vj4k0.fsf@gnu.org> <20091206202348.C2EEB1BA334@ada00.math.uni-bielefeld.de> <83y6lfig4t.fsf@gnu.org> Reply-To: Eli Zaretskii , 4623@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1260217102 18521 80.91.229.12 (7 Dec 2009 20:18:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Dec 2009 20:18:22 +0000 (UTC) Cc: rost@math.uni-bielefeld.de To: 4623@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 07 21:18:14 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NHk2A-0003QL-7A for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Dec 2009 21:18:14 +0100 Original-Received: from localhost ([127.0.0.1]:60945 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHk29-0007yo-VN for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Dec 2009 15:18:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHjYc-0001Ts-Qk for bug-gnu-emacs@gnu.org; Mon, 07 Dec 2009 14:47:42 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHjYW-0001JF-BS for bug-gnu-emacs@gnu.org; Mon, 07 Dec 2009 14:47:39 -0500 Original-Received: from [199.232.76.173] (port=52355 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHjYV-0001Ia-LI for bug-gnu-emacs@gnu.org; Mon, 07 Dec 2009 14:47:35 -0500 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:58517) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NHjYV-0003ys-1O for bug-gnu-emacs@gnu.org; Mon, 07 Dec 2009 14:47:35 -0500 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nB7JlUKs003606; Mon, 7 Dec 2009 11:47:32 -0800 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id nB7JU46P001971; Mon, 7 Dec 2009 11:30:04 -0800 Resent-Date: Mon, 7 Dec 2009 11:30:04 -0800 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Eli Zaretskii Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Mon, 07 Dec 2009 19:30:04 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4623 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 4623-submit@emacsbugs.donarmstrong.com id=B4623.12602139081648 (code B ref 4623); Mon, 07 Dec 2009 19:30:04 +0000 Original-Received: (at 4623) by emacsbugs.donarmstrong.com; 7 Dec 2009 19:25:08 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from mtaout20.012.net.il (mtaout20.012.net.il [80.179.55.166]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id nB7JP6qE001509 for <4623@emacsbugs.donarmstrong.com>; Mon, 7 Dec 2009 11:25:08 -0800 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0KUA00G00R4FLW00@a-mtaout20.012.net.il> for 4623@emacsbugs.donarmstrong.com; Mon, 07 Dec 2009 21:24:30 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([77.126.213.252]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0KUA00DAKR8S2MA0@a-mtaout20.012.net.il>; Mon, 07 Dec 2009 21:24:30 +0200 (IST) In-reply-to: <83y6lfig4t.fsf@gnu.org> X-012-Sender: halo1@inter.net.il X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Mon, 07 Dec 2009 14:47:39 -0500 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:33376 Archived-At: > Date: Mon, 07 Dec 2009 06:04:34 +0200 > From: Eli Zaretskii > Cc: 4623@emacsbugs.donarmstrong.com > > > From: Markus Rost > > CC: 4623@emacsbugs.donarmstrong.com > > Date: Sun, 6 Dec 2009 21:23:48 +0100 (CET) > > > > One minor thing: Since rmail-message-encoding is a global variable, > > several Rmail buffers may interfere. > > Right, I didn't think abut that possibility. I will try to think > about some simple solution. I think I found it. If we have to live with rmail-write-region-annotate, we might as well have it do something useful: Index: lisp/mail/rmail.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/mail/rmail.el,v retrieving revision 1.562 diff -u -r1.562 rmail.el --- lisp/mail/rmail.el 4 Dec 2009 05:00:47 -0000 1.562 +++ lisp/mail/rmail.el 7 Dec 2009 19:14:23 -0000 @@ -1316,13 +1316,19 @@ 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 @@ (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.