2010-05-01 177 views
3

我的.emacs文件中有以下内容(感谢SOer nikwin),它评估当前缓冲区内容并在另一个缓冲区中显示输出。Emacs shell输出缓冲区高度

(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分钟左右,找不到任何有用的东西。提前致谢。

+0

为什么写自己的编译命令?已经有'compile'。 – jrockway 2010-05-02 04:00:53

+0

我不太了解emacs lisp(或者emacs),因此我不能创建一个绑定C-c C-c编译的函数。我在SO上发现了这个函数,它工作得很好。 – jimbo 2010-05-02 05:53:02

回答

1

这扩大了20行的源代码缓存每当它的高度小于(使用ECB前)或等于框架高度的一半。漂亮的原油,但它可能符合你的目的。

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

非常感谢您,这很有用。我把行数改为5而不是20。 – jimbo 2010-05-02 05:50:57

0

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

这是我曾经有过

(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) 
+0

嗨,我添加到我的.emacs文件,但问题仍然存在 – jimbo 2010-05-01 04:39:34

+0

@jim我的代码段使用编译缓冲区,而不是shell缓冲区。不会按原样工作,您可以尝试使用编译缓冲区或查找是否存在与shell缓冲区等效的完成函数挂接点 – Anycorn 2010-05-01 04:44:07