Skip to content

Commit

Permalink
support old option names but mark as deprecated
Browse files Browse the repository at this point in the history
This is in response to a comment left on a35e7ea. Backwards compatibility
is a good idea for at least a release.
  • Loading branch information
rnpnr committed Aug 26, 2023
1 parent 2c5e692 commit 514fae4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
30 changes: 20 additions & 10 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,32 @@ static const OptionDef options[] = {
VIS_HELP("Number of spaces to display (and insert if `expandtab` is enabled) for a tab")
},
[OPTION_SHOW_SPACES] = {
{ "showspaces" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW,
{ "showspaces", "show-spaces" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW|VIS_OPTION_DEPRECATED,
VIS_HELP("Display replacement symbol instead of a space")
NULL,
"show-spaces"
},
[OPTION_SHOW_TABS] = {
{ "showtabs" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW,
{ "showtabs", "show-tabs" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW|VIS_OPTION_DEPRECATED,
VIS_HELP("Display replacement symbol for tabs")
NULL,
"show-tabs"
},
[OPTION_SHOW_NEWLINES] = {
{ "shownewlines" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW,
{ "shownewlines", "show-newlines" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW|VIS_OPTION_DEPRECATED,
VIS_HELP("Display replacement symbol for newlines")
NULL,
"show-newlines"
},
[OPTION_SHOW_EOF] = {
{ "showeof" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW,
{ "showeof", "show-eof" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_NEED_WINDOW|VIS_OPTION_DEPRECATED,
VIS_HELP("Display replacement symbol for lines after the end of the file")
NULL,
"show-eof"
},
[OPTION_NUMBER] = {
{ "numbers", "nu" },
Expand Down Expand Up @@ -382,9 +390,11 @@ static const OptionDef options[] = {
VIS_HELP("How to load existing files 'auto', 'read' or 'mmap'")
},
[OPTION_CHANGE_256COLORS] = {
{ "change256colors" },
VIS_OPTION_TYPE_BOOL,
{ "change256colors", "change-256colors" },
VIS_OPTION_TYPE_BOOL|VIS_OPTION_DEPRECATED,
VIS_HELP("Change 256 color palette to support 24bit colors")
NULL,
"change-256colors"
},
[OPTION_LAYOUT] = {
{ "layout" },
Expand Down
3 changes: 3 additions & 0 deletions vis-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Select
return false;
}

if (opt->flags & VIS_OPTION_DEPRECATED && strcmp(opt->context, name) == 0)
vis_info_show(vis, "%s is deprecated and will be removed in the next release", name);

if (!win && (opt->flags & VIS_OPTION_NEED_WINDOW)) {
vis_info_show(vis, "Need active window for `:set %s'", name);
return false;
Expand Down
1 change: 1 addition & 0 deletions vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ enum VisOption {
VIS_OPTION_TYPE_NUMBER = 1 << 2,
VIS_OPTION_VALUE_OPTIONAL = 1 << 3,
VIS_OPTION_NEED_WINDOW = 1 << 4,
VIS_OPTION_DEPRECATED = 1 << 5,
};

/**
Expand Down

0 comments on commit 514fae4

Please sign in to comment.