From 5a773109742d9444ab7dd7f545d7d202980a8b08 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 7 Apr 2021 12:50:12 +0000 Subject: [PATCH] Add a current_file format for the config file being parsed. Originally suggested by kn@, also GitHub issue 2638. --- usr.bin/tmux/cfg.c | 22 +++++++++++++++++++--- usr.bin/tmux/cmd-queue.c | 4 ++-- usr.bin/tmux/tmux.1 | 5 +++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c index 204a3ab6d49..fe053e87ca7 100644 --- a/usr.bin/tmux/cfg.c +++ b/usr.bin/tmux/cfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cfg.c,v 1.82 2021/02/22 08:18:13 nicm Exp $ */ +/* $OpenBSD: cfg.c,v 1.83 2021/04/07 12:50:12 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -103,6 +103,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags, struct cmd_parse_input pi; struct cmd_parse_result *pr; struct cmdq_item *new_item0; + struct cmdq_state *state; if (new_item != NULL) *new_item = NULL; @@ -136,12 +137,19 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags, return (0); } - new_item0 = cmdq_get_command(pr->cmdlist, NULL); + if (item != NULL) + state = cmdq_copy_state(cmdq_get_state(item)); + else + state = cmdq_new_state(NULL, NULL, 0); + cmdq_add_format(state, "current_file", "%s", pi.file); + + new_item0 = cmdq_get_command(pr->cmdlist, state); if (item != NULL) new_item0 = cmdq_insert_after(item, new_item0); else new_item0 = cmdq_append(NULL, new_item0); cmd_list_free(pr->cmdlist); + cmdq_free_state(state); if (new_item != NULL) *new_item = new_item0; @@ -156,6 +164,7 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path, struct cmd_parse_input pi; struct cmd_parse_result *pr; struct cmdq_item *new_item0; + struct cmdq_state *state; if (new_item != NULL) *new_item = NULL; @@ -182,12 +191,19 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path, return (0); } - new_item0 = cmdq_get_command(pr->cmdlist, NULL); + if (item != NULL) + state = cmdq_copy_state(cmdq_get_state(item)); + else + state = cmdq_new_state(NULL, NULL, 0); + cmdq_add_format(state, "current_file", "%s", pi.file); + + new_item0 = cmdq_get_command(pr->cmdlist, state); if (item != NULL) new_item0 = cmdq_insert_after(item, new_item0); else new_item0 = cmdq_append(NULL, new_item0); cmd_list_free(pr->cmdlist); + cmdq_free_state(state); if (new_item != NULL) *new_item = new_item0; diff --git a/usr.bin/tmux/cmd-queue.c b/usr.bin/tmux/cmd-queue.c index 1aca7393cd7..96d609a8405 100644 --- a/usr.bin/tmux/cmd-queue.c +++ b/usr.bin/tmux/cmd-queue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-queue.c,v 1.100 2020/11/30 13:37:45 nicm Exp $ */ +/* $OpenBSD: cmd-queue.c,v 1.101 2021/04/07 12:50:12 nicm Exp $ */ /* * Copyright (c) 2013 Nicholas Marriott @@ -276,7 +276,7 @@ cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft) const struct cmd_entry *entry; if (item->cmd != NULL) { - entry = cmd_get_entry (item->cmd); + entry = cmd_get_entry(item->cmd); format_add(ft, "command", "%s", entry->name); } if (item->state->formats != NULL) diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 0e39276863b..455b2f67a20 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.831 2021/04/01 06:37:46 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.832 2021/04/07 12:50:12 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: April 1 2021 $ +.Dd $Mdocdate: April 7 2021 $ .Dt TMUX 1 .Os .Sh NAME @@ -4859,6 +4859,7 @@ The following variables are available, where appropriate: .It Li "copy_cursor_word" Ta "" Ta "Word under cursor in copy mode" .It Li "copy_cursor_x" Ta "" Ta "Cursor X position in copy mode" .It Li "copy_cursor_y" Ta "" Ta "Cursor Y position in copy mode" +.It Li "current_file" Ta "" Ta "Current configuration file" .It Li "cursor_character" Ta "" Ta "Character at cursor in pane" .It Li "cursor_flag" Ta "" Ta "Pane cursor flag" .It Li "cursor_x" Ta "" Ta "Cursor X position in pane" -- 2.20.1