diff options
-rw-r--r-- | base.h | 3 | ||||
-rw-r--r-- | buffer.c | 12 | ||||
-rw-r--r-- | lsp-write.c | 1 | ||||
-rw-r--r-- | syntax.c | 3 | ||||
-rw-r--r-- | ted.cfg | 12 |
5 files changed, 27 insertions, 4 deletions
@@ -183,7 +183,7 @@ static void print(const char *fmt, ...) { // If you are adding new languages, DO NOT change the constant values // of the previous languages. It will mess up config files which use :set-language! typedef enum { - LANG_NONE = 0, + LANG_NONE = 0, // avoid using this and use LANG_TEXT instead. LANG_C = 1, LANG_CPP = 2, LANG_RUST = 3, @@ -200,6 +200,7 @@ typedef enum { LANG_JSON = 14, LANG_XML = 15, LANG_GLSL = 16, + LANG_TEXT = 17, // plain text LANG_COUNT } Language; @@ -218,7 +218,7 @@ static Font *buffer_font(TextBuffer *buffer) { // what programming language is this? Language buffer_language(TextBuffer *buffer) { if (!buffer->path) - return LANG_NONE; + return LANG_TEXT; // @TODO(optimization): cache this? // (we're calling buffer_lsp on every edit and that calls this) @@ -229,7 +229,7 @@ Language buffer_language(TextBuffer *buffer) { size_t filename_len = strlen(filename); int match_score = 0; - Language match = LANG_NONE; + Language match = LANG_TEXT; for (u16 l = 0; l < LANG_COUNT; ++l) { const char *extensions = settings->language_extensions[l]; @@ -2759,7 +2759,7 @@ void buffer_render(TextBuffer *buffer, Rect r) { Language language = buffer_language(buffer); // dynamic array of character types, to be filled by syntax_highlight SyntaxCharType *char_types = NULL; - bool syntax_highlighting = language && settings->syntax_highlighting; + bool syntax_highlighting = language && language != LANG_TEXT && settings->syntax_highlighting; if (buffer->frame_latest_line_modified >= buffer->frame_earliest_line_modified && syntax_highlighting) { @@ -2991,6 +2991,8 @@ void buffer_dedent_cursor_line(TextBuffer *buffer) { void buffer_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { Language lang = buffer_language(buffer); const char *start = language_comment_start(lang), *end = language_comment_end(lang); + if (!start[0] && !end[0]) + return; String32 start32 = str32_from_utf8(start), end32 = str32_from_utf8(end); buffer_start_edit_chain(buffer); @@ -3044,6 +3046,8 @@ static bool buffer_line_ends_with_ascii(TextBuffer *buffer, u32 line_idx, const void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { Language lang = buffer_language(buffer); const char *start = language_comment_start(lang), *end = language_comment_end(lang); + if (!start[0] && !end[0]) + return; u32 start_len = (u32)strlen(start), end_len = (u32)strlen(end); buffer_start_edit_chain(buffer); for (u32 line_idx = first_line; line_idx <= last_line; ++line_idx) { @@ -3066,6 +3070,8 @@ void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { void buffer_toggle_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { Language lang = buffer_language(buffer); const char *start = language_comment_start(lang), *end = language_comment_end(lang); + if (!start[0] && !end[0]) + return; // if first line is a comment, uncomment lines, otherwise, comment lines if (buffer_line_starts_with_ascii(buffer, first_line, start) && buffer_line_ends_with_ascii(buffer, first_line, end)) diff --git a/lsp-write.c b/lsp-write.c index 19bd766..4409593 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -10,6 +10,7 @@ static const char *lsp_language_id(Language lang) { switch (lang) { case LANG_CONFIG: case LANG_TED_CFG: + case LANG_TEXT: case LANG_NONE: return "text"; case LANG_C: @@ -88,6 +88,7 @@ static const LanguageName language_names[] = { {LANG_JSON, "JSON"}, {LANG_XML, "XML"}, {LANG_GLSL, "GLSL"}, + {LANG_TEXT, "Text"}, }; static_assert_if_possible(arr_count(language_names) == LANG_COUNT) @@ -135,6 +136,7 @@ const char *language_comment_start(Language l) { return "<!-- "; case LANG_NONE: case LANG_MARKDOWN: + case LANG_TEXT: case LANG_COUNT: break; } @@ -1728,6 +1730,7 @@ static void syntax_highlight_go(SyntaxState *state_ptr, const char32_t *line, u3 void syntax_highlight(SyntaxState *state, Language lang, const char32_t *line, u32 line_len, SyntaxCharType *char_types) { switch (lang) { case LANG_NONE: + case LANG_TEXT: if (char_types) memset(char_types, 0, line_len * sizeof *char_types); break; @@ -146,6 +146,16 @@ lsp = "rust-analyzer" [Tex.core] lsp = "texlab" +# phantom completions are just annoying if you're not actually programming +[Markdown.core] +phantom-completions = off +[TedCfg.core] +phantom-completions = off +[Config.core] +phantom-completions = off +[Text.core] +phantom-completions = off + [keyboard] # motion and selection Left = :left @@ -379,6 +389,8 @@ cursor-line-number = #ddf line-numbers-separator = #fff3 [extensions] +# text is the default if the extension doesn't match any of the ones below +Text = .txt C = .c, .h C++ = .cpp, .hpp, .C, .H, .cxx, .hxx, .cc, .hh Rust = .rs |