all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#19576: 24.4; Broken function in `window-size-change-functions' cause `write-file' to write the wrong buffer
@ 2015-01-12 23:37 Anders Lindgren
  2015-11-16 19:18 ` bug#19576: write-file writes " Anders Lindgren
                   ` (2 more replies)
  0 siblings, 3 replies; 77+ messages in thread
From: Anders Lindgren @ 2015-01-12 23:37 UTC (permalink / raw)
  To: 19576

[-- Attachment #1: Type: text/plain, Size: 5017 bytes --]

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:
<escape> x e v a l - b u f <tab> <return> <escape>
x e <backspace> t e s t - e <backspace> w <tab> <return>
y <escape> x r e p o <tab> o <backspace> r <tab> <
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))

[-- Attachment #2: Type: text/html, Size: 6654 bytes --]

^ permalink raw reply	[flat|nested] 77+ messages in thread

end of thread, other threads:[~2015-11-30 17:27 UTC | newest]

Thread overview: 77+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-12 23:37 bug#19576: 24.4; Broken function in `window-size-change-functions' cause `write-file' to write the wrong buffer Anders Lindgren
2015-11-16 19:18 ` bug#19576: write-file writes " Anders Lindgren
2015-11-16 19:46   ` martin rudalics
2015-11-16 20:05     ` Anders Lindgren
2015-11-17  0:55       ` Juri Linkov
2015-11-17 20:02         ` Alan Mackenzie
2015-11-17 21:52           ` Anders Lindgren
2015-11-18  0:27             ` Juri Linkov
2015-11-18  1:37               ` Drew Adams
2015-11-18  7:54               ` Anders Lindgren
2015-11-18 17:45           ` Eli Zaretskii
2015-11-18 23:23             ` Alan Mackenzie
2015-11-19 16:03               ` Eli Zaretskii
2015-11-20  8:22                 ` martin rudalics
2015-11-20 10:17                   ` Eli Zaretskii
2015-11-20 10:48                     ` martin rudalics
2015-11-20 11:16                       ` Eli Zaretskii
2015-11-20 11:25                         ` martin rudalics
2015-11-20 11:40                           ` Eli Zaretskii
2015-11-20 14:21                             ` martin rudalics
2015-11-20 14:54                               ` Eli Zaretskii
2015-11-21 11:35                 ` Eli Zaretskii
2015-11-21 15:56                   ` Alan Mackenzie
2015-11-21 16:01                     ` Eli Zaretskii
2015-11-21 16:49                       ` Anders Lindgren
2015-11-21 17:10                         ` Eli Zaretskii
2015-11-21 18:27                         ` martin rudalics
2015-11-21 18:33                           ` Eli Zaretskii
2015-11-21 18:44                             ` martin rudalics
2015-11-21 19:08                               ` Eli Zaretskii
2015-11-21 20:33                                 ` Anders Lindgren
2015-11-22 10:44                                 ` martin rudalics
2015-11-22 15:36                                   ` Eli Zaretskii
2015-11-21 16:02                     ` bug#21333: " Eli Zaretskii
2015-11-22 11:08                   ` martin rudalics
2015-11-22 15:39                     ` Eli Zaretskii
2015-11-22 17:46                       ` martin rudalics
2015-11-23 18:21                         ` Eli Zaretskii
2015-11-23 18:28                           ` Alan Mackenzie
2015-11-24  8:27                           ` martin rudalics
2015-11-24 16:19                             ` Eli Zaretskii
2015-11-28 10:26                   ` martin rudalics
2015-11-28 11:27                     ` Eli Zaretskii
2015-11-30 13:30                       ` martin rudalics
2015-11-30 16:28                         ` Eli Zaretskii
2015-11-30 17:27                           ` martin rudalics
2015-11-19  8:13             ` martin rudalics
2015-11-19 15:45               ` Eli Zaretskii
2015-11-20  8:22                 ` martin rudalics
2015-11-20  8:34                   ` Eli Zaretskii
2015-11-20 10:25                     ` martin rudalics
2015-11-20 11:15                       ` Eli Zaretskii
2015-11-20 11:25                         ` martin rudalics
2015-11-20 11:39                           ` Eli Zaretskii
2015-11-20 14:21                             ` martin rudalics
2015-11-20 11:32                         ` Alan Mackenzie
2015-11-20 11:41                           ` Eli Zaretskii
2015-11-17 21:15         ` Anders Lindgren
2015-11-18 17:52           ` Eli Zaretskii
2015-11-18 19:23             ` Anders Lindgren
2015-11-18 20:52               ` Eli Zaretskii
2015-11-19  2:06                 ` John Wiegley
2015-11-19  6:54                 ` Anders Lindgren
2015-11-19 15:31                   ` Eli Zaretskii
2015-11-22 18:44                     ` Johan Bockgård
2015-11-22 18:55                       ` Johan Bockgård
2015-11-22 19:02                       ` Eli Zaretskii
2015-11-17  8:34       ` martin rudalics
2015-11-17 19:08         ` Anders Lindgren
2015-11-18 17:24         ` Eli Zaretskii
2015-11-19  8:12           ` martin rudalics
2015-11-19 15:44             ` Eli Zaretskii
2015-11-20  8:22               ` martin rudalics
2015-11-20  8:32                 ` Eli Zaretskii
     [not found] ` <mailman.9.1447720293.31583.bug-gnu-emacs@gnu.org>
2015-11-17 22:10   ` Alan Mackenzie
2015-11-18  7:09     ` martin rudalics
2015-11-20 20:17 ` bug#19576: Fixed: " Anders Lindgren

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.