9

Say I have an Emacs window (i.e. a subdivision of what Emacs calls a frame) running an M-x ansi-term buffer (e.g. running zsh) with that is ~500 pixels wide. I then run several shell commands and the output is wrapped to fit within those 500 pixels.

Say that I now make this window or buffer wider (e.g. 1000 pixels), maybe because I kill other windows in the frame, giving more space to my ansi-term window.

Is there any way to get older output in my ansi-term window to resize to take advantage of the new window size? (i.e. making lines wider and re-wrapping them according to the new window size)?

Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564

1 Answers1

4

No, not usually, because the program that produced the output (may have) formatted itself to fit the width of the display that was in effect at the time of its printing, and is no longer running when you resize.

However, if it is still running, it goes get the option to resize itself (a SIGWINCH). You might test this with e.g. the links/elinks browser. This is the real “use case” for ANSI terminal mode: programs that use “curses” or similar systems to move the cursor around.

As @user2491 pointed out, shell-mode does handle text-based (stream-based) output with word-wrapping, at the penalty of not being able to run “curses”-type programs. It's designed to treat your session a bit more like a text file, and less like a “real terminal.”

BRPocock
  • 13,638
  • 3
  • 31
  • 50
  • Thanks! Would you mind ellaborating more on how I can use `SIGWINCH` to resize the window where I have `ansi-term` running in Emacs? (I always have the terminal still running). – Amelio Vazquez-Reina Oct 16 '12 at 19:00
  • That's the responsibility of the program that's running. The terminal program itself (e.g. bash) generally won't worry about such things, but e.g. `mplayer`, `alpine`, `links` have handlers for it. If you literally mean, how to handle SIGWINCH in your own programs, I'd recommend using a higher-level library like `ncurses`, but you could also look at e.g. this answer: http://stackoverflow.com/a/3472019/475150 – BRPocock Oct 16 '12 at 19:23
  • Not sure I follow. I have `M-x ansi-term` (e.g. `zsh`) running in one of my windows. You said that if the terminal is still running, there is still hope for me to have it automatically rewrap the text using `SIGWINCH`. What is `SIGWINCH` exactly? Can I send a signal to the buffer running terminal from Emacs to have it rewrap the text? – Amelio Vazquez-Reina Oct 16 '12 at 19:32
  • 1
    SIGWINCH is a Unix signal that means, “your window size has changed.” And, yes, zsh /could/ redraw itself, but I think perhaps you misunderstood: If you run, say, “ls,” while the window is narrow — so, it prints results in one column — then resize the window wider, “ls” is no longer running, so it cannot reformat its output. If you run something like “alpine” or “links,” it will refresh itself on resizing. “zsh” is (probably) only printing a prompt; “bash,” at least (I don't have zsh handy) does re-write the current input line as you resize, but that's all it's responsible for printing. – BRPocock Oct 16 '12 at 19:37