How NOT to fix your Delete key in EMACS

I’ve been runing emacs off of a weird server. I was running x on cygwin and had used “xhost MYSERVER” to pick up the emacs session. Cool. The version of Emacs 20.7.2, though. Anyways… I get there and backspace and the delete key both work by backing over the previous character. I wanted to make the delete key “eat” the next character. This should be easy to fix, right? Doh! It took me more than an hour. Below is my lame trial and error process of finding a lame solution. I haven’t had this much fun since I had to figure out how to enter a carriage return!

C-h b — list key bindings
C-s del — search for del… C-s to go forward, C-r to go backward

C-d runs the command delete-char
which is an interactive built-in function
DEL runs the command delete-backward-char
which is an interactive built-in function

C-x C-e the elisp code lines to execute them.

[Waste time trying many wrong ways to global-set-key the delete key, until….]

runs but doesn’t change behavior:

(global-set-key [del] 'delete-char)

look– hitting del does not make the “hello” text

(global-set-key [del] "hello")

this works! but… now backspace works like delete! Argh!

(global-set-key "\d" 'delete-char)

fix it back:

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

Uh… both of them are bound to DEL.

Problem must not be in EMACS. But wait… the weirdo shell that lanched EMACS knows the difference!

Can EMACS tell the difference between DEL and BACKSPACE?

press backspace , press delete
then hit C-h l to view the lossage buffer.
If you see something like
backspace deletechar

It can!!! Execute this:

(global-set-key [backspace]  'delete-backward-char) 
(global-set-key [deletechar] 'delete-char)

Still doesn’t work right….

(define-key function-key-map [delete] nil) 
(global-set-key [delete] 'delete-char)

Now delete is dead! (Backspace still works.)

Can’t get it back with this:

(define-key function-key-map [delete] [delete])

Hmm…. Maybe…. Aha! A lame hack:

(define-key function-key-map [delete] [F20]) 
(global-set-key [F20] 'delete-char)

This works! I did it! It only took an hour and a half! Argh!

Advertisements

3 Responses to “How NOT to fix your Delete key in EMACS”

  1. Geno Z Heinlein Says:

    Don’t regret that hour and a half. It will come back to you, as you have made your mind more in tune with the true nature of reality. The Force is written is lisp, but emacs was the editor. 🙂

  2. Den Zelig Says:

    Thanks for the post. I learned a bit from it even if it didn’t fix this problem on my system. I use a Mac to access Emacs on a remote server and there is a setting in the preferences to send ^H for the Delete key.

  3. Jon Says:

    Thanks for this post — it worked for me on emacs 22.1…but then didn’t work when I upgraded to fc12 and had emacs 23.1. But then I found this page:

    http://www.delorie.com/gnu/docs/emacs/emacs_512.html

    which had the handy tip regarding the wonderfully-named function normal-erase-is-backspace-mode. Setting this to 1 in my .emacs fixed the problem in both versions.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: