Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1467987543; bh=PnzwStEu0VP0M215kftB2O7nO0TR2Ezs2ggp00PvDOs=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=PW0AQcuwEuTyC9rK9R4AEUxrx/5wgfQG/GR8uuZ3bIx0VXptQtKnVlMSfcBfB7rFOsi+irPjLBgHTTjyxYNWB5qTZvjdy9Alnzo2Hrc0jeC0rxluupimrXZiJnJDcBDbXik7+t/pUNOrHZUgL/oMajVurL/eTE8dxrrRnErIijLL5nkmg2V6avqPUYGC9gSqHiWh2472HJherQYuOVzERfXgh8/InClIAxsvA+kbwS59qjDzUXC2BzGSg2geo/GAXgS/qY9Pyg6UfT37YuDY5l0BMmZ+5UEzRT/tbePiPPswCLdh376Z97mOjbbqi6qNw03KmNti1SIDLu+PgNqIJw==
X-Yahoo-Newman-Id: 272529.97115.bm@smtp132.mail.ir2.yahoo.com
X-Yahoo-Newman-Property: ymail-3
X-YMail-OSG: _hjWoRAVM1n2vL2.JnMMQDBsxJIlk4ck3x4cg3DlQ1ThLKH
 .DY.ruOnOP4wwJcKwkV_oKPFa.Eqy1P7my_4hDamnPLR3Ce_psNZ2fe6qB.W
 h.0iSKRWB6fkTS8GsucRebZgDA1ib1K1tQ52VL78ozz4oFNNTSzXf_oUN8xq
 J_GWQmIdPQn39hWkN2D1wvZcVFLCR_gumuUsUqrHlHgeiLgLcZzxUMlIhtCx
 5p3VeUR6yNl2vVGjckNW3NcikIzTva.roogBSlQkfKRzgnu3iA2kF0RP.pLe
 HEG2sLZWwohGTM9CO1kZHMVZhW20gxGEfhRdqNvHahTOmhDfAPwIhoSLR6_3
 0tVHSKcDf9IkLG_7roY0uAQWbWtRMM0y.qtI6APhmwXe.JnGtoECOodBxZ1M
 RmEXbWTcGEbyCq7X9U0MoE1A9f2HkB1Vh9A4aZ4muVV8EmiHaiHgdJK8SyYP
 J6YWS5Ckx02iS96T3o4c6oFDdsJx80cmUJRSvOUla0jm.tALJ.fq2oUEfrjN
 BVf9mCgOW4T7gMXUePaPQ3wMfumfwy65TEZa6W.L3M5s-
X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI-
In-reply-to: <160110091744.ZM585@torch.brasslantern.com>
From: Oliver Kiddle <okiddle@yahoo.co.uk>
References: <20160110003758.GA28696@tarsus.local2> <160110091744.ZM585@torch.brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: backward-kill-shell-word widget
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <61934.1467987542.1@hydra.kiddle.eu>
Date: Fri, 08 Jul 2016 16:19:02 +0200
Message-ID: <61935.1467987542@hydra.kiddle.eu>
X-Seq: zsh-workers 38810

On 10 Jan, Bart wrote:
> As of 5.0.8 you can do this with:
>
>     backward-kill-shell-word() {
>       zle select-in-shell-word
>       ((++CURSOR))  # adjust for vi vs. emacs region
>       zle kill-region
>     }
>
> I'm not sure if that CURSOR adjustment is a a bug or just a necessary
> evil because of using vi binding in the emacs keymap.

It ought to have adjusted the cursor internally for emacs mode.
It's hard to say exactly how the widget should behave from insert mode
exactly but this patch also fixes select-in/a-word to select further
words when invoked repeatedly from emacs mode. Note that
select-in-shell-word can't unfortunately do that even from vi mode.
I've also tried to consider weird combinations of
virangeflag, invicmdmode() and region_active but may have missed one.

Note that select-in-shell-word will select forwards in some
circumstances which might be unexpected for a backward-kill- widget.

Sorry for taking so long to reply to this.

Oliver

diff --git a/Src/Zle/textobjects.c b/Src/Zle/textobjects.c
index 9b3277a..3db0781 100644
--- a/Src/Zle/textobjects.c
+++ b/Src/Zle/textobjects.c
@@ -1,5 +1,5 @@
 /*
- * textobjects.c - ZLE module implementing Vim style text objects
+ * textobjects.c - ZLE widgets implementing Vim style text objects
  *
  * This file is part of zsh, the Z shell.
  *
@@ -54,11 +54,7 @@ selectword(UNUSED(char **args))
     int sclass = viclass(zleline[zlecs]);
     int doblanks = all && sclass;
 
-    if (!invicmdmode()) {
-	region_active = 1;
-	mark = zlecs;
-    }
-    if (!region_active || zlecs == mark) {
+    if (!region_active || zlecs == mark || mark == -1) {
 	/* search back to first character of same class as the start position
 	 * also stop at the beginning of the line */
 	mark = zlecs;
@@ -207,8 +203,12 @@ selectword(UNUSED(char **args))
     /* Adjustment: vi operators don't include the cursor position, in insert
      * or emacs mode the region also doesn't but for vi visual mode it is
      * included. */
-    if (zlecs && zlecs > mark && !virangeflag)
-	DECCS();
+    if (!virangeflag) {
+	if (!invicmdmode())
+	    region_active = 1;
+	else if (zlecs && zlecs > mark)
+	    DECCS();
+    }
 
     return 0;
 }
@@ -315,7 +315,7 @@ selectargument(UNUSED(char **args))
     }
 
     /* Adjustment: vi operators don't include the cursor position */
-    if (!virangeflag)
+    if (!virangeflag && invicmdmode())
        DECCS();
 
     return 0;

