Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:25:38+00:00 2026-06-06T18:25:38+00:00

If I run M-x shell in emacs to get a terminal, it knows where

  • 0

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))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:25:40+00:00Added an answer on June 6, 2026 at 6:25 pm

    I’m a bit late to the party, but COLUMNS isn’t the way to do this. Here is an excerpt from my .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)
    

    Unlike exporting COLUMNS each time, this method doesn’t require you to be in
    bash at the moment and it doesn’t spam your session with blank prompts. This
    code should probably be in comint itself, maybe I will file a bug report.

    EDIT: If you modify window-configuration-change-hook in a buffer-local-way
    the hook runs once per window, as opposed once per frame.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get my Emacs shell to mimic that of my standard terminal
I would like to run a shell command and get its output in clickable
How to kill an internal process in Emacs? For example I run M-x shell
I want to run a shell script on startup by google ,I found that
How do I get the correct $USER if I run a shell script with
I have configured my emacs to run zsh shell within ansi-term. However, copy/paste no
If I try to run mongodb shell with the mongo command alone, I get:
If I am trying to run a shell-command in an Emacs Lisp function in
I have the following python function that allows me to run shell commands from
When i use dired mode in emacs, I can run a shell command by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.