Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: History Up key



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@xxxxxxx>                  Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



Messages sorted by: Reverse Date, Date, Thread, Author