From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Rost Newsgroups: gmane.emacs.bugs Subject: bug#4655: 23.1.50; buffer-swap-text oddity Date: Thu, 8 Oct 2009 18:48:39 +0200 (CEST) Message-ID: <20091008164839.BAC66EFE6B@sonic02.math.uni-bielefeld.de> References: <20091006184604.9A5B2EFE6F@sonic02.math.uni-bielefeld.de> Reply-To: Markus Rost , 4655@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1255026498 29773 80.91.229.12 (8 Oct 2009 18:28:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 8 Oct 2009 18:28:18 +0000 (UTC) Cc: lekktu@gmail.com, 4655@emacsbugs.donarmstrong.com To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 08 20:28:08 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 1Mvxie-0003MW-QV for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 Oct 2009 20:28:05 +0200 Original-Received: from localhost ([127.0.0.1]:55854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mvxie-0008Td-6D for geb-bug-gnu-emacs@m.gmane.org; Thu, 08 Oct 2009 14:28:04 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvwSU-00022J-S6 for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2009 13:07:18 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvwSP-0001sp-3n for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2009 13:07:18 -0400 Original-Received: from [199.232.76.173] (port=54929 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvwSO-0001sW-D4 for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2009 13:07:12 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:47246) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvwSN-0005LE-QQ for bug-gnu-emacs@gnu.org; Thu, 08 Oct 2009 13:07:12 -0400 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 n98H79lj024045; Thu, 8 Oct 2009 10:07:09 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n98Gt6gm021385; Thu, 8 Oct 2009 09:55:06 -0700 Resent-Date: Thu, 8 Oct 2009 09:55:06 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Markus Rost Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Thu, 08 Oct 2009 16:55:06 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4655 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 4655-submit@emacsbugs.donarmstrong.com id=B4655.125502053020546 (code B ref 4655); Thu, 08 Oct 2009 16:55:06 +0000 Original-Received: (at 4655) by emacsbugs.donarmstrong.com; 8 Oct 2009 16:48:50 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from xen16.math.uni-bielefeld.de (xen16.math.uni-bielefeld.de [129.70.14.14]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n98Gmmiu020539 for <4655@emacsbugs.donarmstrong.com>; Thu, 8 Oct 2009 09:48:50 -0700 Original-Received: from sonic02.math.uni-bielefeld.de (sonic02.math.uni-bielefeld.de [129.70.14.134]) by xen16.math.uni-bielefeld.de (Postfix) with ESMTP id 5993930072C2; Thu, 8 Oct 2009 18:48:42 +0200 (CEST) Original-Received: by sonic02.math.uni-bielefeld.de (Postfix, from userid 3710) id BAC66EFE6B; Thu, 8 Oct 2009 18:48:39 +0200 (CEST) In-reply-to: (message from Stefan Monnier on Wed, 07 Oct 2009 10:29:11 -0400) X-GNU-Emacs-Mailer: GNU Emacs 22.3 X-Home-Page: http://www.math.uni-bielefeld.de/~rost X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Thu, 08 Oct 2009 13:07:18 -0400 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:31788 Archived-At: A follow up to my previous message: If you look at the end of rmail-cease-edit: (save-excursion (rmail-show-message) (rmail-toggle-header (if pruned 1 0)))) (run-hooks 'rmail-mode-hook)) the question arises in which buffer rmail-mode-hook should be run? One may check with (add-hook 'rmail-mode-hook (lambda () (message "foo: %s" (current-buffer)))) that currently it runs in rmail-view-buffer, which is perhaps not what one expects. Changing to (rmail-show-message) (save-excursion (rmail-toggle-header (if pruned 1 0)))) (run-hooks 'rmail-mode-hook)) is probably OK. That would be in line with Stefan's point: > 5- most uses of save-excursion are wrong, ======= Here are more issues related to the usage of buffer-swap-text: I tried to fix (I think this bug should be fixed before the next release: The mbox files should not be corrupted.) with the patch below. See also the thread of It seems to work, except that after a save ('s' in Rmail) the rmail-buffer gets a wrong value of buffer-file-coding-system (to be seen in the mode line). Only temporarily, switching back and forth to another message in Rmail restores the correct value of buffer-file-coding-system. After further debugging, it turned out that the problem sits in ;; 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)) (set-buffer rmail-view-buffer) (widen) nil)) Namely, when rmail-expunge-and-save calls save-buffer, then, with rmail-write-region-annotate in write-region-annotate-functions, save-buffer and basic-save-buffer* write the rmail-view-buffer to the file (which is correct) but then set the buffer-file-coding-system to last-coding-system-used in the rmail-buffer (which is not correct). It seems that generally write-region-annotate-functions should not change the buffer to be written. (What if arg START of write-region is a buffer position?) ===File ~/.emacs.d/rmail/rmail23/bug/rmail-swap.diff======== *** rmail.el 06 Oct 2009 13:20:10 +0200 1.554 --- rmail.el 08 Oct 2009 14:07:01 +0200 *************** *** 1306,1320 **** (defun rmail-swap-buffers () "Swap text between current buffer and `rmail-view-buffer'. ! 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 (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))) (defun rmail-buffers-swapped-p () --- 1306,1322 ---- (defun rmail-swap-buffers () "Swap text between current buffer and `rmail-view-buffer'. ! This function preserves the current buffer's modified flag and ! also swaps the value of `buffer-file-coding-system'." (let ((modp (buffer-modified-p)) + (coding0 buffer-file-coding-system) (coding (with-current-buffer rmail-view-buffer buffer-file-coding-system))) (buffer-swap-text rmail-view-buffer) (setq buffer-file-coding-system coding) + (with-current-buffer rmail-view-buffer + (setq buffer-file-coding-system coding0)) (restore-buffer-modified-p modp))) (defun rmail-buffers-swapped-p () ============================================================