From 1a9561c06ba0197b2b307a61443775f9fd11165b Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 29 Jul 2022 14:44:17 -0400 Subject: language-specific keyboard shortcuts --- README.md | 8 ++++++++ config.c | 3 ++- main.c | 2 +- syntax.c | 2 +- ted.cfg | 5 +++++ ted.h | 37 +++++++++++++++++++------------------ 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index bee145e..ff9d651 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,14 @@ it clear it's a command. Colors are formatted like `#rgb`, `#rgba`, `#rrggbb` or blue, and alpha (transparency/opacity). You can use a [color picker](https://www.google.com/search?q=color+picker) to help you out. The extensions section is fairly self-explanatory. +You can set settings for specific programming languages like this: + +``` +[HTML.core] +# set tab width for HTML files to 2 +tab-width = 2 +``` + To reset your ted configuration to the default settings, delete your ted.cfg file (`~/.local/share/ted/ted.cfg` on Linux, `C:\Users\\AppData\Local\ted\ted.cfg` on Windows) or move it somewhere else. diff --git a/config.c b/config.c index aa09444..3cd64de 100644 --- a/config.c +++ b/config.c @@ -371,6 +371,7 @@ void config_read(Ted *ted, char const *filename, int pass) { switch (section) { case SECTION_CORE: case SECTION_COLORS: + case SECTION_KEYBOARD: break; default: config_err(cfg, "%s settings cannot be configured for individual languages.", @@ -431,7 +432,7 @@ void config_read(Ted *ted, char const *filename, int pass) { case SECTION_KEYBOARD: { // lines like Ctrl+Down = 10 :down u32 key_combo = config_parse_key_combo(cfg, key); - KeyAction *action = &ted->key_actions[key_combo]; + KeyAction *action = &settings->key_actions[key_combo]; llong argument = 1; if (isdigit(*value)) { // read the argument diff --git a/main.c b/main.c index 7a6731e..60bc230 100644 --- a/main.c +++ b/main.c @@ -688,7 +688,7 @@ int main(int argc, char **argv) { (u32)((modifier & (KMOD_LSHIFT|KMOD_RSHIFT)) != 0) << KEY_MODIFIER_SHIFT_BIT | (u32)((modifier & (KMOD_LALT|KMOD_RALT)) != 0) << KEY_MODIFIER_ALT_BIT; if (key_combo < KEY_COMBO_COUNT) { - KeyAction *action = &ted->key_actions[key_combo]; + KeyAction *action = &ted_active_settings(ted)->key_actions[key_combo]; if (action->command) { command_execute(ted, action->command, action->argument); } diff --git a/syntax.c b/syntax.c index bef3ea9..97d0554 100644 --- a/syntax.c +++ b/syntax.c @@ -7,7 +7,7 @@ // returns the language this string is referring to, or LANG_NONE if it's invalid. Language language_from_str(char const *str) { for (int i = 0; i < LANG_COUNT; ++i) { - if (streq(language_names[i].name, str)) + if (strcmp_case_insensitive(language_names[i].name, str) == 0) return language_names[i].lang; } return LANG_NONE; diff --git a/ted.cfg b/ted.cfg index ab7344b..6b30ff9 100644 --- a/ted.cfg +++ b/ted.cfg @@ -231,3 +231,8 @@ Config = .cfg Javascript = .js Java = .java Go = .go + + +# You can add language-specific settings like this: +# [HTML.core] +# tab-width = 2 diff --git a/ted.h b/ted.h index b7ecf19..1ee8525 100644 --- a/ted.h +++ b/ted.h @@ -112,6 +112,24 @@ ENUM_U8 { #define SYNTAX_CODE SYNTAX_PREPROCESSOR // for markdown #define SYNTAX_LINK SYNTAX_CONSTANT // for markdown + +#define SCANCODE_COUNT 0x120 // SDL scancodes should be less than this value. +// a "key combo" is some subset of {control, shift, alt} + some key. +#define KEY_COMBO_COUNT (SCANCODE_COUNT << 3) +#define KEY_MODIFIER_CTRL_BIT 0 +#define KEY_MODIFIER_SHIFT_BIT 1 +#define KEY_MODIFIER_ALT_BIT 2 +#define KEY_MODIFIER_CTRL ((u32)1<