From f212b9d4952c87052e23b5161195917410b7c911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 19 Sep 2014 11:27:55 +0200 Subject: Implement expand tab functionality, make tabwidth configurable If expandtab is enabled then inserted tabs are replaced by tabwidth amount of spaces. Both settings apply to all windows files and can be changed via: :set tabwidth n # where 1 <= n <= 8 :set expandtab (1|yes|true)|(0|no|false) --- editor.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'editor.c') diff --git a/editor.c b/editor.c index c56aec4..e0f27cf 100644 --- a/editor.c +++ b/editor.c @@ -185,6 +185,16 @@ static void editor_windows_invalidate(Editor *ed, size_t start, size_t end) { editor_window_draw(ed->win); } +int editor_tabwidth_get(Editor *ed) { + return ed->tabwidth; +} + +void editor_tabwidth_set(Editor *ed, int tabwidth) { + if (tabwidth < 1 || tabwidth > 8) + return; + for (EditorWin *win = ed->windows; win; win = win->next) + window_tabwidth_set(win->win, tabwidth); +} bool editor_syntax_load(Editor *ed, Syntax *syntaxes, Color *colors) { bool success = true; @@ -296,6 +306,7 @@ static EditorWin *editor_window_new_text(Editor *ed, Text *text) { return NULL; } window_cursor_watch(win->win, editor_window_cursor_moved, win); + window_tabwidth_set(win->win, ed->tabwidth); if (ed->windows) ed->windows->prev = win; win->next = ed->windows; @@ -381,6 +392,8 @@ Editor *editor_new(int width, int height) { goto err; ed->width = width; ed->height = height; + ed->tabwidth = 8; + ed->expandtab = false; ed->windows_arrange = editor_windows_arrange_horizontal; return ed; err: -- cgit v1.2.3