diff options
-rw-r--r-- | buffer.c | 25 | ||||
-rw-r--r-- | command.c | 2 | ||||
-rw-r--r-- | config.c | 1 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | ted.cfg | 1 | ||||
-rw-r--r-- | ted.h | 1 |
6 files changed, 27 insertions, 7 deletions
@@ -1756,6 +1756,17 @@ void buffer_insert_utf8_at_cursor(TextBuffer *buffer, char const *utf8) { } } +void buffer_insert_tab_at_cursor(TextBuffer *buffer) { + Settings const *settings = buffer_settings(buffer); + + if (settings->indent_with_spaces) { + for (int i = 0; i < settings->tab_width; ++i) + buffer_insert_char_at_cursor(buffer, ' '); + } else { + buffer_insert_char_at_cursor(buffer, '\t'); + } +} + // insert newline at cursor and auto-indent void buffer_newline(TextBuffer *buffer) { if (buffer->is_line_buffer) { @@ -2584,11 +2595,17 @@ void buffer_render(TextBuffer *buffer, Rect r) { void buffer_indent_lines(TextBuffer *buffer, u32 first_line, u32 last_line) { assert(first_line <= last_line); + Settings const *settings = buffer_settings(buffer); + buffer_start_edit_chain(buffer); - for (u32 i = first_line; i <= last_line; ++i) { - BufferPos pos = {.line = i, .index = 0}; - char32_t c = '\t'; - buffer_insert_text_at_pos(buffer, pos, str32(&c, 1)); + for (u32 l = first_line; l <= last_line; ++l) { + BufferPos pos = {.line = l, .index = 0}; + if (settings->indent_with_spaces) { + for (int i = 0; i < settings->tab_width; ++i) + buffer_insert_char_at_pos(buffer, pos, ' '); + } else { + buffer_insert_char_at_pos(buffer, pos, '\t'); + } } buffer_end_edit_chain(buffer); } @@ -126,7 +126,7 @@ void command_execute(Ted *ted, Command c, i64 argument) { if (buffer->selection) buffer_indent_selection(buffer); else - buffer_insert_char_at_cursor(buffer, '\t'); + buffer_insert_tab_at_cursor(buffer); } break; case CMD_BACKTAB: @@ -239,6 +239,7 @@ void config_read(Ted *ted, char const *filename, int pass) { {"line-numbers", &nullset->line_numbers, true}, {"restore-session", &nullset->restore_session, false}, {"regenerate-tags-if-not-found", &nullset->regenerate_tags_if_not_found, true}, + {"indent-with-spaces", &nullset->indent_with_spaces, true}, }; OptionU8 const options_u8[] = { {"tab-width", &nullset->tab_width, 1, 100, true}, @@ -84,12 +84,12 @@ static void die(char const *fmt, ...) { va_start(args, fmt); vsnprintf(buf, sizeof buf - 1, fmt, args); va_end(args); - + // show a message box, and if that fails, print it if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", buf, NULL) < 0) { debug_println("%s\n", buf); } - + exit(EXIT_FAILURE); } @@ -1,5 +1,6 @@ [core] tab-width = 4 +indent-with-spaces = off # cursor width in pixels cursor-width = 1 # time to blink cursor for (i.e. it will be on for cursor-blink-time-on seconds, then off for cursor-blink-time-off seconds) @@ -143,6 +143,7 @@ typedef struct { bool auto_reload; bool restore_session; bool regenerate_tags_if_not_found; + bool indent_with_spaces; u8 tab_width; u8 cursor_width; u8 undo_save_time; |