Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs shell-mode display is too wide after splitting window

Tags:

emacs

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))
like image 584
Tyler Avatar asked Nov 02 '11 21:11

Tyler


1 Answers

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))))))
like image 88
Rangi Lin Avatar answered Oct 26 '22 17:10

Rangi Lin