From: NeilBrown Date: Wed, 14 Jun 2023 10:27:51 +0000 (+1000) Subject: global-set-attr: support append. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=0f255ebb6f23e8cc517b9337bddaa4e326ac4e5a;p=edlib.git global-set-attr: support append. Make it easy to append to a global attr. Note the semantics are a bit different to appending to a pane attr. I wonder what is best. Signed-off-by: NeilBrown --- diff --git a/core-editor.c b/core-editor.c index b17c19fc..c7173531 100644 --- a/core-editor.c +++ b/core-editor.c @@ -34,9 +34,23 @@ DEF_LOOKUP_CMD(ed_handle, ed_map); DEF_CMD(global_set_attr) { + char *v; if (!ci->str) return Enoarg; - attr_set_str(&ci->home->attrs, ci->str, ci->str2); + if (!ci->num) { + attr_set_str(&ci->home->attrs, ci->str, ci->str2); + return 1; + } + /* Append */ + if (!ci->str2) + return 1; + v = attr_find(ci->home->attrs, ci->str); + if (!v) { + attr_set_str(&ci->home->attrs, ci->str, ci->str2); + return 1; + } + v = strconcat(ci->home, v, ci->str2); + attr_set_str(&ci->home->attrs, ci->str, v); return 1; }