From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4058 invoked by alias); 10 Dec 2015 17:42:43 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 37378 Received: (qmail 5312 invoked from network); 10 Dec 2015 17:42:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_HDRS_LCASE autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f79b16d000005389-84-5669b98e6f74 Date: Thu, 10 Dec 2015 17:42:35 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: PATCH: initial bindkey tests Message-id: <20151210174235.36114d7f@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: quoted-printable X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOLMWRmVeSWpSXmKPExsVy+t/xy7p9OzPDDM5OZrU42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGRuW+xTskqtoOdPG0sA4TbyLkZNDQsBEYveEX2wQtpjEhXvr gWwuDiGBpYwSc068ZYFwZjBJ3Jv2ESpzjlFi8cv1TBDOWUaJTUfXMYP0swioSux79YwJxGYT MJSYumk2YxcjB4eIgLZE+0cxkLAwUMniTZ/BynkF7CVW7lsLVs4voC9x9e8nJogz7CVmXjnD CFEjKPFj8j0WEJtZQF1i0rxFzBC2tsSTdxdYQWwhoPiNu7vZJzAKzkLSMgtJyywkLQsYmVcx iqaWJhcUJ6XnGukVJ+YWl+al6yXn525ihATn1x2MS49ZHWIU4GBU4uF9IZ0ZJsSaWFZcmXuI UYKDWUmEV3sHUIg3JbGyKrUoP76oNCe1+BCjNAeLkjjvzF3vQ4QE0hNLUrNTUwtSi2CyTByc Ug2MW0StM20trwt/PRSg0Z2j8iFd1fPG4sgmh0vTRD7N7V9RMnvLDveM0w7/znyYu1Or/sjv vrLdjqx7Fk7/n74vI9aJa5VGskgvm+XEV9mXDt/ZeHTpiYl/xJMd3FYrhy2V/OJr+ir54fOP qrv6kgMPfzikmz9rh5vvyQW9J9NFP55Jn38ra9bmQCWW4oxEQy3mouJEAPg0BmpKAgAA Please expand: the only specialist knowledge needed should be obvious from the couple of test cases I've put in, which already cover a multibyte case. So anyone can have a go. Mikael's Special Character also uncovered a bug that the string in ztpy -r was being passed to the pattern code unmetafied. I've made it metafy the input string on the fly as it's read in. Found another bug not yet fixed: binding a full multibyte character (rather than just the first octet) to self-insert doesn't work. This isn't typically needed, but should work. diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index 02708a9..63ff757 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -614,14 +614,23 @@ ptyread(char *nam, Ptycmd cmd, char **args, int noblo= ck, int mustmatch) break; } if (cmd->read !=3D -1 || (ret =3D read(cmd->fd, buf + used, 1)) =3D=3D 1)= { + int readchar; if (cmd->read !=3D -1) { ret =3D 1; - buf[used] =3D (char) cmd->read; + readchar =3D cmd->read; cmd->read =3D -1; - } + } else + readchar =3D STOUC(buf[used]); + if (imeta(readchar)) { + buf[used++] =3D Meta; + buf[used++] =3D (char) (readchar ^ 32); + } else + buf[used++] =3D (char) readchar; seen =3D 1; - if (++used =3D=3D blen) { + if (used >=3D blen-1) { if (!*args) { + buf[used] =3D '\0'; + unmetafy(buf, &used); write_loop(1, buf, used); used =3D 0; } else { @@ -633,7 +642,8 @@ ptyread(char *nam, Ptycmd cmd, char **args, int noblock= , int mustmatch) buf[used] =3D '\0'; =20 if (!prog) { - if (ret <=3D 0 || (*args && buf[used - 1] =3D=3D '\n')) + if (ret <=3D 0 || (*args && buf[used - 1] =3D=3D '\n' && + (used < 2 || buf[used-2] !=3D Meta))) break; } else { if (ret < 0 @@ -666,9 +676,11 @@ ptyread(char *nam, Ptycmd cmd, char **args, int nobloc= k, int mustmatch) return 1; } if (*args) - setsparam(*args, ztrdup(metafy(buf, used, META_HREALLOC))); - else if (used) + setsparam(*args, ztrdup(buf)); + else if (used) { + unmetafy(buf, &used); write_loop(1, buf, used); + } =20 if (seen && (!prog || matchok || !mustmatch)) return 0; diff --git a/Test/X03zlebindkey.ztst b/Test/X03zlebindkey.ztst new file mode 100644 index 0000000..70c42f9 --- /dev/null +++ b/Test/X03zlebindkey.ztst @@ -0,0 +1,45 @@ +# Tests of the vi mode of ZLE + +%prep + mb_ok=3D + langs=3D(en_{US,GB}.{UTF-,utf}8 en.UTF-8 + $(locale -a 2>/dev/null | egrep 'utf8|UTF-8')) + for LANG in $langs; do + if [[ =C3=A9 =3D ? ]]; then + ZSH_TEST_LANG=3D$LANG + mb_ok=3D1 + break; + fi + done + if [[ $OSTYPE =3D cygwin ]]; then + ZTST_unimplemented=3D"the zsh/zpty module does not work on Cygwin" + elif ( zmodload zsh/zpty 2>/dev/null ); then + . $ZTST_srcdir/comptest + comptestinit -z $ZTST_testdir/../Src/zsh + else + ZTST_unimplemented=3D"the zsh/zpty module is not available" + fi + +%test + + zpty_run 'bindkey -s "\C-xy" foo' + zletest $'\C-xy' + zpty_run 'bindkey -r "\C-xy"' +0:bindkey -s +>BUFFER: foo +>CURSOR: 3 + + if [[ -z $mb_ok ]]; then + ZTST_skip=3D"bindkey multibyte test skipped" + else + zpty_run 'alias unbind=3D"bindkey -r =E3=83=9B"' + zpty_run 'bindkey -s =E3=83=9B bar' + zletest '=E3=83=9B' + zpty_run unbind + zletest '=E3=83=9B' + fi +0:bindkey -s multibyte characters +>BUFFER: bar +>CURSOR: 3 +>BUFFER: =E3=83=9B +>CURSOR: 1 diff --git a/Test/comptest b/Test/comptest index f10739a..166d0b4 100644 --- a/Test/comptest +++ b/Test/comptest @@ -27,7 +27,7 @@ comptestinit () { } =20 comptesteval \ -"export LC_ALL=3DC" \ +"export LC_ALL=3D${ZSH_TEST_LANG:-C}" \ "emulate -R zsh" \ "export ZDOTDIR=3D$ZTST_testdir" \ "module_path=3D( $module_path )" \