If I run M-x shell
in emacs to get a terminal, it knows where to wrap lines automatically. For example, the output of ls
is formatted into columns that fit the window properly.
My problem is if I then split the window vertically with C-x 3
, shell-mode still thinks the window fills the whole frame. The result is ugly wrapping of command output. Is there a way to let shell-mode know it has to update the screen width?
EDIT:
Using HN's answer below, I came up with this fix:
(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))
Here is a slightly improved resize function from @Christopher Monsanto's answer. The original one will cause a problem due to nil process. (e.g exit
in shell-mode)
(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))))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With