vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 0e90d66c2b3eacf5204125ed7d1786cc5314c56a
parent 7e51ebb82938fda0349c46a17715a0216fc904f5
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 11 Apr 2015 10:31:28 +0200

Eliminate global state for :set options

Diffstat:
Meditor.c | 1+
Meditor.h | 1+
Mvis.c | 12+++++-------
3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/editor.c b/editor.c @@ -410,6 +410,7 @@ void editor_free(Editor *ed) { editor_syntax_unload(ed); ed->ui->free(ed->ui); map_free(ed->cmds); + map_free(ed->options); free(ed); } diff --git a/editor.h b/editor.h @@ -122,6 +122,7 @@ struct Editor { bool expandtab; /* whether typed tabs should be converted to spaces */ bool autoindent; /* whether indentation should be copied from previous line on newline */ Map *cmds; /* ":"-commands, used for unique prefix queries */ + Map *options; /* ":set"-options */ }; Editor *editor_new(Ui*); diff --git a/vis.c b/vis.c @@ -1392,15 +1392,13 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { [OPTION_NUMBER_RELATIVE] = { { "relativenumbers", "rnu" }, OPTION_TYPE_BOOL }, }; - static Map *optmap = NULL; - - if (!optmap) { - if (!(optmap = map_new())) + if (!vis->options) { + if (!(vis->options = map_new())) return false; for (int i = 0; i < LENGTH(options); i++) { options[i].index = i; for (const char **name = options[i].names; *name; name++) { - if (!map_put(optmap, *name, &options[i])) + if (!map_put(vis->options, *name, &options[i])) return false; } } @@ -1416,7 +1414,7 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { OptionDef *opt = NULL; if (!strncasecmp(argv[1], "no", 2)) { - opt = map_closest(optmap, argv[1]+2); + opt = map_closest(vis->options, argv[1]+2); if (opt && opt->type == OPTION_TYPE_BOOL) invert = true; else @@ -1424,7 +1422,7 @@ static bool cmd_set(Filerange *range, enum CmdOpt cmdopt, const char *argv[]) { } if (!opt) - opt = map_closest(optmap, argv[1]); + opt = map_closest(vis->options, argv[1]); if (!opt) { editor_info_show(vis, "Unknown option: `%s'", argv[1]); return false;