10

I recently read Running Shells in Emacs, and spend some time to adapt my elaborate Zsh prompt to work with the limited capabilities of M-x shell and M-x ansi-term.

Following this effort I'm now finally able to use Zsh from within Emacs, however there is an—albeit minor—nuisance with M-x ansi-term. I always see the stray text 4m before the prompt.

Stray text before prompt

As you can see, this phenomenon seems to be independent of the actual prompt theme. It also appears with any of the built-in prompts, even the simple ones that don't use any fancy control characters. As a matter of fact, it even happens with the default prompt, i.e. if I start Zsh without my .zshrc.

Well, it's really just a minor nuisance, and I wouldn't not really mind if I weren't able to get rid of it—I mostly prefer M-x shell anyway, where this issue does not occur.

But it really annoys me that I haven't been able to find the cause of this issue, even though I really tried to debug it. I must say, though, that my understanding of terminals is rather limited, so I might have missed the very obvious.

I'm on OS X 10.10. My Emacs is 25.0.50, build straight from trunk with Homebrew, and no special flags. Zsh is 5.0.5, as included with Yosemite, but the issue also occurs with 5.0.7 installed via Homebrew.

Can anyone shed a light on this issue?

  • Try to set *export TERM=xterm-256color* in your .zshrc or *(setq system-uses-terminfo nil)*. – kmicu Jan 14 '15 at 16:13
  • `system-user-terminfo` didn't change anything. Changing `$TERM` fixed the issue, but that can't be the solution, can it? After all, it's a lie, essentially: `ansi-term` is no xterm, and definitely does not support 256 colours. –  Jan 14 '15 at 16:40
  • *4m* is an artifact from ANSI escape code used for defining a color e.g. `\x1b[37;4m` specifies a white color with 37 and underlined text with 4. I cannot reproduce your problem. My zsh is *5.0.7* and *'echo $TERM'* in ansi-term gives me *eterm-color*, my emacs is *24.4.1*. I tested also clean default version *'env HOME=~/tmp/emacstest emacs -Q'* and I cannot see any problems. – kmicu Jan 14 '15 at 21:05
  • @kmicu On OS X 10.10, I can consistently reproduce the issue with `emacs -Q` and no Zsh configuration at all. –  Jan 15 '15 at 09:30

1 Answers1

10

Apparently this issue is caused by missing terminfo for eterm-color. I managed to fix the issue by following the instructions in that answer to install an appropriate entry into the terminfo database. Specifically:

$ tic -o ~/.terminfo /usr/local/share/emacs/25.0.50/etc/e/eterm-color.ti

I'm still not sure why that is needed at all. term.el actually exports the $TERMINFO variable pointing to that directory, so the shell should be able to find the terminfo. Zsh seems to ignore the directory, though…

It does look at ~/.terminfo, though, so the above command makes the terminfo entry available to Zsh.

I'd be glad if anyone could provide a better explanation or a solution that does not require manual intervention.