zsh-users
 help / color / mirror / code / Atom feed
From: Boyd Adamson <boyd-adamson@usa.net>
To: zsh-users@sunsite.dk
Subject: Re: The old backspace/delete problem
Date: Thu, 20 Jan 2005 14:33:54 +1100	[thread overview]
Message-ID: <877jm8g4f1.fsf@eddy.tactio.lan> (raw)
In-Reply-To: <200501191422.j0JEMfxA020496@news01.csr.com>

Peter Stephenson <pws@csr.com> 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.


      parent reply	other threads:[~2005-01-20  3:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-19 13:12 Boyd Adamson
2005-01-19 14:22 ` Peter Stephenson
2005-01-19 17:36   ` Bart Schaefer
2005-01-19 18:10     ` Peter Stephenson
2005-01-24 20:36       ` Seth Kurtzberg
2005-01-20  3:33   ` Boyd Adamson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877jm8g4f1.fsf@eddy.tactio.lan \
    --to=boyd-adamson@usa.net \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).