Run screen in emacs with ansi-term (combine this with emacs + ess + remote R)

This is actually an update to this post, but since I discovered a few more things, I’ll write a new post. To run screen within a shell buffer in emacs, I tried M-x shell and fired up screen (ditto with M-x term). It gave me this error: Clear screen capability required. I found the solution to this here. To fix this issue, do M-x ansi-term (use /bin/bash when asked of course). screen now works inside emacs. Combine this with running a remote R session in emacs, and there you have it, the perfect work flow for developing and running computationally intensive R code! I can utilize screen to not have my R sessions interrupted, and I can utilize ESS to send code to an R session/buffer. I have to say, this WILL be the way I use R for any computationally-intensive project!

UPDATE

So screen doesn’t work in emacs after I ssh to a remote server inside ansi-term. I get the error: Cannot find terminfo entry for 'eterm-color'. To fix this, I put the following in my remote server’s .bashrc file (info from here.):

if [ "$TERM" = "eterm-color" ] ; then
 TERM="vt100"
fi

UPDATE AGAIN (better solution)

This page (Remote Term Type section) shows how to fix the e-term color issue. Do make sure you create the .terminfo folder if its not there:

$ scp /usr/share/emacs/22.1/etc/e/eterm-color username@remoteserver:~/.terminfo/e/eterm-color
$ scp /usr/share/emacs/22.1/etc/e/eterm-color.ti username@remoteserver:~/.terminfo/e/eterm-color.ti

UPDATE AGAIN 2

So copying files into .terminfo didn’t fix everything. I guess SunOS servers don’t look in my home directory for those files. I guess we can copy things into /usr/share/lib/terminfo/?/* (more information at man terminfo), but I don’t have access to this location in some of my servers. I will have to resort back to the old trick (changing TERM). This time, change it to xterm (this doesn’t give me funny characters in emacs ansi-term); found this at the bottom of this page. Put the following in the remote .bashrc file:

TEMP=`uname`
if [ $TEMP = "SunOS" ]; then
 if [ "$TERM" = "eterm-color" ] ; then
 TERM="xterm"
 fi
fi

I hope there aren’t any more issues. What the previous trick does is check if system is SunOS, and if so, use xterm. I got the unix command information from here. I got the uname command info from here.

FINAL UPDATE

To get eterm-color to work in SunOS, put the following in my .bashrc file:

##following to get eterm-color working in SunOS
TERMINFO=${HOME}/.terminfo
export TERMINFO

I guess I’ve been doing this, but I never exported TERMINFO. Didn’t know this was needed. Make sure the eterm-files are copied over (see top of post). Now everything should work, hopefully flawlessly. To summarize, copy eterm files into ~/.terminfo, and put the TERMINFO stuff in ~/.bashrc.

Now screen works in emacs. An issue that arised from this method is that when screen is run inside emacs, I can’t execute ess-remote anymore because I can’t press M-x. In ansi-term, C-x C-j : behave like emacs, cursor can go anywhere C-x C-k : behave like a terminal (default) This is documented here and here. Press C-x C-j and I can press M-x again. However, ess-remote still doesn’t work.

I guess when I use screen, I am forced to copy and paste code. If I really must use screen with ESS, do the regular M-x shell. After logging into the remote server, execute “TERM\=’vt100′” in the shell. Now, run screen -> R -> ess-remote. I can send code with keypresses now, but screen steals some of my emacs key bindings. To fix this, put the following,

escape \^Oo

in my remote ~/.screenrc file to switch the default command key from C-a to C-o so it doesn’t conflict with my emacs key bindings (documented here).

More information on ansi term (like remaping C-x to C-c) can be found here.

This was a long post. Summary:

  1. ansi-term in emacs behaves VERY much like a terminal. I can run vi, emacs, etc, inside of it. Emacs behavior is ‘term’ and ‘shell’.
  2. I can change things by editing the env variable, TERM.
  3. Change keybinding in the remote .screenrc file.

NEED TO DO: get ess-remote to work with ansi-term and screen in emacs!

UPDATE2: It seems the best way to do things so far is to use ansi-term -> ssh to remote server -> screen -> R, then go to line run (C-c C-j) and copy and paste code from there. To get screen commands to work (like detach, etc), need to go back to char run (C-c C-k). Remember, I now use C-o instead of C-a (defined in .screenrc); this only works on a regular terminal or in emacs with ansi-term, not using ‘shell’ in emacs with the hack I mentioned up there.

About Vinh Nguyen

Statistician

4 comments

  1. Pingback: Vaughan Marais

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>