zsh-users
 help / color / mirror / code / Atom feed
From: m0viefreak <m0viefreak.cm@googlemail.com>
To: zsh-users@zsh.org
Cc: m0viefreak <m0viefreak.cm@googlemail.com>
Subject: [PATCH] zle/completion: fix auto-removable suffix highlighting
Date: Sun, 23 Mar 2014 19:38:25 +0100	[thread overview]
Message-ID: <1395599905-6068-1-git-send-email-m0viefreak.cm@googlemail.com> (raw)
In-Reply-To: <140322234515.ZM9387@torch.brasslantern.com>

The variable suffixnoinslen, intended for use related to the
\- suffix specifier, was also used for the length of the active
suffix in the highlighting code. This broke highlighting in cases
where \- was NOT specified.

Semantically two variables are needed:

Introduce a new variable that only reflects *IF* the suffix
should be removed on uninsertable characters and set the length
variable independant from that.
---
 Src/Zle/compresult.c  |  2 +-
 Src/Zle/zle_misc.c    | 28 ++++++++++++++--------------
 Src/Zle/zle_refresh.c |  4 ++--
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index c0e5ff3..fcceb67 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -1131,7 +1131,7 @@ do_single(Cmatch m)
 	    /* If a suffix was added, and is removable, let *
 	     * `,' and `}' remove it.                       */
 	    if (isset(AUTOPARAMKEYS))
-		addsuffix(SUFTYP_POSSTR, 0, ZWS(",}"), 2, suffixnoinslen);
+		addsuffix(SUFTYP_POSSTR, 0, ZWS(",}"), 2, suffixlen);
 	} else if (!menucmp) {
 	    /*{{*/
 	    /* Otherwise, add a `,' suffix, and let `}' remove it. */
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index 7be0ebb..9bc1cf6 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -1249,10 +1249,14 @@ static char *suffixfunc;
 /* Length associated with the suffix function */
 static int suffixfunclen;
 
-/* Length associated with uninsertable characters */
+/* Whether to remove suffix on uninsertable characters */
+/**/
+int suffixnoinsrem;
+
+/* Length of the currently active, auto-removable suffix. */
 /**/
 mod_export int
-suffixnoinslen;
+suffixlen;
 
 /**/
 mod_export void
@@ -1309,7 +1313,8 @@ makesuffix(int n)
     if ((suffixchars = getsparam("ZLE_SPACE_SUFFIX_CHARS")) && *suffixchars)
 	addsuffixstring(SUFTYP_POSSTR, SUFFLAGS_SPACE, suffixchars, n);
 
-    suffixnoinslen = n;
+    suffixlen = n;
+    suffixnoinsrem = 1;
 }
 
 /* Set up suffix for parameter names: the last n characters are a suffix *
@@ -1358,15 +1363,10 @@ makesuffixstr(char *f, char *s, int n)
 	s = metafy(s, i, META_USEHEAP);
 	ws = stringaszleline(s, 0, &i, NULL, NULL);
 
-	if (z)
-	    suffixnoinslen = inv ? 0 : n;
-	else if (inv) {
-	    /*
-	     * negative match, \- wasn't present, so it *should*
-	     * have this suffix length
-	     */
-	    suffixnoinslen = n;
-	}
+	/* Remove suffix on uninsertable characters if  \- was given *
+	 * and the character class wasn't negated -- or vice versa.  */
+	suffixnoinsrem = z ^ inv;
+	suffixlen = n;
 
 	lasts = wptr = ws;
 	while (i) {
@@ -1444,7 +1444,7 @@ iremovesuffix(ZLE_INT_T c, int keep)
 	struct suffixset *ss;
 
 	if (c == NO_INSERT_CHAR) {
-	    sl = suffixnoinslen;
+	    sl = suffixnoinsrem ? suffixlen : 0;
 	} else {
 	    ZLE_CHAR_T ch = c;
 	    /*
@@ -1538,5 +1538,5 @@ fixsuffix(void)
 	suffixlist = next;
     }
 
-    suffixfunclen = suffixnoinslen = 0;
+    suffixfunclen = suffixnoinsrem = suffixlen = 0;
 }
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index 2bedbc4..8ce6787 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -1046,8 +1046,8 @@ zrefresh(void)
 	region_highlights[1].start = region_highlights[1].end = -1;
     }
     /* check for an active completion suffix */
-    if (suffixnoinslen) {
-	region_highlights[2].start = zlecs - suffixnoinslen;
+    if (suffixlen) {
+	region_highlights[2].start = zlecs - suffixlen;
 	region_highlights[2].end = zlecs;
     } else {
 	region_highlights[2].start = region_highlights[2].end = -1;
-- 
1.9.1.286.g5172cb3


  reply	other threads:[~2014-03-23 18:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 21:42 Remove space added by completion zzapper
2014-02-14 22:11 ` Oliver Kiddle
2014-02-15  0:49   ` Aaron Schrab
2014-02-15  2:33     ` Bart Schaefer
2014-02-15  4:45       ` Aaron Schrab
2014-02-18 16:54         ` Oliver Kiddle
2014-02-20  1:33           ` Aaron Schrab
2014-03-22 14:10           ` m0viefreak
2014-03-22 16:43             ` [PATCH] _git: auto-removable '..' suffix: remove at the end of lines m0viefreak
2014-03-22 17:37               ` Bart Schaefer
2014-03-23  3:41                 ` m0viefreak
2014-03-23  6:45                   ` Bart Schaefer
2014-03-23 18:38                     ` m0viefreak [this message]
2014-02-15 12:45   ` Remove space added by completion zzapper
2014-02-20 10:05     ` Oliver Kiddle

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=1395599905-6068-1-git-send-email-m0viefreak.cm@googlemail.com \
    --to=m0viefreak.cm@googlemail.com \
    --cc=zsh-users@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).