【问题标题】:See the compilation screen only when it is necessary仅在必要时查看编译屏幕
【发布时间】:2016-01-22 17:05:06
【问题描述】:

我已将(global-set-key "\C-x\C-m" 'compile) 放入我的.emacs。结果在Emacs下,如果我使用快捷方式C-x C-m C-m,1) 询问是否要保存修改; 2)Emacs下会打开另一个缓冲区,显示编译的地方(另外,编译结束并没有系统显示,需要手动向下浏览)。

是否可以不让包含编译的缓冲区受到干扰?

理想情况下,我希望C-x C-m C-m 切换编译(我想默认保存修改)。如果没有错误,我不想看到编译画面;否则,我会找到屏幕并看到错误消息。

有人知道是否可以设置吗?

编辑 1:

根据@maxy 的回答,我修改了.emacs 并做了一些测试。奇怪的是,有两种情况:

1)如果上一次编译成功,再一次编译会产生一个缓冲区,编译后缓冲区不会被删除:

2)如果上一次编译不成功,删除编译缓冲区并更正tex文件中的错误后,再次编译会生成一个缓冲区,然后编译后删除缓冲区。

有人知道怎么解决吗?

编辑 2:

我明白了。在@maxy 的答案中,将(run-at-time 0.5 nil 'delete-windows-on buf) 更改为(run-at-time 0.5 nil 'delete-other-windows) 即可。

【问题讨论】:

    标签: emacs


    【解决方案1】:

    EmacsWiki,将以下内容放入您的 .emacs:

    ;; If there were no compilation errors, delete the compilation window
    (setq compilation-exit-message-function
          (lambda (status code msg)
            ;; If M-x compile exists with a 0
            (when (and (eq status 'exit) (zerop code))
              ;; then bury the *compilation* buffer, so that C-x b doesn't go there
              (bury-buffer "*compilation*")
              ;; and return to whatever were looking at before
              (replace-buffer-in-windows "*compilation*"))
            ;; Always return the anticipated result of compilation-exit-message-function
            (cons msg code)))
    

    这实际上会短暂显示窗口,但如果没有错误则会立即将其删除,并恢复它替换的任何窗口。

    此外,您可以让 Emacs 滚动到第一个错误或编译缓冲区的末尾,如下所示:

    (require 'cl)
    
    (setq
     ;; Either
     compilation-scroll-output 'first-error      ;; scroll until first error
     ;; or
     compilation-scroll-output 't                ;; scroll to bottom
    )
    

    【讨论】:

    • 谢谢...这样更好,但是如果没有错误,它不会删除编译缓冲区。
    • 有警告吗?如果是这样,您还需要添加(setq compilation-skip-threshold 2) ;; skip warnings
    • 它确实删除了编译消息;编译缓冲区仍然存在,它被内存中的另一个文本或 Emacs 欢迎页面(欢迎来到 GNU Emacs...Emacs Tutorial...Emacs Guided Tour...)填充。如果没有编译错误,我只想系统地删除创建的缓冲区。
    【解决方案2】:

    我很久以前就解决了这个问题,以至于我认为这是 emacs 的默认设置。可悲的是它不是。来自我的emacs.el

    ;; get rid of compilation window on success
    ;; source: http://www.bloomington.in.us/~brutt/emacs-c-dev.html [dead link]
    (setq compilation-finish-function
          (lambda (buf str)
            (if (string-match "exited abnormally" str)
                ;;there were errors
                ;(message "compilation errors, press C-x ` to visit")
                (message "ERRORs while compiling.")
              ;;no errors, make the compilation window go away in 0.5 seconds
              (run-at-time 0.5 nil 'delete-windows-on buf)
              (message "Compilation done."))))
    

    另外,将M-x customize-variable 用于:

     '(compilation-ask-about-save nil)
     '(compilation-context-lines 0)
     '(compilation-scroll-output t)
     '(compilation-window-height 21)
    

    如果您使用swbuff,请参阅swbuff-exclude-buffer-regexps 的示例以忽略最近使用的缓冲区列表中的*compilation* 缓冲区。

    【讨论】:

    • (run-at-time 0.5 nil 'delete-windows-on buf) 更改为 (run-at-time 0.5 nil 'delete-other-windows) 即可解决问题
    猜你喜欢
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多