mirror of
https://github.com/tmux/tmux.git
synced 2025-03-29 02:08:48 +00:00
When parsing strings, put all commands in one group even if there are
newlines. This means that for example bind q { a \n b } and bind q "a ; b" are the same. Also log commands in different groups separated by ;; rather than ; (a command list like this should never be user visible).
This commit is contained in:
parent
3f86d6d460
commit
34804f2709
21
cmd-parse.y
21
cmd-parse.y
@ -700,15 +700,17 @@ cmd_parse_build_commands(struct cmd_parse_commands *cmds,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse each command into a command list. Create a new command list
|
* Parse each command into a command list. Create a new command list
|
||||||
* for each line so they get a new group (so the queue knows which ones
|
* for each line (unless the flag is set) so they get a new group (so
|
||||||
* to remove if a command fails when executed).
|
* the queue knows which ones to remove if a command fails when
|
||||||
|
* executed).
|
||||||
*/
|
*/
|
||||||
result = cmd_list_new();
|
result = cmd_list_new();
|
||||||
TAILQ_FOREACH(cmd, cmds, entry) {
|
TAILQ_FOREACH(cmd, cmds, entry) {
|
||||||
log_debug("%s: %u %s", __func__, cmd->line, cmd->name);
|
log_debug("%s: %u %s", __func__, cmd->line, cmd->name);
|
||||||
cmd_log_argv(cmd->argc, cmd->argv, __func__);
|
cmd_log_argv(cmd->argc, cmd->argv, __func__);
|
||||||
|
|
||||||
if (cmdlist == NULL || cmd->line != line) {
|
if (cmdlist == NULL ||
|
||||||
|
((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) {
|
||||||
if (cmdlist != NULL) {
|
if (cmdlist != NULL) {
|
||||||
cmd_parse_print_commands(pi, line, cmdlist);
|
cmd_parse_print_commands(pi, line, cmdlist);
|
||||||
cmd_list_move(result, cmdlist);
|
cmd_list_move(result, cmdlist);
|
||||||
@ -775,6 +777,19 @@ cmd_parse_from_file(FILE *f, struct cmd_parse_input *pi)
|
|||||||
struct cmd_parse_result *
|
struct cmd_parse_result *
|
||||||
cmd_parse_from_string(const char *s, struct cmd_parse_input *pi)
|
cmd_parse_from_string(const char *s, struct cmd_parse_input *pi)
|
||||||
{
|
{
|
||||||
|
struct cmd_parse_input input;
|
||||||
|
|
||||||
|
if (pi == NULL) {
|
||||||
|
memset(&input, 0, sizeof input);
|
||||||
|
pi = &input;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When parsing a string, put commands in one group even if there are
|
||||||
|
* multiple lines. This means { a \n b } is identical to "a ; b" when
|
||||||
|
* given as an argument to another command.
|
||||||
|
*/
|
||||||
|
pi->flags |= CMD_PARSE_ONEGROUP;
|
||||||
return (cmd_parse_from_buffer(s, strlen(s), pi));
|
return (cmd_parse_from_buffer(s, strlen(s), pi));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
cmd.c
23
cmd.c
@ -624,7 +624,7 @@ cmd_list_free(struct cmd_list *cmdlist)
|
|||||||
char *
|
char *
|
||||||
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||||
{
|
{
|
||||||
struct cmd *cmd;
|
struct cmd *cmd, *next;
|
||||||
char *buf, *this;
|
char *buf, *this;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
@ -634,15 +634,24 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
|||||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||||
this = cmd_print(cmd);
|
this = cmd_print(cmd);
|
||||||
|
|
||||||
len += strlen(this) + 4;
|
len += strlen(this) + 6;
|
||||||
buf = xrealloc(buf, len);
|
buf = xrealloc(buf, len);
|
||||||
|
|
||||||
strlcat(buf, this, len);
|
strlcat(buf, this, len);
|
||||||
if (TAILQ_NEXT(cmd, qentry) != NULL) {
|
|
||||||
if (escaped)
|
next = TAILQ_NEXT(cmd, qentry);
|
||||||
strlcat(buf, " \\; ", len);
|
if (next != NULL) {
|
||||||
else
|
if (cmd->group != next->group) {
|
||||||
strlcat(buf, " ; ", len);
|
if (escaped)
|
||||||
|
strlcat(buf, " \\;\\; ", len);
|
||||||
|
else
|
||||||
|
strlcat(buf, " ;; ", len);
|
||||||
|
} else {
|
||||||
|
if (escaped)
|
||||||
|
strlcat(buf, " \\; ", len);
|
||||||
|
else
|
||||||
|
strlcat(buf, " ; ", len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(this);
|
free(this);
|
||||||
|
1
tmux.h
1
tmux.h
@ -1370,6 +1370,7 @@ struct cmd_parse_input {
|
|||||||
#define CMD_PARSE_PARSEONLY 0x2
|
#define CMD_PARSE_PARSEONLY 0x2
|
||||||
#define CMD_PARSE_NOALIAS 0x4
|
#define CMD_PARSE_NOALIAS 0x4
|
||||||
#define CMD_PARSE_VERBOSE 0x8
|
#define CMD_PARSE_VERBOSE 0x8
|
||||||
|
#define CMD_PARSE_ONEGROUP 0x10
|
||||||
|
|
||||||
const char *file;
|
const char *file;
|
||||||
u_int line;
|
u_int line;
|
||||||
|
Loading…
Reference in New Issue
Block a user