From e53329668e403a6b73bc8c9b56ad6b55eecba4e9 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Mon, 1 Feb 2021 12:45:37 -0500 Subject: fix C hex literal highlighting also open to untitled empty buffer --- buffer.c | 6 +++++- syntax.c | 15 ++++----------- ted.c | 7 +++++-- ted.cfg | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/buffer.c b/buffer.c index 41dc216..9a0627f 100644 --- a/buffer.c +++ b/buffer.c @@ -52,6 +52,10 @@ char const *buffer_get_filename(TextBuffer *buffer) { return buffer->filename; } +bool buffer_is_untitled(TextBuffer *buffer) { + return streq(buffer->filename, TED_UNTITLED); +} + // clear all undo and redo events void buffer_clear_undo_redo(TextBuffer *buffer) { buffer_clear_undo_history(buffer); @@ -132,7 +136,7 @@ static bool buffer_pos_valid(TextBuffer *buffer, BufferPos p) { // are there any unsaved changes? bool buffer_unsaved_changes(TextBuffer *buffer) { - if (streq(buffer->filename, TED_UNTITLED) && buffer_empty(buffer)) + if (buffer_is_untitled(buffer) && buffer_empty(buffer)) return false; // don't worry about empty untitled buffers return buffer->modified; } diff --git a/syntax.c b/syntax.c index 4491f0d..1c426e8 100644 --- a/syntax.c +++ b/syntax.c @@ -45,7 +45,7 @@ static void syntax_highlight_c(SyntaxStateC *state, char32_t *line, u32 line_len bool in_multi_line_comment = state->multi_line_comment; bool in_char = false; bool in_number = false; - + int backslashes = 0; for (u32 i = 0; i < line_len; ++i) { SyntaxCharType type = SYNTAX_NORMAL; @@ -92,14 +92,6 @@ static void syntax_highlight_c(SyntaxStateC *state, char32_t *line, u32 line_len else if (!in_multi_line_comment && !in_single_line_comment && !in_string) in_char = in_char_now = true; break; - case '<': // preprocessor string, e.g. - if (in_preprocessor && !in_char) - in_string = in_string_now = true; - break; - case '>': - if (in_preprocessor && in_string) - in_string = false; - break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // don't you wish C had case ranges... // a number! if (!in_single_line_comment && !in_multi_line_comment && !in_string && !in_number && !in_char) { @@ -209,8 +201,9 @@ static void syntax_highlight_c(SyntaxStateC *state, char32_t *line, u32 line_len } break; } if (line[i] != '\\') backslashes = 0; - if (in_number && !(is32_digit(line[i]) || line[i] == '.' || line[i] == 'e' || - (i && line[i-1] == 'e' && (line[i] == '+' || line[i] == '-')))) { + if (in_number && !(is32_digit(line[i]) || line[i] == '.' + || (line[i] < CHAR_MAX && strchr("xXoObBlLuU", (char)line[i])) + || (i && line[i-1] == 'e' && (line[i] == '+' || line[i] == '-')))) { in_number = false; } diff --git a/ted.c b/ted.c index f5de990..65f4dc5 100644 --- a/ted.c +++ b/ted.c @@ -168,7 +168,10 @@ static Status ted_open_buffer(Ted *ted, u16 *buffer_idx, u16 *tab) { // Returns true on success static bool ted_open_file(Ted *ted, char const *filename) { u16 buffer_idx, tab_idx; - if (ted_open_buffer(ted, &buffer_idx, &tab_idx)) { + if (buffer_is_untitled(ted->active_buffer) && buffer_empty(ted->active_buffer)) { + // the active buffer is just an empty untitled buffer. open it here. + return buffer_load_file(ted->active_buffer, filename); + } else if (ted_open_buffer(ted, &buffer_idx, &tab_idx)) { TextBuffer *buffer = &ted->buffers[buffer_idx]; if (buffer_load_file(buffer, filename)) { return true; @@ -230,7 +233,7 @@ static bool ted_save_all(Ted *ted) { if (buffers_used[i]) { TextBuffer *buffer = &ted->buffers[i]; if (buffer_unsaved_changes(buffer)) { - if (buffer->filename && streq(buffer->filename, TED_UNTITLED)) { + if (buffer->filename && buffer_is_untitled(buffer)) { ted_switch_to_buffer(ted, i); menu_open(ted, MENU_SAVE_AS); success = false; // we haven't saved this buffer yet; we've just opened the "save as" menu. diff --git a/ted.cfg b/ted.cfg index d2e7d49..7e2877f 100644 --- a/ted.cfg +++ b/ted.cfg @@ -135,5 +135,5 @@ keyword = #0c0 preprocessor = #77f string = #f77 character = #a7f -comment = #777 +comment = #999 constant = #8ff -- cgit v1.2.3