Subject: bug#1238: ido-write-file makes it easy to overwrite files unintentionally

From: Ryan Twitchell <[email-masked]>
Date: Sat, 13 Nov 2010 09:57:42 -0500

I encountered this problem independently in version 23.2.1, and think I have a very simple fix.

As a drop in replacement for write-file, ido-write-file does not prompt the user for confirmation when overwriting an existing file:

Steps to reproduce:
$ emacs -Q
M-x emacs-version
"GNU Emacs 23.2.1 (x86_64-pc-linux-gnu, GTK+ Version 2.20.1) of 2010-11-07 on falconsrevenge"
M-x ido-mode
C-x C-f new-file
...editing
C-x C-s
C-x C-b new-buffer
...editing
C-x C-w new-file OR M-x ido-write-file<return>new-file
...prompt expected here, but new-file is overwritten.

The function ido-file-internal uses plain old write-file to carry out this action:

Line 2382:
       ((eq method 'write)
	(ido-record-work-file filename)
	(setq default-directory ido-current-directory)
	(setq filename (concat ido-current-directory filename))
	(ido-record-command 'write-file filename)
	(add-to-history 'file-name-history filename)
	(ido-record-work-directory)
	(write-file filename))

ido functions are primarily for interactive use, so it seems safe to pass a true value to write-file's CONFIRM arg (on the last line above) to always enable prompting:

(write-file filename t)

A quick test confirmed this change added the expected behavior.

Ryan Twitchell