Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Re: region_highlight converts `fg=default` to `none`, which is not the same
- X-seq: zsh-workers 54055
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: Re: region_highlight converts `fg=default` to `none`, which is not the same
- Date: Sun, 09 Nov 2025 01:04:29 +0100
- Archived-at: <https://zsh.org/workers/54055>
- In-reply-to: <88618-1762556365.023840@KaS5.q-Op.UPLl>
- List-id: <zsh-workers.zsh.org>
- References: <CAHLkEDv9ch+nhtpYF3So+029J6GMv5iU-8=RzHRHLa7OYzc3kg@mail.gmail.com> <88618-1762556365.023840@KaS5.q-Op.UPLl>
I wrote:
> With this patch, if you want bold text and no inherited attributes, you
> need: none,bold
> They apply in sequence.
I noticed that with the syntax highlighting plugins, "none" is used as
the default for various contexts. This resulted in the terminal defaults
applying and not whatever was given in the default: field of
zle_highlight.
It then occurred to me that in 5.9, "none" essentially means "inherit"
because it didn't turn any attributes off. So backward compatibility can
largely be preserved by defining "none" to mean no additional
highlighting and add a new type to reset or clear highlighting. This
uses "clear" but I'm not especially attached to that if someone has
other suggestions.
The following applies on top of the previous patch. There's also some
extra minor fixes where I forgot to update some array indices when
copy-pasting.
The one line assignment to txtunknownattrs is a somewhat unrelated
improvement to backward compatibility where the prompt contains literal
escapes and leaves attributes enabled at the end.
Oliver
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 9f7aeb0b9..fc9a98bd6 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -2822,6 +2822,13 @@ not all types of highlighting are available on all terminals:
startitem()
item(tt(none))(
+No additional highlighting is applied to the given context. It is not
+useful for this to appear with other types of highlighting; it is used to
+override a default. Any inherited highlighting is retained so for example,
+with tt(region:none), highlighting associated with tt(default) is still used
+for the region.
+)
+item(tt(clear))(
The terminal's default highlighting is applied to the given context.
This can be useful as a way to clear all inherited highlighting, so
may be used before naming other types of highlighting.
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index fd92ea6d7..8a89be333 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -371,17 +371,17 @@ zle_set_highlight(void)
region_attr_set = 1;
} else if (strpfx("isearch:", *atrs)) {
match_highlight(*atrs + 8, &(region_highlights[1].atr),
- &(region_highlights[0].atrmask),
+ &(region_highlights[1].atrmask),
&(region_highlights[1].layer));
isearch_attr_set = 1;
} else if (strpfx("suffix:", *atrs)) {
match_highlight(*atrs + 7, &(region_highlights[2].atr),
- &(region_highlights[0].atrmask),
+ &(region_highlights[2].atrmask),
&(region_highlights[2].layer));
suffix_attr_set = 1;
} else if (strpfx("paste:", *atrs)) {
match_highlight(*atrs + 6, &(region_highlights[3].atr),
- &(region_highlights[0].atrmask),
+ &(region_highlights[3].atrmask),
&(region_highlights[3].layer));
paste_attr_set = 1;
} else if (strpfx("ellipsis:", *atrs)) {
@@ -393,15 +393,15 @@ zle_set_highlight(void)
/* Default attributes */
if (!special_attr_set)
- special_attr = TXTSTANDOUT;
+ special_attr = special_mask = TXTSTANDOUT;
if (!region_attr_set)
- region_highlights[0].atr = TXTSTANDOUT;
+ region_highlights[0].atr = region_highlights[0].atrmask = TXTSTANDOUT;
if (!isearch_attr_set)
- region_highlights[1].atr = TXTUNDERLINE;
+ region_highlights[1].atr = region_highlights[1].atrmask = TXTUNDERLINE;
if (!suffix_attr_set)
- region_highlights[2].atr = TXTBOLDFACE;
+ region_highlights[2].atr = region_highlights[2].atrmask = TXTBOLDFACE;
if (!paste_attr_set)
- region_highlights[3].atr = TXTSTANDOUT;
+ region_highlights[3].atr = region_highlights[3].atrmask = TXTSTANDOUT;
if (!ellipsis_attr_set)
ellipsis_attr = TXTBGCOLOUR | ((zattr) 3 << TXT_ATTR_BG_COL_SHIFT) |
TXTFGCOLOUR | ((zattr) 4 << TXT_ATTR_FG_COL_SHIFT);
@@ -1161,6 +1161,9 @@ zrefresh(void)
zputs("\n", shout); /* works with both hasam and !hasam */
/* lpromptbuf includes literal escapes so we need to update for it */
txtcurrentattrs = txtpendingattrs = pmpt_attr;
+ /* Unknown attributes remain so but if sequences were embedded
+ * directly in the prompt, let's not needlessly reset them. */
+ txtunknownattrs = 0;
}
if (clearflag) {
zputc(&zr_cr);
diff --git a/Src/prompt.c b/Src/prompt.c
index 4ec9f22de..4e9b552d9 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1801,7 +1801,7 @@ struct highlight {
};
static const struct highlight highlights[] = {
- { "none", 0, TXT_ATTR_ALL },
+ { "clear", 0, TXT_ATTR_ALL },
{ "bold", TXTBOLDFACE, TXTFAINT },
{ "faint", TXTFAINT, TXTBOLDFACE },
{ "standout", TXTSTANDOUT, 0 },
@@ -1994,8 +1994,8 @@ match_highlight(const char *teststr, zattr *on_var, zattr *setmask, int *layer)
teststr = val;
found = 1;
}
- /* delayed this to the end of the first iteration because "none"
- * starts with "no" */
+ /* delayed this to the end of the first iteration because
+ * "noclear" isn't valid */
if (hl == highlights && (turn_off = strpfx("no", teststr)))
teststr += 2;
}
@@ -2072,7 +2072,7 @@ output_highlight(zattr atr, zattr mask, char *buf)
mask &= atr; /* mark unset bits from atr as done */
atrlen = 4;
if (buf) {
- strcpy(ptr, "none");
+ strcpy(ptr, "clear");
ptr += 4;
}
}
@@ -2150,10 +2150,8 @@ output_highlight(zattr atr, zattr mask, char *buf)
}
if (atrlen == 0) {
- /* "none" means no attributes but if there was nothing, attributes
- * are left untouched so return something that signifies that. */
if (buf)
- strcpy(ptr, "inherit");
+ strcpy(ptr, "none");
return 7;
}
return atrlen;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author