如果我在emacs中运行M-x shell
以获得终端,它会自动知道在哪里换行。例如,ls
的输出被格式化为适合窗口的列。
我的问题是,如果我然后用C-x 3
垂直分割窗口,shell模式仍然认为窗口填充整个框架。其结果是命令输出的丑陋包装。是否有一种方法让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))
我有点晚了,但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)
与每次导出COLUMNS不同,此方法不需要您在Bash,它不会用空白提示垃圾邮件会话。这代码本身应该是comint的,也许我会提交一个bug报告。
EDIT:如果您以buffer-local方式修改window-configuration-change-hook
钩子每个窗口运行一次,而不是每帧运行一次。
这是一个稍微改进的调整大小函数,来自@Christopher Monsanto的回答。原来的一个会因为nil进程而导致问题。(例如:shell模式下的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))))))
这个显示由COLUMNS环境变量决定。在我的设置中,COLUMNS的值为202,在垂直分割之后,如果我通过
将COLUMNS设置为80,那么在shell模式下ls将正确显示。export COLUMNS=80
一定有一种方法来编码这个,但我没有足够的elisp-fu来做到这一点。如果你不想麻烦的话,multi-term可以自动管理。
http://www.emacswiki.org/emacs/MultiTerm尝试 M - x eshell
;它没有这个问题。