Subject: Re: Using the delete key to "right-delete" chars
To: Valeriy E. Ushakov <uwe@ptc.spbu.ru>
From: Greg A. Woods <woods@weird.com>
List: port-i386
Date: 10/02/2003 14:57:44
[ On Thursday, October 2, 2003 at 14:55:30 (+0400), Valeriy E. Ushakov wrote: ]
> Subject: Re: Using the delete key to "right-delete" chars
>
> On Thu, Oct 02, 2003 at 10:36:17 +0200, Johan Danielsson wrote:
> 
> > Greywolf <greywolf@starwolf.com> writes:
> > 
> > > This seems to me to be a lot of work for very little gain; why not
> > 
> > Because I want to use ^H for other purposes.
> 
> What Joda said...  I take care to rubout the backspace from existince
> in my setup.  When I mean Ctrl-H, i press Ctrl-H.

Hang on a minute!  We're talking about ASCII (ANSI X3.4-1997) characters
here.  The "backspace" character (ASCII "BS") _is_ 0x08, and just happens
to _also_ be what most keyboards send when you press <CTRL-H>.

(X11 keyboards are a whole other nightmare, but the end result seen from
any TTY's perspective should be the same)

> One of the primary reasons to avoid ^H generating backspace key is
> emacs.

GNU-Emacs is the one and only thing that is broken here, and luckily it
can trivially be fixed (though 21.3's prefered built-in fix is totally
broken and misguided)

Here's how I deal with the BS brain-damage in GNU Emacs:

;;; first off, we do some fancy stuff to make C-h work "properly," but still
;;; have good access to the help functions!
;;
;; NOTE: this *should* work by simply reading termio for current erase char.
;; As of emacs-21.2 there's a note in the NEWS file which says "** On terminals
;; whose erase-char is ^H (Backspace), Emacs now uses
;; normal-erase-is-backspace-mode."  Unfortunately this does exactly the wrong
;; thing, and in a totally bizzare and stupid way.
;;
;; Remember to call override-local-key-settings in the appropriate hooks to fix
;; up modes which violate global user preferences....
;;
(if (and (>= init-emacs-type 21)
	 (>= emacs-version-minor 2))
    ;; grrr.... do something with that stupid broken poor useless excuse for
    ;; a feature, normal-erase-is-backspace-mode....
    (setq keyboard-translate-table nil))
(global-set-key "\C-h" 'delete-backward-char)
(global-set-key "\C-?" 'delete-char)
(global-set-key "\e\C-h" 'backward-kill-word)
(global-set-key "\e\C-?" 'kill-word)

;;; OK, now we diddle with help....
;;
;; Oddly, the help interface in emacs is extremely scatter-brained, with
;; several slightly different ways of doing the same thing.  This is probably
;; due to the fact that several different programmers have implemented various
;; bits and pieces of the help systems.  See help.el and help-macro.el, but try
;; not to tear your hair out when you find out help-event-list in 19.34 is
;; essentially bogus, since it is simply an extension to a "standard" list.
;;
;; Remember to call override-local-key-settings in the appropriate hooks to fix
;; up modes which violate global user preferences....
;;
(global-set-key [f1] 'help-command)	; first do this for 19.28.
(global-set-key "\e?" 'help-command)	; this is the first step to set up help
(global-set-key "\e?F" 'view-emacs-FAQ)	; in 19.34 it needs more help...
;; should help-char be just ? instead?
(setq help-char ?\M-?)			; this should "fix" the rest.

;;; I USUALLY EXPECT THE BACKSPACE KEY TO WORK LIKE AN ASCII BACKSPACE!
;;
;; For some entirely un-fathomable reason the default function bindings make
;; the 'backspace' and 'delete' keys synonymous!
;;
(define-key function-key-map [backspace] [?\C-h])
(define-key function-key-map [M-backspace] [?\M-\C-h])
;;(define-key function-key-map [C-backspace] [?\C-h]) ; sometimes *is* DEL....

;;; OK, that's the end of the stuff to fix GNU Emacs' C-h brain damage.

-- 
						Greg A. Woods

+1 416 218-0098                  VE3TCP            RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>