Blog

More as a reminder to myself: for some odd reason, the Terminal window in Panic’s otherwise most excellent Coda was giving me gyp with Emacs.

Please, by the way, don’t ask me why I’d still fire up an Emacs window in what’s effectively a very pretty modern editing environment with some surprisingly powerful tools built into it. It’s a combination of habit, long experience, and the need to interface with Subversion, among other things.

But I digress. I was having the Standard Emacs Backspace/Help problem, which is that hitting the “delete” key on my Mac keyboard was sending a control-H character to Emacs, and Emacs was interpreting that as a call for help, rather than a hint that I wanted something deleted. This has been happening to people since Emacs has been mixing with text terminals.

Long story short, I tried to poke around with stty and tset and a few other things, but I couldn’t figure out why the Terminal window in Coda was any different from the normal OS X Terminal, which was behaving perfectly. I found that a quick “tset –e ^h” fixed the problem, but I also figured that the best thing to do would be to attack things from the Emacs side, so I did a bit of searching on the net, found the famous old page of the Emacs manual, and put this in my ~/.emacs:

(global-set-key "\C-h" 'backward-delete-char)

Job done. My delete key now worked from normal Terminal as usual, and also from within the Terminal in Coda. So, strange one, but an easy solution. If you don’t have a .emacs file, just create a new one in your home directory and shove the above line in it, and all should be well in Emacs in Coda.

3 Comments

Danny

I realize how old this article is, but I hope you get this comment anyway.

I’m having this same problem. I’d like to use Coda because it’s great to be able to use the FTP aspect without ever leaving my editing window. Plus CSS in emacs is… less than pleasant.

Anywho, my question is: I edit directly to an Amazon EC2 Server which is accessed by other people, so If I edit the emacs file to reroute C-h to backward-delete-char, won’t this eliminate the ability of others to use C-h legitimately?

What exactly does ‘tset –e ^h’ do? Does this have to be executed with every new session?

“tset –e ^h” means “set the erase character to control+h”, and is basically doing exactly the same thing as the emacs command, only at the shell level. You would have to execute this for every new terminal window you opened up.

To make it work automatically every time you logged in, you’d have to put it in one of your shell startup files (e.g. ~/.bash_profile, depending on what kind of system you’re connecting to.)

Editing either the .emacs or a shell login script would mean that everyone who logs in as the particular user you’re using would be affected — so it depends on whether everyone logs into the EC2 server using the same username, or if you each have your own.

This all appears to be because Coda’s terminal sends a ctrl-H character rather than 0x7f when you hit the backspace key — which appears to have been a change in Coda 1.02. I’d love to know why this was changed — I’d ask Panic if I had the time.

Sorry I can’t be much more help — the answer for you will depend very much on your specific setup. Can you get together with another emacs user on that server and do some testing?

Frankly, most Emacs users I know tend to trigger the help menu accidentally rather than deliberately, and most will know of alternative ways of bringing it up — hitting F1 or “Meta-x help” will both do the job, so you might just get away with rebinding ctrl-H for everyone :)

[…] I just got Snow Leopard* and it’s blown away some obscure tricks I’d left for myself. This is a note to future me, should I need to fix Coda’s annoying preference of ^H instead of backspace in their terminal window. […]