在文件上运行批处理emacs命令

时间:2013-10-07 19:49:00

标签: emacs batch-processing

要清理一些文件,我需要执行一系列步骤,这些步骤的emacs代码是

(query-replace "," " " nil 
  (if (and transient-mark-mode mark-active) 
    (region-beginning)) 
  (if (and transient-mark-mode mark-active) 
    (region-end)))

(query-replace "1 1/4" "1.25" nil 
  (if (and transient-mark-mode mark-active) 
    (region-beginning)) 
  (if (and transient-mark-mode mark-active) 
    (region-end)))

(query-replace-regexp "[0-9][0-9][0-9]V[0-9][0-9][0-9] " "" nil 
  (if (and transient-mark-mode mark-active) 
    (region-beginning)) 
  (if (and transient-mark-mode mark-active) 
    (region-end)))

(还有更多,但你明白了) 有没有办法将所有这些命令放在一个文件中并运行它们?或者也许在lisp文件中为它们指定一个名称并按名称运行它们?

1 个答案:

答案 0 :(得分:2)

您可以参考manual的此部分。 把你想要做的所有东西放在一个超级函数foo中。 把它放进~/bar.el。 然后这将完成工作:

emacs --batch -l ~/bar.el -f foo

UPD:一个小例子

加入~/bar.el

(defun foo ()
  (goto-char (point-min))
  (replace-regexp "foo" "bar")
  (goto-char (point-min))
  (replace-regexp "fred" "barney")
  (save-buffer))

创建测试文件:

echo "Fred walks into a foo" > test.txt

现在测试一下:

emacs --batch -l ~/bar.el test.txt -f foo
相关问题