From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25845 invoked from network); 14 Mar 2001 11:29:55 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 14 Mar 2001 11:29:55 -0000 Received: (qmail 27642 invoked by alias); 14 Mar 2001 11:29:50 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13633 Received: (qmail 27626 invoked from network); 14 Mar 2001 11:29:31 -0000 Message-ID: To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: History Up key In-Reply-To: Your message of "Tue, 13 Mar 2001 13:57:46 PST." <010313135746.ZM638@candle.brasslantern.com> Date: Wed, 14 Mar 2001 11:28:45 +0000 From: Peter Stephenson 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 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 Software Engineer CSR Ltd., Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070