Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Add completion suffix highlighting



I have a friend who just started using zsh a while ago, and she
complained about / being removed when she pressed enter after
completing a directory to rsync. Apparently rsync behaves differently
with and without the / in place. We tried setting
ZLE_REMOVE_SUFFIX_CHARS to nothing and using zle auto-suffix-retain in
an accept-line hook, but then we realized it would be better if you
could tell more easily if the suffix would be removed or not. So I
whipped this up and somehow it worked on the first try (no guarantees
though :). Given my poor track record of posting patches via email,
here is a link to the patch, and I'll just paste in the essence of the
patch for reference.

http://mika.l3ib.org/0001-Add-region-highlighting-for-completion-suffixes.patch

I'm not sure if the reference in the man page needs to be more
specific, or point somewhere completely different. Or if this is at
all a good idea, it seems to work and be useful though.

diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index c849d9b..e99cbb3 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -247,8 +247,9 @@ struct region_highlight *region_highlights;
  * for the first few elements of region_highlights.
  * 0: region between point and mark
  * 1: isearch region
+ * 2: suffix
  */
-#define N_SPECIAL_HIGHLIGHTS	(2)
+#define N_SPECIAL_HIGHLIGHTS	(3)
 /*
  * Number of elements in region_highlights.
  * This includes the special elements above.
@@ -340,6 +341,7 @@ zle_set_highlight(void)
     int special_atr_on_set = 0;
     int region_atr_on_set = 0;
     int isearch_atr_on_set = 0;
+    int suffix_atr_on_set = 0;
     struct region_highlight *rhp;

     special_atr_on = default_atr_on = 0;
@@ -373,6 +375,9 @@ zle_set_highlight(void)
 	    } else if (strpfx("isearch:", *atrs)) {
 		match_highlight(*atrs + 8, &(region_highlights[1].atr));
 		isearch_atr_on_set = 1;
+	    } else if (strpfx("suffix:", *atrs)) {
+		match_highlight(*atrs + 7, &(region_highlights[2].atr));
+		suffix_atr_on_set = 1;
 	    }
 	}
     }
@@ -384,6 +389,8 @@ zle_set_highlight(void)
 	region_highlights[0].atr = TXTSTANDOUT;
     if (!isearch_atr_on_set)
 	region_highlights[1].atr = TXTUNDERLINE;
+    if (!suffix_atr_on_set)
+	region_highlights[2].atr = TXTBOLDFACE;

     allocate_colour_buffer();
 }
@@ -1076,6 +1083,13 @@ zrefresh(void)
     } else {
 	region_highlights[1].start = region_highlights[1].end = -1;
     }
+    /* check for an active completion suffix */
+    if (suffixnoinslen) {
+	region_highlights[2].start = zlecs - suffixnoinslen;
+	region_highlights[2].end = zlecs;
+    } else {
+	region_highlights[2].start = region_highlights[2].end = -1;
+    }

     if (clearlist && listshown > 0) {
 	if (tccan(TCCLEAREOD)) {


-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author