你如何自动化查找定向查询替换?
How can you automate a find-dired query-replace?
M-x find-dired
:系统将提示您输入根目录和文件名模式。
- 找到所有文件,按
t
到 "toggle mark"。
- 按
Q
获得 "Query-Replace in Files..."
- 系统将提示您输入 query/substitution 正则表达式。
如何定义像 my-find-dired
这样的函数,它会为您执行步骤 1-3,在步骤 1 中使用目录 /foo
和文件名 -iname \*.html
,然后直接带您到第 4 步?
编辑 fn def:
我得到了第 4 步的提示,但它没有做任何事情,因为 none 个文件被标记了,所以我认为倒数第二行一定是错误的。这里有一些尝试:
(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))
也刚试过"*"
(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))
从程序调用时,方法与使用交互式调用略有不同。那这样呢:
(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))
M-x find-dired
:系统将提示您输入根目录和文件名模式。- 找到所有文件,按
t
到 "toggle mark"。 - 按
Q
获得 "Query-Replace in Files..." - 系统将提示您输入 query/substitution 正则表达式。
如何定义像 my-find-dired
这样的函数,它会为您执行步骤 1-3,在步骤 1 中使用目录 /foo
和文件名 -iname \*.html
,然后直接带您到第 4 步?
编辑 fn def:
我得到了第 4 步的提示,但它没有做任何事情,因为 none 个文件被标记了,所以我认为倒数第二行一定是错误的。这里有一些尝试:
(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))
也刚试过"*"
(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))
从程序调用时,方法与使用交互式调用略有不同。那这样呢:
(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))