From c1ede507d954b98a73c40665e7aee6fe5f0c5bce Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 07:41:29 +0000 Subject: Add a helper function to work out option table from name. --- cmd-set-option.c | 55 ++++++------------------------------------------------- 1 file changed, 6 insertions(+), 49 deletions(-) (limited to 'cmd-set-option.c') diff --git a/cmd-set-option.c b/cmd-set-option.c index 7be561f2..10b70304 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -92,16 +92,19 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) struct options *oo; struct options_entry *parent, *o; char *name, *argument, *value = NULL, *cause; - const char *target; int window, idx, already, error, ambiguous; struct style *sy; + window = (self->entry == &cmd_set_window_option_entry); + /* Expand argument. */ c = cmd_find_client(item, NULL, 1); argument = format_single(item, args->argv[0], c, s, wl, NULL); + /* If set-hook -R, fire the hook straight away. */ if (self->entry == &cmd_set_hook_entry && args_has(args, 'R')) { notify_hook(item, argument); + free(argument); return (CMD_RETURN_NORMAL); } @@ -123,25 +126,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) else value = xstrdup(args->argv[1]); - /* - * Figure out the scope: for user options it comes from the arguments, - * otherwise from the option name. - */ - if (*name == '@') { - window = (self->entry == &cmd_set_window_option_entry); - scope = options_scope_from_flags(args, window, fs, &oo, &cause); - } else { - if (options_get_only(global_options, name) != NULL) - scope = OPTIONS_TABLE_SERVER; - else if (options_get_only(global_s_options, name) != NULL) - scope = OPTIONS_TABLE_SESSION; - else if (options_get_only(global_w_options, name) != NULL) - scope = OPTIONS_TABLE_WINDOW; - else { - scope = OPTIONS_TABLE_NONE; - xasprintf(&cause, "unknown option: %s", argument); - } - } + /* Get the scope and table for the option .*/ + scope = options_scope_from_name(args, window, name, fs, &oo, &cause); if (scope == OPTIONS_TABLE_NONE) { if (args_has(args, 'q')) goto out; @@ -149,35 +135,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) free(cause); goto fail; } - - /* Which table should this option go into? */ - if (scope == OPTIONS_TABLE_SERVER) - oo = global_options; - else if (scope == OPTIONS_TABLE_SESSION) { - if (args_has(self->args, 'g')) - oo = global_s_options; - else if (s == NULL) { - target = args_get(args, 't'); - if (target != NULL) - cmdq_error(item, "no such session: %s", target); - else - cmdq_error(item, "no current session"); - goto fail; - } else - oo = s->options; - } else if (scope == OPTIONS_TABLE_WINDOW) { - if (args_has(self->args, 'g')) - oo = global_w_options; - else if (wl == NULL) { - target = args_get(args, 't'); - if (target != NULL) - cmdq_error(item, "no such window: %s", target); - else - cmdq_error(item, "no current window"); - goto fail; - } else - oo = wl->window->options; - } o = options_get_only(oo, name); parent = options_get(oo, name); -- cgit From 5f92f92908b81b4ec66682adb84b9ffc8d83c2f7 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 20 Jun 2019 11:59:59 +0000 Subject: Add a per-pane option set. Pane options inherit from window options (so there should be no change to existing behaviour) and are set and shown with set-option -p and show-options -p. Change remain-on-exit and window-style/window-active-style to be pane options (some others will be changed later). This makes select-pane -P and -g unnecessary so no longer document them (they still work) and no longer document set-window-option and show-window-options in favour of set-option -w and show-options -w. --- cmd-set-option.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'cmd-set-option.c') diff --git a/cmd-set-option.c b/cmd-set-option.c index 10b70304..23b45230 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -43,10 +43,10 @@ const struct cmd_entry cmd_set_option_entry = { .name = "set-option", .alias = "set", - .args = { "aFgoqst:uw", 1, 2 }, - .usage = "[-aFgosquw] [-t target-window] option [value]", + .args = { "aFgopqst:uw", 1, 2 }, + .usage = "[-aFgopqsuw] " CMD_TARGET_PANE_USAGE " option [value]", - .target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL }, + .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .flags = CMD_AFTERHOOK, .exec = cmd_set_option_exec @@ -88,11 +88,12 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) struct session *s = fs->s; struct winlink *wl = fs->wl; struct window *w; - enum options_table_scope scope; + struct window_pane *wp; struct options *oo; struct options_entry *parent, *o; char *name, *argument, *value = NULL, *cause; int window, idx, already, error, ambiguous; + int scope; struct style *sy; window = (self->entry == &cmd_set_window_option_entry); @@ -249,8 +250,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item) alerts_reset_all(); if (strcmp(name, "window-style") == 0 || strcmp(name, "window-active-style") == 0) { - RB_FOREACH(w, windows, &windows) - w->flags |= WINDOW_STYLECHANGED; + RB_FOREACH(wp, window_pane_tree, &all_window_panes) + wp->flags |= PANE_STYLECHANGED; } if (strcmp(name, "pane-border-status") == 0) { RB_FOREACH(w, windows, &windows) -- cgit