From ebc9dcb3bb71c2c8640466d84897971648a43845 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 14 Jun 2019 12:40:35 +0100 Subject: Add a bit to {}. --- CHANGES | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index b5d83e50..751b5210 100644 --- a/CHANGES +++ b/CHANGES @@ -5,7 +5,9 @@ CHANGES FROM 2.9 to 3.0 take other commands as string arguments to be expressed more clearly and without additional escaping. - A literal { and } must now be escaped or quoted, for example '{' and '}'. + A literal { and } or a string containing { or } must now be escaped or + quoted, for example '{' and '}' instead of { or }, or 'X#{foo}' instead of + X#{foo}. * New <, >, <= and >= comparison operators for formats. -- cgit From 0a94dbe051042cba644240ab0361319744ee4875 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 14 Jun 2019 12:04:11 +0000 Subject: A couple of minor parser changes around conditions: 1) only treat #{ specially after a condition, otherwise as a comment (which is more as most people expect) 2) allow formats to be quoted after a condition. --- cmd-parse.y | 26 ++++++++++++++++++++------ tmux.1 | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cmd-parse.y b/cmd-parse.y index 6feeb35a..9a2c2cfd 100644 --- a/cmd-parse.y +++ b/cmd-parse.y @@ -59,6 +59,7 @@ struct cmd_parse_state { size_t len; size_t off; + int condition; int eol; int eof; struct cmd_parse_input *input; @@ -102,7 +103,7 @@ static void cmd_parse_free_commands(struct cmd_parse_commands *); %token ENDIF %token FORMAT TOKEN EQUALS -%type argument expanded +%type argument expanded format %type arguments %type if_open if_elif %type elif elif1 @@ -158,7 +159,16 @@ statement : condition } } -expanded : FORMAT +format : FORMAT + { + $$ = $1; + } + | TOKEN + { + $$ = $1; + } + +expanded : format { struct cmd_parse_state *ps = &parse_state; struct cmd_parse_input *pi = ps->input; @@ -950,12 +960,15 @@ yylex(void) { struct cmd_parse_state *ps = &parse_state; char *token, *cp; - int ch, next; + int ch, next, condition; if (ps->eol) ps->input->line++; ps->eol = 0; + condition = ps->condition; + ps->condition = 0; + for (;;) { ch = yylex_getc(); @@ -995,11 +1008,11 @@ yylex(void) if (ch == '#') { /* - * #{ opens a format; anything else is a comment, - * ignore up to the end of the line. + * #{ after a condition opens a format; anything else + * is a comment, ignore up to the end of the line. */ next = yylex_getc(); - if (next == '{') { + if (condition && next == '{') { yylval.token = yylex_format(); if (yylval.token == NULL) return (ERROR); @@ -1026,6 +1039,7 @@ yylex(void) } if (*cp == '\0') return (TOKEN); + ps->condition = 1; if (strcmp(yylval.token, "%if") == 0) { free(yylval.token); return (IF); diff --git a/tmux.1 b/tmux.1 index 263aecbc..286192a3 100644 --- a/tmux.1 +++ b/tmux.1 @@ -583,9 +583,9 @@ or .Ql %endif . For example: .Bd -literal -offset indent -%if #{==:#{host},myhost} +%if "#{==:#{host},myhost}" set -g status-style bg=red -%elif #{==:#{host},myotherhost} +%elif "#{==:#{host},myotherhost}" set -g status-style bg=green %else set -g status-style bg=blue -- cgit From a924694820c631d7d9b1b13ad48ce4fc0a60df8b Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 13 Jun 2019 21:44:13 +0000 Subject: Use the right client when working out where to save or load the buffer, reported by kn@. --- cmd-load-buffer.c | 2 +- cmd-save-buffer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c index 47cb0ca2..3e669093 100644 --- a/cmd-load-buffer.c +++ b/cmd-load-buffer.c @@ -93,7 +93,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_WAIT); } - file = server_client_get_path(c, path); + file = server_client_get_path(item->client, path); free(path); f = fopen(file, "rb"); diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index 938bb3d6..3395612f 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -104,7 +104,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item) if (args_has(self->args, 'a')) flags = "ab"; - file = server_client_get_path(c, path); + file = server_client_get_path(item->client, path); free(path); f = fopen(file, flags); -- cgit