From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20995 invoked by alias); 27 Jan 2014 16:21:38 -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: 32308 Received: (qmail 12915 invoked from network); 27 Jan 2014 16:21:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,T_FRT_FOLLOW2 autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7fc96d000004885-78-52e6852d5313 Date: Mon, 27 Jan 2014 16:11:24 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: zle: vi mode: wrong undo handling on fresh lines Message-id: <20140127161124.2aa16b37@pwslap01u.europe.root.pri> In-reply-to: <20140127124301.4144f2d9@pwslap01u.europe.root.pri> References: <20130923213014.15f97f9e@pws-pc.ntlworld.com> <3511.1390605547@thecus.kiddle.eu> <140125111530.ZM21792@torch.brasslantern.com> <20140127124301.4144f2d9@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=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e/4VV3d1mdBBp93aVgcbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujPaZL5gKNkpWfD/6krWB8YxwFyMnh4SAicTFa4fYIWwxiQv3 1rN1MXJxCAksZZTY+ekzE4SznEniafNVsCoWAVWJy5uvMILYbAKGElM3zQazRQTEJc6uPc8C YgsL2Eqc/72GtYuRg4NXwF5iX5spSJhTwEHi34Jl7BAze5kkGhYfZwJJ8AvoS1z9+4kJ4gp7 iZlXzoDN5BUQlPgx+R7YTGYBLYnN25pYIWx5ic1r3jJPYBSYhaRsFpKyWUjKFjAyr2IUTS1N LihOSs810itOzC0uzUvXS87P3cQICcKvOxiXHrM6xCjAwajEwztV+lmQEGtiWXFl7iFGCQ5m JRFekzqgEG9KYmVValF+fFFpTmrxIUYmDk6pBsZo21uvw1pKYx7wd8bnMxc1aovErU4+/Ej7 IMcjGXMZa9UetbPXPXcpOF70tudluJtzxiTs1UGW/plLkgNPrI8R27VpXdTmt5IP6jsKqsye XDe4P2HGgeepF9X2XNSeOa3IqXLnvhdi7xNPaR/9nSW6kctZ5+bLaw9tvvsfiznO5jHxs6EF A7cSS3FGoqEWc1FxIgDZbY0oIAIAAA== On Mon, 27 Jan 2014 12:43:01 +0000 Peter Stephenson wrote: > > } However, even aside from that, the change doesn't seem to > > } be quite right: e.g. vi-repeat (dot) can't repeat the initial insertion. > > > > Worse than that, vi-repeat forllowing the initial insertion repeats > > the accept-line from the end of the previous command, thus attempting > > to execute the (usually partial) current command line immediately. > > > > Clearly more is needed to properly set up the vi-mode state at the start > > of the buffer. > > That kind of suggests there's some stuff startvitext() or > startvichange() ought to be doing already but isn't, but we've got away > with it somehow. inrepeat and vichgrepeat presumably have something to > do with it. Or startvitext() and startvichange() may be buried too far in to want any changing. I think this is starting to get somewhere, but I suspect it needs tweaking. For example, should that synthesised 'i' really be an 'a'? Is it OK to assume we're not in insert mode when vi-repeat is executed? If it's not safe, I don't understand how it ever worked. Some vi user will need to take over at this point. All the action I'm aware of is in the functions I've changed and if you've looked at the code you understand it as well as I do. I haven't thought further about the completion thing. I've no idea how that ever did anything useful. diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index 040b7cb..a2b20df 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -1204,7 +1204,7 @@ zleread(char **lp, char **rp, int flags, int context, char *init, char *finish) * no user operation to indicate this. */ if (openkeymap("main") == openkeymap("viins")) - viinsert(NULL); + viinsert_init(); selectlocalmap(NULL); fixsuffix(); if ((s = getlinknode(bufstack))) { diff --git a/Src/Zle/zle_vi.c b/Src/Zle/zle_vi.c index 173a49e..989998e 100644 --- a/Src/Zle/zle_vi.c +++ b/Src/Zle/zle_vi.c @@ -67,6 +67,13 @@ int viinsbegin; static struct modifier lastmod; static int inrepeat, vichgrepeat; +/** + * im: >= 0: is an insertmode + * -1: skip setting insert mode + * -2: entering viins at start of editing from clean --- don't use + * inrepeat or lastchar, synthesise an i to enter insert mode. + */ + /**/ static void startvichange(int im) @@ -75,7 +82,7 @@ startvichange(int im) insmode = im; vichgflag = 1; } - if (inrepeat) { + if (inrepeat && im != -2) { zmod = lastmod; inrepeat = vichgflag = 0; vichgrepeat = 1; @@ -84,7 +91,11 @@ startvichange(int im) if (vichgbuf) free(vichgbuf); vichgbuf = (char *)zalloc(vichgbufsz = 16); - vichgbuf[0] = lastchar; + if (im == -2) { + vichgbuf[0] = 'i'; + } else { + vichgbuf[0] = lastchar; + } vichgbufptr = 1; vichgrepeat = 0; } @@ -303,6 +314,18 @@ viinsert(UNUSED(char **args)) return 0; } +/* + * Go to vi insert mode when we first start the line editor. + * Iniialises some other stuff. + */ + +/**/ +void +viinsert_init(void) +{ + startvitext(-2); +} + /**/ int viinsertbol(UNUSED(char **args)) pws