From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20677 invoked from network); 20 Jan 2005 03:35:19 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 20 Jan 2005 03:35:19 -0000 Received: (qmail 26510 invoked from network); 20 Jan 2005 03:35:12 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 20 Jan 2005 03:35:12 -0000 Received: (qmail 15540 invoked by alias); 20 Jan 2005 03:34:40 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8401 Received: (qmail 15523 invoked from network); 20 Jan 2005 03:34:39 -0000 Received: from unknown (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 20 Jan 2005 03:34:39 -0000 Received: (qmail 24809 invoked from network); 20 Jan 2005 03:34:03 -0000 Received: from main.gmane.org (80.91.229.2) by a.mx.sunsite.dk with SMTP; 20 Jan 2005 03:34:00 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1CrT56-0003fv-00 for ; Thu, 20 Jan 2005 04:34:00 +0100 Received: from ppp154-51.lns1.mel3.internode.on.net ([150.101.154.51]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 20 Jan 2005 04:34:00 +0100 Received: from boyd-adamson by ppp154-51.lns1.mel3.internode.on.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 20 Jan 2005 04:34:00 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@sunsite.dk From: Boyd Adamson Subject: Re: The old backspace/delete problem Date: Thu, 20 Jan 2005 14:33:54 +1100 Message-ID: <877jm8g4f1.fsf@eddy.tactio.lan> References: <87ekghftq7.fsf@eddy.tactio.lan> <200501191422.j0JEMfxA020496@news01.csr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: ppp154-51.lns1.mel3.internode.on.net User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:KfyXn+o+sZNrGJP6T0e6zS9qLcU= Sender: news X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.1 required=6.0 tests=AWL,BAYES_00,URIBL_SBL autolearn=no version=3.0.2 X-Spam-Hits: -2.1 Peter Stephenson writes: > Boyd Adamson wrote: >> Someone recently mentioned to me a solution to the old "backspace key >> sends ^? or ^H" problem that I hadn't heard of, and I thought we here >> in zsh land might be able to improve on it. >> [snip] >> Any ideas on how we could do this sort of auto-detection in zsh? > > It's doable; there's a slight catch, but I think I've managed to make it > almost invisible to the user. Here's the code first: > > > backward-delete-char-detect() { > if (( #KEYS == ##\C-? )); then > zmodload -i zsh/sched > sched +00:00 "stty erase '^?'" > elif (( #KEYS == ##\C-h )); then > zmodload -i zsh/sched > sched +00:00 "stty erase '^h'" > fi > > zle -A .$WIDGET $WIDGET > zle .$WIDGET > } > zle -N backward-delete-char backward-delete-char-detect > zle -N vi-backward-delete-char backward-delete-char-detect > > > This code will run the function backward-delete-char-detect the first > time you type a key bound to backward-delete-char. If that's either ^? > or ^h, it will record the fact. Then it will restore the original > version of backward-delete-char and perform the normal operation. > > The unpleasantness is that we can't run stty inside the editor widget, > since the terminal setup is explicitly restored on exit from zle and any > change is lost. So instead we use "sched" to schedule the stty to run > immediately, which in practice is the next time the command line is > executed. This does seem to work, but the effect consequently isn't > instantaneous; the first command that runs immediately after you've > deleted a character doesn't yet have the character remapped, because the > "sched" event is only examined when control returns to the shell after > that command. > > Alternatively, you could split the stty into the preexec function, but > then it becomes messier. Nice work! A great little feature.