zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: History Up key
Date: Wed, 14 Mar 2001 11:28:45 +0000	[thread overview]
Message-ID: <Tc0a88d015249554427@mailsweeper01.cambridgesiliconradio.com> (raw)
In-Reply-To: Your message of "Tue, 13 Mar 2001 13:57:46 PST." <010313135746.ZM638@candle.brasslantern.com>

Bart write:
> On Mar 13,  8:22pm, Zefram wrote:
> > Subject: Re: History Up key
> > 
> > A.  It would be a bad idea to have arrow keys bound by default in vi
> >     insert mode.  Emacs mode and vi command mode don't have the same
> >     problems, because <esc> itself isn't bound to anything in those
> >     keymaps.
> 
> Obviously, though, users want it, or all those vi clones wouldn't have put
> in hacks to make it work.

Yes, we get lots of complaints that arrow keys don't work, despite the FAQ.
We don't get many complaints that zsh is full of hacks.  Odd...

> > B.  Adapting the arrow key sequences to the local terminal is problematic.
> >     Binding things like ^H as arrow key sequences will cause big problems,
> >     so at minimum terminals where arrow keys don't send escape sequences
> >     should be treated as having no arrow keys.
> 
> This suggests that any and all keybindings read from term(cap|info) should
> be bound BEFORE any of zsh's regular defaults, so that e.g. if down-arrow
> sends ^J, the binding to down-history is replaced by one for accept-line.

It's a little hard to do that cleanly, since default_bindings() is optimised
to set up the single-character bindings without going through bindkey.  But
I think we can do almost the same quite easily by testing whether termcap
came up with a single character binding which is already bound.  In fact,
most single character bindings are already bound, but there are a few which
are t_undefinedkey.  This should keep the default bindings clean --- users
are on their own, as usual.

Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.4
diff -u -r1.4 zle_keymap.c
--- Src/Zle/zle_keymap.c	2001/03/13 15:32:43	1.4
+++ Src/Zle/zle_keymap.c	2001/03/14 11:21:25
@@ -1029,6 +1029,7 @@
 add_cursor_key(Keymap km, int tccode, Thingy thingy, int defchar)
 {
     char buf[2048];
+    int ok = 0;
 
     /*
      * Be careful not to try too hard with bindings for dubious or
@@ -1042,7 +1043,18 @@
 	cursorptr = buf;
 	tputs(tcstr[tccode], 1, add_cursor_char);
 	*cursorptr = '\0';
-    } else {
+
+	/*
+	 * Sanity checking.  If the cursor key is zero-length (unlikely,
+	 * but this is termcap we're talking about), or it's a single
+	 * character which is already bound, then we don't bind it.
+	 */
+	if (!buf[0] || (!buf[1] && km->first[STOUC(buf[0])] != t_undefinedkey))
+	    ok = 0;
+	else
+	    ok = 1;
+    }
+    if (!ok) {
 	/* Assume the normal VT100-like values. */
 	sprintf(buf, "\33[%c", defchar);
     }

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070


  reply	other threads:[~2001-03-14 11:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E14cvJO-00084f-00@crucigera.fysh.org>
2001-03-13 21:57 ` Bart Schaefer
2001-03-14 11:28   ` Peter Stephenson [this message]
2001-03-15 19:15     ` Zefram
2001-03-15 19:27   ` Zefram
2001-03-17 22:31     ` Bart Schaefer

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=Tc0a88d015249554427@mailsweeper01.cambridgesiliconradio.com \
    --to=pws@csr.com \
    --cc=zsh-workers@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).