snarfed.org

draw group stream of consciousness

why I don't run shells inside Emacs

Wed, 01 Jan 2003 [comments (4)] [history] [rdf] [raw]

terminal.jpgtcsh_oyster_catcher.jpggnu.jpg

This article details my experience running shells inside Emacs. I take a while to warm up, so if you're impatient, feel free to skip to the pros and cons, the .emacs settings, or the related articles.

When I'm working, I pretty much live inside Emacs. It's my IDE, debugger, text editor, email composer, spreadsheet, file manager, and all-around scratch pad. The only other app that's as ubiquitous in my work routine is my shell, tcsh inside rxvt.

I've customized the hell out of both Emacs and tcsh to make them work the way I want. I have Emacs whipped into shape, and tcsh too, mostly, except for one thing: copying without the mouse.

I hate the mouse. It's good for some things, but not my work. Switching between the mouse and the keyboard wreaks havoc on my muscle memory and fine-motor flow. Thanks to Emacs, Ion, Pine, Gaim, and Firefox's blessed Find As You Type, I can do pretty much everything with the keyboard. The only thing I can't do with the keyboard is copy text from a terminal. And that irks me.

A voice in the back of my head had been nagging me about this for a while. Ryan, you can fix this, it said, and you know how. It was right. I didn't want to admit it, but I did know how, and it did too. Why don't you try running your shells inside Emacs?

I had a laundry list of reasons. Half of my .cshrc would be usless. I'd forgo acoc's wonderful colorized command output. Emacs' shell-mode would never do history management as well as native tcsh. And I wouldn't get that cool transparent background. :P

The voice in the back of my head didn't go away, though. Every time I reached for the mouse to copy something out of a terminal, it piped up. You could fix that, you know. Sigh. I knew.

Finally, it got the better of me. I wrote try emacs shell mode on my todo list, and a few days later, I tried it. M-x shell was all it took, and it worked surprisingly well. What's more, most of my reasons for avoiding it were unfounded. Here's what worked well:

It wasn't perfect, though. Here's what didn't work well:

So, you might ask, what was the verdict? The jury's still out. I'm currently wrestling GNU screen into submission, since it also allows keyboard navigation and copy/paste over shell contents. So far, I've synchronized its paste buffer and the X selection, and I've Emacs-ified its copy-scrollback mode. Stay tuned for more!

Here's what I added to my .emacs to make shell-mode behave the way I wanted:

(custom-set-variables
 '(comint-scroll-to-bottom-on-input t)  ; always insert at the bottom
 '(comint-scroll-to-bottom-on-output t) ; always add output at the bottom
 '(comint-scroll-show-maximum-output t) ; scroll to show max possible output
 '(comint-completion-autolist t)        ; show completion list when ambiguous
 '(comint-input-ignoredups t)           ; no duplicates in command history
 '(comint-completion-addsuffix t)       ; insert space/slash after file completion
 )

; interpret and use ansi color codes in shell output windows
(ansi-color-for-comint-mode-on)

; make completion buffers disappear after 3 seconds.
(add-hook 'completion-setup-hook
  (lambda () (run-at-time 3 nil
    (lambda () (delete-windows-on "*Completions*")))))

;; run a few shells.
(shell "*shell5*")
(shell "*shell6*")
(shell "*shell7*")

; C-5, 6, 7 to switch to shells
(global-set-key [(control 5)]
  (lambda () (interactive) (switch-to-buffer "*shell5*")))
(global-set-key [(control 6)]
  (lambda () (interactive) (switch-to-buffer "*shell6*")))
(global-set-key [(control 7)]
  (lambda () (interactive) (switch-to-buffer "*shell7*")))


See also:

comment bubble OpenID Guest, Wed 31 May 2006

Maybe TRAMP filename completion might be usable if you used the OpenSSH 4.0+ ControlMaster feature?

- Marc

comment bubble OpenID ryan, Wed 31 May 2006

fascinating! i'd never heard of ControlMaster before.

sadly, the machines i work on regularly all have openssh 3.7.x, and some of them would be bears to upgrade. still, i'll keep it in mind. thanks!

comment bubble OpenID Guest, Mon 12 Jun 2006

If you're on Linux, you could try solving the secure access to remote filesystems problem on a different level that would take care of the filename completion: sshfs or shfs. I've only used the former; it worked perfectly with Emacs. http://fuse.sourceforge.net/sshfs.html http://shfs.sourceforge.net/faq.html

- Zed

comment bubble OpenID Gregory Collins, Mon 24 Mar 2008

Have you tried eshell? (M-x eshell)

Post a comment...



Simple HTML and wiki markup are allowed.