aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hotkey.c13
-rw-r--r--src/hotkey.h1
-rw-r--r--src/parse.c18
-rw-r--r--src/tokenize.c2
-rw-r--r--src/tokenize.h2
5 files changed, 32 insertions, 4 deletions
diff --git a/src/hotkey.c b/src/hotkey.c
index 0c8b9f0..2f0df3a 100644
--- a/src/hotkey.c
+++ b/src/hotkey.c
@@ -145,14 +145,21 @@ should_capture_hotkey(uint32_t capture)
internal inline char *
find_process_command_mapping(struct hotkey *hotkey, uint32_t *capture, struct carbon_event *carbon)
{
+ char *result = NULL;
+ bool found = false;
+
for (int i = 0; i < buf_len(hotkey->process_name); ++i) {
if (same_string(carbon->process_name, hotkey->process_name[i])) {
- return hotkey->command[i];
+ result = hotkey->command[i];
+ found = true;
+ break;
}
}
- *capture &= ~HOTKEY_FOUND;
- return NULL;
+ if (!found) result = hotkey->wildcard_command;
+ if (!result) *capture &= ~HOTKEY_FOUND;
+
+ return result;
}
bool find_and_exec_hotkey(struct hotkey *k, struct table *t, struct mode **m, struct carbon_event *carbon)
diff --git a/src/hotkey.h b/src/hotkey.h
index 71d2e1d..641875d 100644
--- a/src/hotkey.h
+++ b/src/hotkey.h
@@ -73,6 +73,7 @@ struct hotkey
uint32_t key;
char **process_name;
char **command;
+ char *wildcard_command;
struct mode **mode_list;
};
diff --git a/src/parse.c b/src/parse.c
index a5760b7..760485d 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -92,8 +92,24 @@ parse_process_command_list(struct parser *parser, struct hotkey *hotkey)
if (parser_match(parser, Token_Command)) {
parse_command(parser, hotkey);
parse_process_command_list(parser, hotkey);
+ } else if (parser_match(parser, Token_Unbound)) {
+ buf_push(hotkey->command, NULL);
+ parse_process_command_list(parser, hotkey);
+ } else {
+ parser_report_error(parser, parser_peek(parser), "expected '~' or ':' followed by command\n");
+ }
+ } else if (parser_match(parser, Token_Wildcard)) {
+ if (parser_match(parser, Token_Command)) {
+ struct token command = parser_previous(parser);
+ char *result = copy_string_count(command.text, command.length);
+ debug("\tcmd: '%s'\n", result);
+ hotkey->wildcard_command = result;
+ parse_process_command_list(parser, hotkey);
+ } else if (parser_match(parser, Token_Unbound)) {
+ hotkey->wildcard_command = NULL;
+ parse_process_command_list(parser, hotkey);
} else {
- parser_report_error(parser, parser_peek(parser), "expected ':' followed by command\n");
+ parser_report_error(parser, parser_peek(parser), "expected '~' or ':' followed by command\n");
}
} else if (parser_match(parser, Token_EndList)) {
if (!buf_len(hotkey->process_name)) {
diff --git a/src/tokenize.c b/src/tokenize.c
index 8445a71..a0fd93d 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -146,6 +146,8 @@ get_token(struct tokenizer *tokenizer)
case ',': { token.type = Token_Comma; } break;
case '<': { token.type = Token_Insert; } break;
case '@': { token.type = Token_Capture; } break;
+ case '~': { token.type = Token_Unbound; } break;
+ case '*': { token.type = Token_Wildcard; } break;
case '[': { token.type = Token_BeginList; } break;
case ']': { token.type = Token_EndList; } break;
case '"': {
diff --git a/src/tokenize.h b/src/tokenize.h
index 73cdb30..ff82dee 100644
--- a/src/tokenize.h
+++ b/src/tokenize.h
@@ -49,6 +49,8 @@ enum token_type
Token_Dash,
Token_Arrow,
Token_Capture,
+ Token_Unbound,
+ Token_Wildcard,
Token_String,
Token_BeginList,