From 14c230dc3216b7fe0f63d797347e14178d4ede2b Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 15 Feb 2024 14:48:04 +0100 Subject: 52533: add module to provide alternate readonly views of the content of .zle.hlgroups --- Src/Modules/hlgroup.c | 211 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 Src/Modules/hlgroup.c (limited to 'Src/Modules/hlgroup.c') diff --git a/Src/Modules/hlgroup.c b/Src/Modules/hlgroup.c new file mode 100644 index 000000000..6382f3216 --- /dev/null +++ b/Src/Modules/hlgroup.c @@ -0,0 +1,211 @@ +/* + * hlgroup.c - Supporting parameters for highlight groups + * + * This file is part of zsh, the Z shell. + * + * Copyright (c) 2024 Oliver Kiddle + * All rights reserved. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and to distribute modified versions of this software for any + * purpose, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * In no event shall Oliver Kiddle or the Zsh Development Group be liable + * to any party for direct, indirect, special, incidental, or consequential + * damages arising out of the use of this software and its documentation, + * even if Oliver Kiddle and the Zsh Development Group have been advised of + * the possibility of such damage. + * + * Oliver Kiddle and the Zsh Development Group specifically disclaim any + * warranties, including, but not limited to, the implied warranties of + * merchantability and fitness for a particular purpose. The software + * provided hereunder is on an "as is" basis, and Oliver Kiddle and the + * Zsh Development Group have no obligation to provide maintenance, + * support, updates, enhancements, or modifications. + * + */ + +#include "hlgroup.mdh" +#include "hlgroup.pro" + +#define GROUPVAR ".zle.hlgroups" + +static const struct gsu_scalar pmesc_gsu = +{ strgetfn, nullstrsetfn, nullunsetfn }; + +/**/ +static char * +convertattr(char *attrstr, int sgr) +{ + zattr atr; + char *r, *s; + int len; + + match_highlight(attrstr, &atr, NULL); + s = zattrescape(atr, sgr ? NULL : &len); + + if (sgr) { + char *c = s, *t = s - 1; + + while (c[0] == '\033' && c[1] == '[') { + c += 2; + while (isdigit(*c) || *c == ';') + *++t = *c++; + t++; + if (*c != 'm') + break; + *t = ';'; + c++; + } + *t = '\0'; + len = t - s; + } + + r = dupstring_wlen(s, len); + free(s); + return r; +} + +/**/ +static HashNode +getgroup(const char *name, int sgr) +{ + Param pm = NULL; + HashNode hn; + HashTable hlg; + Value v; + struct value vbuf; + char *var = GROUPVAR; + + pm = (Param) hcalloc(sizeof(struct param)); + pm->gsu.s = &pmesc_gsu; + pm->node.nam = dupstring(name); + pm->node.flags = PM_SCALAR|PM_SPECIAL; + + if (!(v = getvalue(&vbuf, &var, 0)) || + PM_TYPE(v->pm->node.flags) != PM_HASHED || + !(hlg = v->pm->gsu.h->getfn(v->pm)) || + !(hn = gethashnode2(hlg, name))) + { + pm->u.str = dupstring(""); + pm->node.flags |= PM_UNSET; + } else { + pm->u.str = convertattr(((Param) hn)->u.str, sgr); + } + + return &pm->node; +} + +/**/ +static void +scangroup(ScanFunc func, int flags, int sgr) +{ + struct param pm; + int i; + HashNode hn; + HashTable hlg; + Value v; + struct value vbuf; + char *var = GROUPVAR; + + if (!(v = getvalue(&vbuf, &var, 0)) || + PM_TYPE(v->pm->node.flags) != PM_HASHED) + return; + hlg = v->pm->gsu.h->getfn(v->pm); + + memset((void *)&pm, 0, sizeof(struct param)); + pm.node.flags = PM_SCALAR; + pm.gsu.s = &pmesc_gsu; + + for (i = 0; i < hlg->hsize; i++) + for (hn = hlg->nodes[i]; hn; hn = hn->next) { + pm.u.str = convertattr(((Param) hn)->u.str, sgr); + pm.node.nam = hn->nam; + func(&pm.node, flags); + } +} +/**/ +static HashNode +getpmesc(UNUSED(HashTable ht), const char *name) +{ + return getgroup(name, 0); +} + +/**/ +static void +scanpmesc(UNUSED(HashTable ht), ScanFunc func, int flags) +{ + return scangroup(func, flags, 0); +} + +/**/ +static HashNode +getpmsgr(UNUSED(HashTable ht), const char *name) +{ + return getgroup(name, 1); +} + +/**/ +static void +scanpmsgr(UNUSED(HashTable ht), ScanFunc func, int flags) +{ + return scangroup(func, flags, 1); +} + +static struct paramdef partab[] = { + SPECIALPMDEF(".zle.esc", PM_READONLY_SPECIAL, 0, getpmesc, scanpmesc), + SPECIALPMDEF(".zle.sgr", PM_READONLY_SPECIAL, 0, getpmsgr, scanpmsgr) +}; + +static struct features module_features = { + NULL, 0, + NULL, 0, + NULL, 0, + partab, sizeof(partab)/sizeof(*partab), + 0 +}; + +/**/ +int +setup_(UNUSED(Module m)) +{ + return 0; +} + +/**/ +int +features_(Module m, char ***features) +{ + *features = featuresarray(m, &module_features); + return 0; +} + +/**/ +int +enables_(Module m, int **enables) +{ + return handlefeatures(m, &module_features, enables); +} + +/**/ +int +boot_(UNUSED(Module m)) +{ + return 0; +} + +/**/ +int +cleanup_(Module m) +{ + return setfeatureenables(m, &module_features, NULL); +} + +/**/ +int +finish_(UNUSED(Module m)) +{ + return 0; +} -- cgit v1.2.3 From 37f434498eb626a10e3009216afa306e5ae841c6 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Wed, 13 Mar 2024 00:35:10 +0100 Subject: 52724: fix .zle.sgr for empty sequences --- ChangeLog | 4 ++++ Src/Modules/hlgroup.c | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'Src/Modules/hlgroup.c') diff --git a/ChangeLog b/ChangeLog index a2609a1cf..f136bc6b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2024-03-13 Oliver Kiddle + + * 52724: Src/Modules/hlgroup.c: fix .zle.sgr for empty sequences + 2024-03-09 Bart Schaefer * 52725: Src/Modules/ksh93.c: updated named reference semantics diff --git a/Src/Modules/hlgroup.c b/Src/Modules/hlgroup.c index 6382f3216..9c0aedcf8 100644 --- a/Src/Modules/hlgroup.c +++ b/Src/Modules/hlgroup.c @@ -59,6 +59,10 @@ convertattr(char *attrstr, int sgr) *t = ';'; c++; } + if (t <= s) { /* always return at least "0" */ + *s = '0'; + t = s + 1; + } *t = '\0'; len = t - s; } -- cgit v1.2.3 From 7139d3b286bba5874548eb6faca25cf9bb90f7be Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Wed, 20 Mar 2024 23:40:23 +0100 Subject: 52783: allow for unset hash element --- ChangeLog | 2 ++ Src/Modules/hlgroup.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'Src/Modules/hlgroup.c') diff --git a/ChangeLog b/ChangeLog index df8caca42..157abcc9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2024-03-20 Oliver Kiddle + * 52783: Src/Modules/hlgroup.c: allow for unset hash element + * unposted: configure.ac: remove reference to fp_PROG_CC_STDC macro which was removed in 52750 diff --git a/Src/Modules/hlgroup.c b/Src/Modules/hlgroup.c index 9c0aedcf8..9b656c24e 100644 --- a/Src/Modules/hlgroup.c +++ b/Src/Modules/hlgroup.c @@ -91,7 +91,8 @@ getgroup(const char *name, int sgr) if (!(v = getvalue(&vbuf, &var, 0)) || PM_TYPE(v->pm->node.flags) != PM_HASHED || !(hlg = v->pm->gsu.h->getfn(v->pm)) || - !(hn = gethashnode2(hlg, name))) + !(hn = gethashnode2(hlg, name)) || + (((Param) hn)->node.flags & PM_UNSET)) { pm->u.str = dupstring(""); pm->node.flags |= PM_UNSET; -- cgit v1.2.3 From 017738cd60743b21832e5ee66b849b5adea1a28d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 21 Mar 2024 09:25:07 +0000 Subject: 52780: unneccessary returns in hlgroup --- ChangeLog | 4 ++++ Src/Modules/hlgroup.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'Src/Modules/hlgroup.c') diff --git a/ChangeLog b/ChangeLog index 157abcc9e..4cb7ca634 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2024-03-21 Peter Stephenson + + * 52780: Src/Modules/hlgroup.c: remove unnecessary returns. + 2024-03-20 Oliver Kiddle * 52783: Src/Modules/hlgroup.c: allow for unset hash element diff --git a/Src/Modules/hlgroup.c b/Src/Modules/hlgroup.c index 9b656c24e..082762623 100644 --- a/Src/Modules/hlgroup.c +++ b/Src/Modules/hlgroup.c @@ -142,7 +142,7 @@ getpmesc(UNUSED(HashTable ht), const char *name) static void scanpmesc(UNUSED(HashTable ht), ScanFunc func, int flags) { - return scangroup(func, flags, 0); + scangroup(func, flags, 0); } /**/ @@ -156,7 +156,7 @@ getpmsgr(UNUSED(HashTable ht), const char *name) static void scanpmsgr(UNUSED(HashTable ht), ScanFunc func, int flags) { - return scangroup(func, flags, 1); + scangroup(func, flags, 1); } static struct paramdef partab[] = { -- cgit v1.2.3 From 4f3d69e2a0bc6b4d98a4aa3ef37ebea44cbda51f Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Mon, 27 Jan 2025 23:50:27 +0100 Subject: 53329: adapt .zle.sgr for CSI sequences that use : instead of ; --- ChangeLog | 3 +++ Src/Modules/hlgroup.c | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'Src/Modules/hlgroup.c') diff --git a/ChangeLog b/ChangeLog index f6b41f94a..d826e6c8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2025-01-27 Oliver Kiddle + * 53329: Src/Modules/hlgroup.c: adapt .zle.sgr for CSI sequences + that use : instead of ; + * github #128: GI : Completion/Unix/Command/_vim: Updated completion for neovim diff --git a/Src/Modules/hlgroup.c b/Src/Modules/hlgroup.c index 082762623..6c5a4bec4 100644 --- a/Src/Modules/hlgroup.c +++ b/Src/Modules/hlgroup.c @@ -50,9 +50,14 @@ convertattr(char *attrstr, int sgr) char *c = s, *t = s - 1; while (c[0] == '\033' && c[1] == '[') { - c += 2; - while (isdigit(*c) || *c == ';') - *++t = *c++; + for (c += 2; ; c++) { + if (isdigit(*c)) + *++t = *c; + else if (*c == ';' || *c == ':') + *++t = ';'; + else + break; + } t++; if (*c != 'm') break; -- cgit v1.2.3