[英]How can you automate a find-dired query-replace?
Mx find-dired
: you will be prompted for a root directory and a filename pattern. Mx find-dired
:将提示您输入根目录和文件名模式。 t
to "toggle mark" for all files found. t
来“切换标记”。 Q
for "Query-Replace in Files..." Q
进行“查询替换文件...” How can you define a function like my-find-dired
that goes through steps 1-3 for you, using in step 1 dir /foo
and filename -iname \\*.html
, and takes you straight to step 4? 如何在步骤1中使用dir
/foo
和filename -iname \\*.html
来定义类似my-find-dired
的函数,该函数会为您执行步骤1-3,并直接进入步骤4?
EDIT working on fn def: 编辑在fn def上工作:
I get the step 4 prompting, but it doesn't do anything, because none of the files are marked, so I'm thinking the second-to-last line must be wrong. 我得到第4步的提示,但是它没有做任何事情,因为没有标记任何文件,因此我认为倒数第二行一定是错误的。 Here are a couple tries:
这里有一些尝试:
(defun my-find-dired-and-replace ()
(interactive)
(find-dired "~/foo/" "-iname \*.html -o -iname \*.coffee -o -iname \*.styl")
(dired-mark-files-containing-regexp "\*")
(call-interactively 'dired-do-query-replace-regexp))
also tried just "*"
还尝试了
"*"
(defun my-find-dired-and-replace ()
(interactive)
(find-dired "~/foo/" "-iname \*.html -o -iname \*.coffee -o -iname \*.styl")
(dired-toggle-marks)
(call-interactively 'dired-do-query-replace-regexp))
When calling from a program, the approach will be slightly different than using interactive calls. 从程序调用时,该方法与使用交互式调用略有不同。 What about that way:
那怎么办:
(defun my-find-dired-and-replace ()
(interactive)
(find-name-dired "MY-DIR" "*.html")
(dired-mark-files-containing-regexp MY_REGEXP)
(dired-do-query-replace-regexp FROM TO))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.