diff options
author | pommicket <pommicket@gmail.com> | 2022-07-29 14:44:17 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-07-29 14:44:17 -0400 |
commit | 1a9561c06ba0197b2b307a61443775f9fd11165b (patch) | |
tree | 2297afc02e5a4eb7f65a8248db3906284c144737 | |
parent | ab65fe136f7a8739b78aaa4801a9fb761a301417 (diff) |
language-specific keyboard shortcuts
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | config.c | 3 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | syntax.c | 2 | ||||
-rw-r--r-- | ted.cfg | 5 | ||||
-rw-r--r-- | ted.h | 37 |
6 files changed, 36 insertions, 21 deletions
@@ -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\<your user name>\AppData\Local\ted\ted.cfg` on Windows) or move it somewhere else. @@ -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 @@ -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); } @@ -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; @@ -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 @@ -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<<KEY_MODIFIER_CTRL_BIT) +#define KEY_MODIFIER_SHIFT ((u32)1<<KEY_MODIFIER_SHIFT_BIT) +#define KEY_MODIFIER_ALT ((u32)1<<KEY_MODIFIER_ALT_BIT) +// ctrl+alt+c is encoded as SDL_SCANCODE_C << 3 | KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT + +typedef struct KeyAction { + u32 line_number; // config line number where this was set + Command command; // this will be 0 (COMMAND_UNKNOWN) if there's no action for the key + i64 argument; +} KeyAction; + typedef struct { float cursor_blink_time_on, cursor_blink_time_off; u32 colors[COLOR_COUNT]; @@ -135,25 +153,9 @@ typedef struct { char build_default_command[256]; // [i] = comma-separated string of file extensions for language i, or NULL for none char *language_extensions[LANG_COUNT]; + KeyAction key_actions[KEY_COMBO_COUNT]; } Settings; -#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<<KEY_MODIFIER_CTRL_BIT) -#define KEY_MODIFIER_SHIFT ((u32)1<<KEY_MODIFIER_SHIFT_BIT) -#define KEY_MODIFIER_ALT ((u32)1<<KEY_MODIFIER_ALT_BIT) -// ctrl+alt+c is encoded as SDL_SCANCODE_C << 3 | KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT - -typedef struct KeyAction { - u32 line_number; // config line number where this was set - Command command; // this will be 0 (COMMAND_UNKNOWN) if there's no action for the key - i64 argument; -} KeyAction; - // a position in the buffer typedef struct { u32 line; @@ -320,7 +322,6 @@ typedef struct Ted { TextBuffer argument_buffer; // used for command selector double error_time; // time error box was opened (in seconds -- see time_get_seconds) double cursor_error_time; // time which the cursor error animation started (cursor turns red, e.g. when there's no autocomplete suggestion) - KeyAction key_actions[KEY_COMBO_COUNT]; bool search_cwd; // should the working directory be searched for files? set to true if the executable isn't "installed" bool quit; // if set to true, the window will close next frame. NOTE: this doesn't check for unsaved changes!! bool find; // is the find or find+replace menu open? |