简体   繁体   English

如何删除带有感叹号的文件! 使用emacs的删除文件

[英]How to delete files with exclamation marks! using emacs' delete-file

I'm trying to make emacs' delete-file function delete files with exclamation marks in their names. 我试图使emacs的delete-file函数删除名称中带有感叹号的文件。

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. 特殊的用例是我将emacs设置为将所有备份文件保存在一个目录中,并删除旧的备份文件。 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. 在名称中带有感叹号的文件上调用delete-file时,它将返回零,并且不会删除该文件。 It doesn't signal any error. 它不表示任何错误。 Normally, delete-file returns nil. 通常,delete-file返回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. 无论如何,emacs的备份系统使用delete-file进行删除,我宁愿不重新定义整个功能,而只是更改一行。

I've tried backslashing the exclamation marks and shell-quoting the filename string, and neither has worked. 我尝试用反斜杠将感叹号和shell引用文件名字符串,但都没有用。 I found out that something in my config is causing this, but I haven't figured out what yet. 我发现配置中的某些原因导致了这种情况,但是我还没有弄清楚是什么原因。 I have tracked the source of the problem to my custom system-move-file-to-trash function, which I now have to debug. 我已将问题的来源跟踪到我的自定义system-move-file-to-trash函数中,现在必须对其进行调试。

So, how can I make this work? 那么,我该如何做呢?

Emacs version: GNU Emacs 23.1.50.1 Emacs版本:GNU Emacs 23.1.50.1
emacs-snapshot: Installed: 1:20090730-1~jaunty1 emacs快照:已安装:1:20090730-1〜jaunty1

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, Lisp调用也是如此,

(delete-file "!home!blah!filename")

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. 我自定义的system-move-file-to-trash功能,该删除文件将自动使用,在文件名上不恰当地称为shell-quote-argument Apparently arguments to a command run using call-process do not need to be shell-quoted. 显然,使用参数命令运行call-process 并不需要是壳报价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM