Emacs shell 输出缓冲区高度

3
我在我的.emacs文件中有以下内容(感谢SOer nikwin),它会评估当前缓冲区的内容并在另一个缓冲区中显示输出。
 (defun shell-compile ()
  (interactive)
(save-buffer)
   (shell-command (concat "python " (buffer-file-name))))

 (add-hook 'python-mode-hook
           (lambda () (local-set-key (kbd "\C-c\C-c") 'shell-compile)))

问题在于输出窗口占据了emacs屏幕的一半。是否有办法将输出窗口的高度设置为更小的值?我谷歌搜索了30分钟左右,但没有找到可行的解决方法。先谢过了。

为什么要编写自己的编译命令?已经有了“编译”。 - jrockway
我不太了解emacs lisp(或emacs),因此无法创建将C-c C-c绑定到编译的函数。我在SO上找到了这个函数,它运行得非常好。 - jimbo
2个回答

1

每当源代码缓冲区的高度小于或等于帧高度的一半时,它会将其扩展20行。这很粗糙,但可能能够满足您的需求。

(defun shell-compile ()
  (interactive)
  (save-buffer)
  (shell-command (concat "python " (buffer-file-name)))
  (if (<= (* 2 (window-height)) (frame-height))
      (enlarge-window 20)
    nil))

非常感谢,这个方法非常有效。不过我把行数改成了5而不是20。 - jimbo

0

我之前问过非常类似的问题:emacs programmatically change window size

这是我以前使用 ecb 之前的情况。

(defun collapse-compilation-window (buffer)
  "Shrink the window if the process finished successfully."
  (let ((compilation-window-height 5))
    (compilation-set-window-height (get-buffer-window buffer 0))))

(add-hook 'compilation-finish-functions
          (lambda (buf str)
            (if (string-match "exited abnormally" str)
;               (next-error)
              ;;no errors, make the compilation window go away in a few seconds
              ;(run-at-time "2 sec" nil 'delete-windows-on (get-buffer-create "*compilation*"))
              (collapse-compilation-window buf)
              (message "No Compilation Errors!")
              )
            ))

;(add-hook 'compilation-finish-functions 'my-compilation-finish-function)

嗨,我将这个添加到了我的.emacs文件中,但问题仍然存在。 - jimbo
@jim 我的代码片段使用编译缓冲区,而不是 shell 缓冲区。如果直接使用可能无法正常工作,你可以尝试使用编译缓冲区,或者查找是否有等效的 finish-functions 钩子函数适用于 shell 缓冲区。 - Anycorn

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