2011-11-02 51 views
12

如果我在emacs中运行M-x shell以获取终端,它会知道在哪里自动换行。例如,ls的输出被格式化为适合窗口的列。拆分窗口后Emacs shell模式显示太宽

我的问题是,如果我然后垂直分割窗口与C-x 3,壳模式仍认为窗口填充整个框架。结果是丑陋的命令输出包装。有没有办法让shell模式知道它必须更新屏幕宽度?

编辑:

使用下面HN的答案,我想出了这个修复:

(defun my-resize-window() 
    "Reset the COLUMNS environment variable to the current width of the window." 
    (interactive) 
    (let ((proc (get-buffer-process (current-buffer))) 
     (str (format "export COLUMNS=%s" (window-width)))) 
    (funcall comint-input-sender proc str))) 

(defun my-shell-mode-hook() 
    (local-set-key "\C-cw" 'my-resize-window)) 

回答

14

我对晚会有点迟,但是COLUMNS不是这样做的。下面是我的.emacs的摘录:

(defun comint-fix-window-size() 
    "Change process window size." 
    (when (derived-mode-p 'comint-mode) 
    (set-process-window-size (get-buffer-process (current-buffer)) 
         (window-height) 
         (window-width)))) 

(defun my-shell-mode-hook() 
    ;; add this hook as buffer local, so it runs once per window. 
    (add-hook 'window-configuration-change-hook 'comint-fix-window-size nil t)) 

(add-hook 'shell-mode-hook 'my-shell-mode-hook) 

不像每次出口柱,这种方法不需要你在此刻 bash和它不与空白提示垃圾邮件的会话。这 代码应该可能在comint本身,也许我会提交一个错误报告。

编辑:如果您以缓冲区本地方式 修改window-configuration-change-hook钩子每个窗口运行一次,而不是每帧一次。

+0

这是一个非常有用的修复程序。请提交作为错误报告! –

+1

感谢有用的功能,但它会导致问题,当进程为零,所以我在设置过程窗口大小之前添加了无检查 - [请参阅我的答案](http://stackoverflow.com/a/20015336/554279) –

2

这显示被列环境变量决定。在我的设置列进行正确对,如果我通过

export COLUMNS=80 

一组列80必须有实现代码了壳模式202的值,垂直分割ls显示后,但我没有足够的elisp-fu来做到这一点。如果你想避免多任期的麻烦,可以自动管理。

http://www.emacswiki.org/emacs/MultiTerm

0

尝试中号 - Xeshell;它没有这个问题。

5

这是来自@Christopher Monsanto的回答稍微改进的调整大小函数。原来的那个会由于零进程而导致问题。 (例如,外壳模式下的exit

(defun comint-fix-window-size() 
    "Change process window size." 
    (when (derived-mode-p 'comint-mode) 
    (let ((process (get-buffer-process (current-buffer)))) 
     (unless (eq nil process) 
     (set-process-window-size process (window-height) (window-width)))))) 
+2

(当过程更习惯于(除非(eq nil过程) –