diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-01 12:45:37 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-02-01 12:45:37 -0500 |
commit | e53329668e403a6b73bc8c9b56ad6b55eecba4e9 (patch) | |
tree | ca87e777053112f5de53155374f2272d6aad0ca1 | |
parent | 11b50663dc489b7ec8cb1c8774d9bda2c7acac3b (diff) |
fix C hex literal highlighting
also open to untitled empty buffer
-rw-r--r-- | buffer.c | 6 | ||||
-rw-r--r-- | syntax.c | 15 | ||||
-rw-r--r-- | ted.c | 7 | ||||
-rw-r--r-- | ted.cfg | 2 |
4 files changed, 15 insertions, 15 deletions
@@ -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; } @@ -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. <stdio.h> - 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; } @@ -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. @@ -135,5 +135,5 @@ keyword = #0c0 preprocessor = #77f string = #f77 character = #a7f -comment = #777 +comment = #999 constant = #8ff |