问题 如何使Emacs中的编译窗口始终具有一定的大小?


我想让Emacs中的编辑窗口始终显示在窗口的底部,并且始终是一定的高度。到目前为止,我将以下几行放在我的.emacs文件中:

(setq split-height-threshold 0)
(setq compilation-window-height 10)

...当我只有一个窗口打开时,它确实有效,但只要我将屏幕水平分割成两个窗口(即中间的分界线从顶部到底部),编译窗口停止尊重高度变量,并将窗口右侧分开。

我该如何解决?


2875
2018-03-15 17:29


起源

popw​​in 如Amardeep建议的那样有用。 - kenorb


答案:


我会使用这样的东西,从中自由改编 EmacsWiki

(defun my-compilation-hook ()
  (when (not (get-buffer-window "*compilation*"))
    (save-selected-window
      (save-excursion
        (let* ((w (split-window-vertically))
               (h (window-height w)))
          (select-window w)
          (switch-to-buffer "*compilation*")
          (shrink-window (- h compilation-window-height)))))))
(add-hook 'compilation-mode-hook 'my-compilation-hook)

如果 *compilation* 缓冲区不可见,这将垂直分割窗口,将新打开的窗口调整为10行高,然后打开 *compilation* 缓冲在里面。


13
2018-03-15 21:21



你知道如何修补它,所以它总是在当前的底部 帧,不是窗户?我的意思是以下情况:编辑一些东西,C-x 2将窗口分成两半,M-x编译时留在顶部窗口。你的代码在顶级胜利的底部打开编译,在框架的底部打开它会更好... - Mekk
@Mekk我在下面发布了修订版 要旨 - Francesco
非常感谢,看起来很酷。还有一件事情会很好,但在这里我不确定它是否可行 - 使编译共享窗口具有很少的类似派生模式(在我的情况下,这些是大多数 确认 要么 银,但我想 发生 要么 (部分)的grep 需要相同的)。我试图自己寻找解决方案,但我不知道如何告诉emacs“请打开这个你刚刚在窗口中创建的编译 确认)(仍然,再次感谢你当前的代码) - Mekk
关于你的代码(两个版本)的一个注释:我将用compilation-window-height替换10,然后这个代码片段可由该标准自定义var配置.... - Mekk
@Mekk我认为为各种编译缓冲区选择一个窗口的问题并不是那么微不足道,并且值得一个完整的问题,无论是在SO,还是在 emacs.stackexchange.com - Francesco


您可以自定义变量 compilation-window-height


1
2018-03-15 19:18





结合来自的代码 如何防止emacs打开编辑输出的新窗口? 和来自的代码 http://www.emacswiki.org/emacs/CompilationMode,这是我的所有代码 compile,它为您提供4个功能:

1)。使用 compile-again 自动运行与上次相同的编译,没有提示。如果没有最后一次,或者有一个前缀参数,它就像M-x编译一样。

2)。 compile 将拆分当前窗口(永远是一定的规模),它不会影响此框架中的其他窗口。

3)。它会自动关闭 *compilation* 缓冲区(窗口)如果没有错误,如果错误存在则保留它。

4)。它将突出显示源代码的错误行和行号 *compilation* 缓冲,使用 M-n/p 导航中的每个错误 *compilation* 缓冲, Enter 在错误行中跳转到代码中的行。

(require 'compile)
(setq compilation-last-buffer nil)
(defun compile-again (ARG)
  "Run the same compile as the last time.

If there is no last time, or there is a prefix argument, this acts like M-x compile."
  (interactive "p")
  (if (and (eq ARG 1)
           compilation-last-buffer)
      (progn
        (set-buffer compilation-last-buffer)
        (revert-buffer t t))
    (progn
      (call-interactively 'compile)
      (setq cur (selected-window))
      (setq w (get-buffer-window "*compilation*"))
      (select-window w)
      (setq h (window-height w))
      (shrink-window (- h 10))
      (select-window cur))))
(global-set-key (kbd "C-x C-m") 'compile-again)
(defun my-compilation-hook ()
  "Make sure that the compile window is splitting vertically."
  (progn
    (if (not (get-buffer-window "*compilation*"))
        (progn
          (split-window-vertically)))))
(add-hook 'compilation-mode-hook 'my-compilation-hook)
(defun compilation-exit-autoclose (STATUS code msg)
  "Close the compilation window if there was no error at all."
  ;; 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)
    ;; and delete the *compilation* window
    (delete-window (get-buffer-window (get-buffer "*compilation*"))))
  ;; Always return the anticipated result of compilation-exit-message-function
  (cons msg code))
(setq compilation-exit-message-function 'compilation-exit-autoclose)
(defvar all-overlays ())
(defun delete-this-overlay(overlay is-after begin end &optional len)
  (delete-overlay overlay)
  )
(defun highlight-current-line ()
"Highlight current line."
  (interactive)
  (setq current-point (point))
  (beginning-of-line)
  (setq beg (point))
  (forward-line 1)
  (setq end (point))
  ;; Create and place the overlay
  (setq error-line-overlay (make-overlay 1 1))

  ;; Append to list of all overlays
  (setq all-overlays (cons error-line-overlay all-overlays))

  (overlay-put error-line-overlay
               'face '(background-color . "red"))
  (overlay-put error-line-overlay
               'modification-hooks (list 'delete-this-overlay))
  (move-overlay error-line-overlay beg end)
  (goto-char current-point))
(defun delete-all-overlays ()
  "Delete all overlays"
  (while all-overlays
    (delete-overlay (car all-overlays))
    (setq all-overlays (cdr all-overlays))))
(defun highlight-error-lines(compilation-buffer process-result)
  (interactive)
  (delete-all-overlays)
  (condition-case nil
      (while t
        (next-error)
        (highlight-current-line))
    (error nil)))
(setq compilation-finish-functions 'highlight-error-lines)

1
2018-02-01 22:51