zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Subject: Re: zle: vi mode: wrong undo handling on fresh lines
Date: Mon, 27 Jan 2014 16:11:24 +0000	[thread overview]
Message-ID: <20140127161124.2aa16b37@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20140127124301.4144f2d9@pwslap01u.europe.root.pri>

On Mon, 27 Jan 2014 12:43:01 +0000
Peter Stephenson <p.stephenson@samsung.com> 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


  reply	other threads:[~2014-01-27 16:21 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-22 12:37 Hauke Petersen
2013-09-22 18:24 ` Bart Schaefer
2013-09-22 20:27   ` Hauke Petersen
2013-09-23  4:57     ` Bart Schaefer
2013-09-23 20:30 ` Peter Stephenson
2014-01-24 23:19   ` Oliver Kiddle
2014-01-25 19:15     ` Bart Schaefer
2014-01-27 12:43       ` Peter Stephenson
2014-01-27 16:11         ` Peter Stephenson [this message]
2014-01-28 14:58           ` Peter Stephenson
2014-01-28 16:28             ` Bart Schaefer
2014-01-28 16:47               ` Peter Stephenson
2014-01-28 17:41                 ` Bart Schaefer
2014-01-28 23:00           ` Oliver Kiddle
2014-01-29  2:59             ` Bart Schaefer
2014-01-29 10:50               ` Oliver Kiddle
2014-01-29 14:48                 ` Bart Schaefer
2014-01-30 14:51             ` Jun T.
2014-01-30 15:38               ` Peter Stephenson
2014-01-30 16:03                 ` Bart Schaefer
2014-01-31 12:00               ` Jun T.
2014-01-31 15:19                 ` Bart Schaefer
2014-01-31 15:33                   ` Peter Stephenson
     [not found]               ` <16181.1391175951@thecus.kiddle.eu>
2014-01-31 16:43                 ` Jun T.
2014-01-31 21:37               ` Oliver Kiddle
2014-01-31 22:32                 ` Oliver Kiddle
2014-02-01 19:27                   ` Bart Schaefer
2014-02-03 16:20                   ` Jun T.
2014-02-03 21:29                     ` Oliver Kiddle
2014-02-03 22:20                       ` Bart Schaefer
2014-02-03 23:26                         ` Oliver Kiddle
2014-02-04 17:11                           ` Jun T.
2014-02-05 22:00                             ` Oliver Kiddle
2014-02-02 22:10             ` Oliver Kiddle
2014-02-07 14:43             ` Oliver Kiddle
2014-02-07 16:22               ` Bart Schaefer
2014-01-27 16:29         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140127161124.2aa16b37@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).