Getting Emacs ansi-term and Zsh to play nicely
Asked Answered
B

4

17

I've been trying to use Zsh within my emacs session, without emacs remapping all the Zsh keys. I found ansi-term works pretty well for this but, I'm still having some problems. I was getting lots of junk characters outputted with, I was able to fix it with:

## Setup proper term information for emacs ansi-term mode
[[ $TERM == eterm-color ]] && export TERM=xterm

But everything still doesn't work perfectly. Now I am having trouble with output being drawn offscreen , especially when using something like C-r for search.

What I found is that it works fine if you don't resize the window. I can reproduce it like:

  1. Launch a clean emacs -q
  2. Start ansi-term and use zsh
  3. Make window fullscreen
  4. Output something that fills the screen
  5. Type C-r
  6. The prompt will be off the screen

Maybe there is some way I can make the space between the output and the minibuffer larger to compensate for the overshoot?

Anyone else have Zsh + Ansi-term working properly?

Blotter answered 15/12, 2008 at 4:1 Comment(2)
+1 -- you aren't the only one. Though, I only experience this issue on mac in tty mode.Depside
Use M-r for command history search in emacs, not C-rAmir
A
16

Try MultiTerm.

Its the only Emacs terminal mode that seems to play nice with zsh. It allows you to easily set which commands you want captured by emacs and which you want routed to the terminal. The default settings have been good enough for me so far though.

Also, add the following to your .zshrc to allow emacs to track your current directory as you cd around.

if [ -n "$INSIDE_EMACS" ]; then
  chpwd() { print -P "\033AnSiTc %d" }
  print -P "\033AnSiTu %n"
  print -P "\033AnSiTc %d"
fi
Auld answered 6/4, 2012 at 22:46 Comment(2)
This is great. Do you know how to extend this to ssh connections? (e.g. assuming that my shell has connected to a remote machine on a particular path).Nightrider
@AmelioVazquez-Reina - I wish I did. That would be really useful.Auld
O
3

Hmmm. I don't think I've ever seen any fancy editing work out well within ansi-term, although I haven't tried it in maybe 20 years. I'll just ask, in passing, if you've tried shell-mode (M-x shell) as it's a lot more natural with EMACS anyway.

That said, reading through the term.el file, it kind of looks like ansi-term is doing a lot of manging of its own. you might want to look at the term raw mode code, starting around line 1230, at least in EMACS 22.3.

Outlive answered 15/12, 2008 at 4:13 Comment(0)
P
1

I was looking for this as well for quite a while now. For me adding following to the

;; ansi-term

(global-set-key "\C-x\C-a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))
(global-set-key "\C-x\ a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))

works. I picked this from http://svn.assembla.com/svn/id774/scripts/dot_files/dot_emacs.d/elisp/global-set-key.el .

I am sure there are other goodies in that script. As an added bonus screen seems to play nicely with emacs for me.

Peppery answered 21/5, 2010 at 1:42 Comment(0)
B
0

I figured it out. It was an emacs config problem. This bit of elisp in my .emacs was causing it:

(custom-set-variables
 '(fringe-mode nil nil (fringe))
 '(fringes-outside-margins t t))

Thanks for the help.

Blotter answered 15/12, 2008 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.