views:

195

answers:

2

I'm trying to make emacs' delete-file function delete files with exclamation marks in their names.

The particular use case is that I have set emacs to save all backup files in a single directory and to delete old backup files. However, when all backup files are placed in one directory, the directory separator / is replaced with !. When delete-file is called on a file with an exclamation mark in its name, it returns zero and the file is not deleted. It doesn't signal any error. Normally, delete-file returns nil. Anyway, emacs' backup system uses delete-file for deletion, and I'd rather not redefine the entire function just to change a single line.

I've tried backslashing the exclamation marks and shell-quoting the filename string, and neither has worked.

So, how can I make this work?

Emacs version: GNU Emacs 23.1.50.1
emacs-snapshot: Installed: 1:20090730-1~jaunty1

EDIT: I found out that something in my config is causing this, but I havent figured out what yet. EDIT 2: I have tracked the source of the problem to my custom system-move-file-to-trash function, which I now have to debug.

+2  A: 
M-x delete-file

Then just enter the name of the file, don't escape anything, just the name,

!home!blah!filename

and it just works. And the same goes for the lisp invocation,

(delete-file "!home!blah!filename")
Sujoy
Your observation that delete-file works interactively gave me the clue I needed. I suspect that one of my customizations broke completing-read in some subtle way, so that even when delete-file isn't prompting me for a file, it still breaks somehow.
Ryan Thompson
A: 

I found the answer. My custom system-move-file-to-trash function, which delete-file will automatically use, inappropriately called shell-quote-argument on the file name. Apparently arguments to a command run using call-process do not need to be shell-quoted.

Ryan Thompson