如果我M-x shell在emacs中运行以获取终端,它会知道自动换行的位置.例如,输出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))
Run Code Online (Sandbox Code Playgroud)
Chr*_*nto 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)
Run Code Online (Sandbox Code Playgroud)
与每次导出COLUMNS不同,此方法目前不要求您使用bash,并且不会使用空白提示向您的会话发送垃圾邮件.这段代码可能应该是comint本身,也许我会提交bug报告.
编辑:如果你window-configuration-change-hook在缓冲区本地方式修改钩子每个窗口运行一次,而不是每帧一次.
这是@Christopher Monsanto的答案稍微改进的调整大小功能.由于零过程,原始的将导致问题.(例如exit在shell模式下)
(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))))))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1736 次 |
| 最近记录: |