zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@zsh.org
Subject: Re: backward-kill-shell-word widget
Date: Fri, 08 Jul 2016 16:19:02 +0200	[thread overview]
Message-ID: <61935.1467987542@hydra.kiddle.eu> (raw)
In-Reply-To: <160110091744.ZM585@torch.brasslantern.com>

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;


  parent reply	other threads:[~2016-07-08 14:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  0:37 Daniel Shahaf
2016-01-10  7:42 ` Sebastian Gniazdowski
2016-01-10  7:54   ` Sebastian Gniazdowski
2016-01-10 20:13   ` Daniel Shahaf
2016-01-10 13:37 ` Sebastian Gniazdowski
2016-01-10 19:59   ` Daniel Shahaf
2016-01-10 21:06     ` Bart Schaefer
2016-01-12  8:23   ` Bart Schaefer
2016-01-10 15:50 ` Sebastian Gniazdowski
2016-01-10 20:19   ` Daniel Shahaf
2016-01-11  8:05     ` Sebastian Gniazdowski
2016-01-12 10:36       ` Sebastian Gniazdowski
2016-01-13  1:18       ` Daniel Shahaf
2016-01-13  8:38         ` Sebastian Gniazdowski
2016-01-14  0:13           ` Daniel Shahaf
2016-01-14  6:54             ` Bart Schaefer
2016-01-15  6:26               ` Daniel Shahaf
2016-01-10 17:17 ` Bart Schaefer
2016-01-10 19:53   ` Daniel Shahaf
2016-01-12  7:54     ` Bart Schaefer
2016-04-14 16:21   ` Bart Schaefer
2016-07-08 14:19   ` Oliver Kiddle [this message]
2016-01-11 11:53 ` Sebastian Gniazdowski
2016-01-12  6:59   ` Bart Schaefer
2016-01-12  7:49     ` Sebastian Gniazdowski

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=61935.1467987542@hydra.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --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).