From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anders Lindgren Newsgroups: gmane.emacs.bugs Subject: bug#19576: 24.4; Broken function in `window-size-change-functions' cause `write-file' to write the wrong buffer Date: Tue, 13 Jan 2015 00:37:53 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b5d98afc0fc0a050c7cfe75 X-Trace: ger.gmane.org 1421105959 19848 80.91.229.3 (12 Jan 2015 23:39:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 12 Jan 2015 23:39:19 +0000 (UTC) To: 19576@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 13 00:39:14 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YAoZk-0001JR-Uv for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Jan 2015 00:39:13 +0100 Original-Received: from localhost ([::1]:36708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAoZk-0002Gn-91 for geb-bug-gnu-emacs@m.gmane.org; Mon, 12 Jan 2015 18:39:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAoZe-0002GS-Uq for bug-gnu-emacs@gnu.org; Mon, 12 Jan 2015 18:39:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YAoZa-0002h2-RF for bug-gnu-emacs@gnu.org; Mon, 12 Jan 2015 18:39:06 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAoZa-0002gy-OF for bug-gnu-emacs@gnu.org; Mon, 12 Jan 2015 18:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YAoZa-0002h7-Hp for bug-gnu-emacs@gnu.org; Mon, 12 Jan 2015 18:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Anders Lindgren Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Jan 2015 23:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 19576 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.142110589210264 (code B ref -1); Mon, 12 Jan 2015 23:39:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Jan 2015 23:38:12 +0000 Original-Received: from localhost ([127.0.0.1]:54811 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YAoYl-0002fS-Be for submit@debbugs.gnu.org; Mon, 12 Jan 2015 18:38:12 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:35923) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YAoYg-0002ew-LF for submit@debbugs.gnu.org; Mon, 12 Jan 2015 18:38:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YAoYZ-000271-E4 for submit@debbugs.gnu.org; Mon, 12 Jan 2015 18:38:01 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:50735) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAoYZ-00026v-BP for submit@debbugs.gnu.org; Mon, 12 Jan 2015 18:37:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAoYX-0001py-0G for bug-gnu-emacs@gnu.org; Mon, 12 Jan 2015 18:37:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YAoYU-00022T-VH for bug-gnu-emacs@gnu.org; Mon, 12 Jan 2015 18:37:56 -0500 Original-Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:37254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YAoYU-00021Q-KK for bug-gnu-emacs@gnu.org; Mon, 12 Jan 2015 18:37:54 -0500 Original-Received: by mail-wi0-f173.google.com with SMTP id em10so2041412wid.0 for ; Mon, 12 Jan 2015 15:37:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=ya07l5W/+nMlzS1RtHlsMTOu0rcnU28NS3HsujUIUY8=; b=jyCam0i6ThxZanGm4YK9mm6TXD7gSp8JgBgfabWtJfgLoT7VSBr0KdhetNXpBV4pvT Vt2czrby6qiw3st+r4F3oCL+pif9whh4vrWQ5MqyQmyEKj8qGCFOwIbkbdkrMQwXwtzw WNBgWph/yjDQUip6a5MZB6v9rmBG5xWAIgs3vjRRCyvAE2sWw6Wl8rG5x/QwkIZKfWbg IfUhwqWlC2rPu4ThCVKHpawNwp0Xcs1Hcum0ZQnJnfNQpiHyUbM47yz6weoMZH5hgQ9H xJnEC3kk30wPG8gotcKccSwl1O5E4qixaB1lRjpOo/wQMuqHaQhluBE6vIQXel/G7O2s Otfg== X-Received: by 10.194.6.70 with SMTP id y6mr2259418wjy.97.1421105873089; Mon, 12 Jan 2015 15:37:53 -0800 (PST) Original-Received: by 10.216.92.72 with HTTP; Mon, 12 Jan 2015 15:37:53 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:98279 Archived-At: --047d7b5d98afc0fc0a050c7cfe75 Content-Type: text/plain; charset=UTF-8 Hi! I have noticed that if a broken window size change function is installed, `write-file' will save the content of the wrong buffer. One such broken windows-size-change-function is `follow-window-size-change' of Follow Mode (a package I wrote many years ago). To verify this, place the following piece of code in a buffer and evaluate it (lets call this the CODE buffer). Call M-x test-write-file RET. The code first creates a new file with the content "Alpha", this works OK. It then tries to overwrite the file with the content "Beta", answer "y" when asked to confirm this. Now, the file contains the content of the CODE buffer, and the CODE buffer is associated with the "test.txt" file name, which clearly is incorrect. What happens is that the `y-or-n-p' triggers a window size change callback. `follow-window-size-change' walks through all buffers to check if anything is needed to be done. It then restores the original frame, the original buffer, and the original window. Unfortunately, when restoring the original window, it also sets the buffer associated with the window as current, this causes `write-file' to write the wrong buffer. This will, most likely, affect other functions also using `y-or-n-p', or otherwise trigger a window change callback. Interestingly, the problem only is visible in Emacs 24.3 and 24.4, even though `follow-window-size-change' has been broken much longer than that. This makes me wonder if there has been a change done to the code that calls the functions in `window-size-change-functions'. Of course, this should be corrected in Follow Mode (maybe a simple reordering of the restore expression would suffice). However, it might be a good idea for Emacs to ensure that the correct frame, window, and buffer is set, in case of other broken size change functions. ;;; write-file-bug.el ;; Works in 24.2, broken in 24.3. (require 'follow) ;; This simulates that there is at least one buffer with Follow Mode ;; enabled. (add-hook 'window-size-change-functions 'follow-window-size-change t) (defvar test-write-file--filename "test.txt") (defun test-write-file--write-to-file (s) (with-temp-buffer (insert s) (write-file test-write-file--filename t))) (defun test-write-file () (interactive) (when (file-exists-p test-write-file--filename) (delete-file test-write-file--filename)) (test-write-file--write-to-file "Alpha") (test-write-file--write-to-file "Beta")) ;;; white-file-bug.el ends here. Sincerely, Anders Lindgren In GNU Emacs 24.4.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21) of 2014-10-21 on builder10-9.porkrind.org Windowing system distributor `Apple', version 10.3.1265 Configured using: `configure --with-ns' Important settings: value of $LC_CTYPE: UTF-8 locale-coding-system: utf-8-unix Major mode: Text Minor modes in effect: tooltip-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Recent input: x e v a l - b u f x e t e s t - e w y x r e p o o r < return> Recent messages: For information about GNU Emacs and the GNU system, type C-h C-a. Saving file /Users/anders/emacs/src/bugs/test.txt... Wrote /Users/anders/emacs/src/bugs/test.txt File `test.txt' exists; overwrite? (y or n) y Saving file /Users/anders/emacs/src/bugs/test.txt... Wrote /Users/anders/emacs/src/bugs/test.txt Making completion list... Load-path shadows: None found. Features: (shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util help-fns mail-prsvr mail-utils help-mode follow easymenu vc-dispatcher vc-svn time-date tooltip electric uniquify ediff-hook vc-hooks lisp-float-type mwheel ns-win tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment lisp-mode prog-mode register page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote make-network-process cocoa ns multi-tty emacs) Memory information: ((conses 16 74101 5798) (symbols 48 17581 0) (miscs 40 40 159) (strings 32 10646 4637) (string-bytes 1 280871) (vectors 16 9360) (vector-slots 8 377207 14310) (floats 8 54 183) (intervals 56 224 0) (buffers 960 13)) --047d7b5d98afc0fc0a050c7cfe75 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi!

I have noticed that if a= broken window size change function is installed, `write-file' will sav= e the content of the wrong buffer. One such broken windows-size-change-func= tion is `follow-window-size-change' of Follow Mode (a package I wrote m= any years ago).

To verify this, place the followin= g piece of code in a buffer and evaluate it (lets call this the CODE buffer= ). Call M-x test-write-file RET. The code first creates a new file with the= content "Alpha", this works OK. It then tries to overwrite the f= ile with the content "Beta", answer "y" when asked to c= onfirm this. Now, the file contains the content of the CODE buffer, and the= CODE buffer is associated with the "test.txt" file name, which c= learly is incorrect.

What happens is that the `y-o= r-n-p' triggers a window size change callback. `follow-window-size-chan= ge' walks through all buffers to check if anything is needed to be done= . It then restores the original frame, the original buffer, and the origina= l window. Unfortunately, when restoring the original window, it also sets t= he buffer associated with the window as current, this causes `write-file= 9; to write the wrong buffer.

This will, most like= ly, affect other functions also using `y-or-n-p', or otherwise trigger = a window change callback.

Interestingly, the probl= em only is visible in Emacs 24.3 and 24.4, even though `follow-window-size-= change' has been broken much longer than that. This makes me wonder if = there has been a change done to the code that calls the functions in `windo= w-size-change-functions'.

Of course, this shou= ld be corrected in Follow Mode (maybe a simple reordering of the restore ex= pression would suffice). However, it might be a good idea for Emacs to ensu= re that the correct frame, window, and buffer is set, in case of other brok= en size change functions.

;;; write-file-bug.el

;; Works in 24.2, broken in 24.3.

(require 'follow)

;; This simu= lates that there is at least one buffer with Follow Mode
;; enabl= ed.
(add-hook 'window-size-change-functions 'follow-windo= w-size-change t)

(defvar test-write-file--filename= "test.txt")

(defun test-write-file--wri= te-to-file (s)
=C2=A0 (with-temp-buffer
=C2=A0 =C2=A0 (= insert s)
=C2=A0 =C2=A0 (write-file test-write-file--filename t))= )

(defun test-write-file ()
=C2=A0 (inte= ractive)
=C2=A0 (when (file-exists-p test-write-file--filename)
=C2=A0 =C2=A0 (delete-file test-write-file--filename))
= =C2=A0 (test-write-file--write-to-file "Alpha")
=C2=A0 = (test-write-file--write-to-file "Beta"))

;;; white-file-bug.el ends here.

Sincerely,=
=C2=A0 =C2=A0 Anders Lindgren


In GNU Emacs 24.4.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.= 21)
=C2=A0of 2014-10-21 on builder10-9.porkrind.org
Windowing system distributor `= Apple', version 10.3.1265
Configured using:
=C2=A0`= configure --with-ns'

Important settings:
=
=C2=A0 value of $LC_CTYPE: UTF-8
=C2=A0 locale-coding-system= : utf-8-unix

Major mode: Text

=
Minor modes in effect:
=C2=A0 tooltip-mode: t
=C2= =A0 electric-indent-mode: t
=C2=A0 mouse-wheel-mode: t
= =C2=A0 tool-bar-mode: t
=C2=A0 menu-bar-mode: t
=C2=A0 = file-name-shadow-mode: t
=C2=A0 global-font-lock-mode: t
=C2=A0 font-lock-mode: t
=C2=A0 blink-cursor-mode: t
= =C2=A0 auto-composition-mode: t
=C2=A0 auto-encryption-mode: t
=C2=A0 auto-compression-mode: t
=C2=A0 line-number-mode: = t
=C2=A0 transient-mark-mode: t

Recent i= nput:
<escape> x e v a l - b u f <tab> <return>= <escape>=C2=A0
x e <backspace> t e s t - e <backs= pace> w <tab> <return>=C2=A0
y <escape> x r = e p o <tab> o <backspace> r <tab> <
return&g= t;

Recent messages:
For information abou= t GNU Emacs and the GNU system, type C-h C-a.
Saving file /Users/= anders/emacs/src/bugs/test.txt...
Wrote /Users/anders/emacs/src/b= ugs/test.txt
File `test.txt' exists; overwrite? (y or n) y
Saving file /Users/anders/emacs/src/bugs/test.txt...
Wrot= e /Users/anders/emacs/src/bugs/test.txt
Making completion list...=

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacs= bug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm= -encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendma= il rfc2047 rfc2045 ietf-drums mm-util
help-fns mail-prsvr mail-ut= ils help-mode follow easymenu vc-dispatcher
vc-svn time-date tool= tip electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel = ns-win tool-bar dnd fontset image regexp-opt
fringe tabulated-lis= t newcomment lisp-mode prog-mode register page
menu-bar rfn-eshad= ow timer select scroll-bar mouse jit-lock font-lock
syntax faceme= nu font-core frame cham georgian utf-8-lang misc-lang
vietnamese = tibetan thai tai-viet lao korean japanese hebrew greek
romanian s= lovak czech european ethiopic indian cyrillic chinese
case-table = epa-hook jka-cmpr-hook help simple abbrev minibuffer nadvice
load= defs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtab= le-print-readable backquote make-network-process cocoa ns
multi-t= ty emacs)

Memory information:
((conses 1= 6 74101 5798)
=C2=A0(symbols 48 17581 0)
=C2=A0(miscs 4= 0 40 159)
=C2=A0(strings 32 10646 4637)
=C2=A0(string-b= ytes 1 280871)
=C2=A0(vectors 16 9360)
=C2=A0(vector-sl= ots 8 377207 14310)
=C2=A0(floats 8 54 183)
=C2=A0(inte= rvals 56 224 0)
=C2=A0(buffers 960 13))

--047d7b5d98afc0fc0a050c7cfe75--