Emacs(重新编译 -y)

7

在emacs的“重新编译”命令中,是否可以传递“-yes”标志?

请原谅我完全不了解(e)lisp。我厌倦了在Emacs之外编译我的latex代码,因此我将以下键绑定添加到了我的.emacs文件中:

(global-set-key (kbd "<f12>") 'recompile);

有没有可能自动回答以下可能出现的提示:“编译进程正在运行;杀死它?(是或否)”?

此外,是否可以使打开并显示输出的窗口自动滚动到底部。有趣的东西通常在那里。也许可以在重新编译后链接以下命令:“C-x o,end-of-buffer”。

谢谢!


1
或者你可以直接将“-halt-on-error”传递给“pdflatex”(或类似的程序)。 - cYrus
5个回答

7
这里有一些代码可以解决你的第一个问题(中断当前编译):

(defun interrupt-and-recompile ()
  "Interrupt old compilation, if any, and recompile."
  (interactive)
  (ignore-errors (kill-compilation))
  (recompile))

关于你的第二个问题(滚动编译输出),只需自定义用户设置compilation-scroll-output即可。


3
这种行为受到compilation-always-kill全局变量的控制。通过customize-variable进行定制,并将其设置为t即可。不确定最早出现在哪个版本的emacs中,但26及以上版本肯定有此功能。

1
“NEWS.24” 表示它是在 Emacs 24.3 中添加的。 - phils

2

我需要在Emacs 23.2中将kill-compilation放入ignore-errors中,以便在没有进程运行时使其正常工作。否则它的表现非常好。

(defun interrupt-and-recompile ()
  "Interrupt old compilation, if any, and recompile."
  (interactive)
  (ignore-errors
    (kill-compilation))
  (recompile)
)

2
每当我尝试使用 kill-compilation 命令来终止latex/pdflatex进程时,都会失败。我猜测这是因为latex无法响应SIGINT信号。
相反,我正在使用以下hack方法:首先设置compilation缓冲区的process-kill-without-query位,然后关闭它(这会杀死运行中的进程)。
(defun interrupt-and-recompile ()
  "Interrupt old compilation, if any, and recompile."
  (interactive)
  (ignore-errors 
    (process-kill-without-query 
      (get-buffer-process
        (get-buffer "*compilation*"))))
  (ignore-errors 
    (kill-buffer "*compilation*"))
  (recompile)
)

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接