Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zle: vi mode: wrong undo handling on fresh lines
On Mon, 27 Jan 2014 12:43:01 +0000
Peter Stephenson <p.stephenson@xxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author