aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sam.c2
-rw-r--r--view.c6
-rw-r--r--view.h2
-rw-r--r--vis-cmds.c10
-rw-r--r--vis-core.h1
-rw-r--r--vis-lua.c12
-rw-r--r--vis-operators.c4
-rw-r--r--vis.c4
8 files changed, 19 insertions, 22 deletions
diff --git a/sam.c b/sam.c
index db4627b..df8cf83 100644
--- a/sam.c
+++ b/sam.c
@@ -328,7 +328,7 @@ static const OptionDef options[] = {
},
[OPTION_TABWIDTH] = {
{ "tabwidth", "tw" },
- VIS_OPTION_TYPE_NUMBER,
+ VIS_OPTION_TYPE_NUMBER|VIS_OPTION_NEED_WINDOW,
VIS_HELP("Number of spaces to display (and insert if `expandtab` is enabled) for a tab")
},
[OPTION_SHOW_SPACES] = {
diff --git a/view.c b/view.c
index a684382..5fa512b 100644
--- a/view.c
+++ b/view.c
@@ -120,10 +120,16 @@ static void selection_free(Selection*);
static size_t cursor_set(Selection*, Line *line, int col);
void view_tabwidth_set(View *view, int tabwidth) {
+ if (tabwidth < 1 || tabwidth > 8)
+ return;
view->tabwidth = tabwidth;
view_draw(view);
}
+int view_tabwidth_get(View *view) {
+ return view->tabwidth;
+}
+
/* reset internal view data structures (cell matrix, line offsets etc.) */
static void view_clear(View *view) {
memset(view->lines, 0, view->lines_size);
diff --git a/view.h b/view.h
index fbe3736..95df58b 100644
--- a/view.h
+++ b/view.h
@@ -365,6 +365,8 @@ const char *view_breakat_get(View*);
/** Set how many spaces are used to display a tab `\t` character. */
void view_tabwidth_set(View*, int tabwidth);
+/** Get how many spaces are used to display a tab `\t` character. */
+int view_tabwidth_get(View*);
/** Define a display style. */
bool view_style_define(View*, enum UiStyle, const char *style);
/** Apply a style to a text range. */
diff --git a/vis-cmds.c b/vis-cmds.c
index bf567bf..968b7f2 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -129,14 +129,6 @@ static void windows_arrange(Vis *vis, enum UiLayout layout) {
vis->ui->arrange(vis->ui, layout);
}
-void vis_tabwidth_set(Vis *vis, int tabwidth) {
- if (tabwidth < 1 || tabwidth > 8)
- return;
- for (Win *win = vis->windows; win; win = win->next)
- view_tabwidth_set(win->view, tabwidth);
- vis->tabwidth = tabwidth;
-}
-
void vis_shell_set(Vis *vis, const char *new_shell) {
char *shell = strdup(new_shell);
if (!shell) {
@@ -269,7 +261,7 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Select
vis->autoindent = toggle ? !vis->autoindent : arg.b;
break;
case OPTION_TABWIDTH:
- vis_tabwidth_set(vis, arg.i);
+ view_tabwidth_set(vis->win->view, arg.i);
break;
case OPTION_SHOW_SPACES:
case OPTION_SHOW_TABS:
diff --git a/vis-core.h b/vis-core.h
index ef04f1b..e8bc27e 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -183,7 +183,6 @@ struct Vis {
char search_char[8]; /* last used character to search for via 'f', 'F', 't', 'T' */
int last_totill; /* last to/till movement used for ';' and ',' */
int search_direction; /* used for `n` and `N` */
- int tabwidth; /* how many spaces should be used to display a tab */
bool expandtab; /* whether typed tabs should be converted to spaces */
bool autoindent; /* whether indentation should be copied from previous line on newline */
bool change_colors; /* whether to adjust 256 color palette for true colors */
diff --git a/vis-lua.c b/vis-lua.c
index bee077c..c3d3128 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -1553,8 +1553,6 @@ static int vis_options_assign(Vis *vis, lua_State *L, const char *key, int next)
if (!lua_isstring(L, next))
return newindex_common(L);
vis_shell_set(vis, lua_tostring(L, next));
- } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) {
- vis_tabwidth_set(vis, luaL_checkint(L, next));
}
return 0;
}
@@ -1663,7 +1661,6 @@ static const struct luaL_Reg vis_lua[] = {
* @tfield[opt=false] boolean ignorecase {ic}
* @tfield[opt="auto"] string loadmethod `"auto"`, `"read"`, or `"mmap"`.
* @tfield[opt="/bin/sh"] string shell
- * @tfield[opt=8] int tabwidth {tw}
*/
static int vis_options_index(lua_State *L) {
@@ -1704,9 +1701,6 @@ static int vis_options_index(lua_State *L) {
} else if (strcmp(key, "shell") == 0) {
lua_pushstring(L, vis->shell);
return 1;
- } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) {
- lua_pushinteger(L, vis->tabwidth);
- return 1;
}
}
return index_common(L);
@@ -1971,6 +1965,8 @@ static int window_options_assign(Win *win, lua_State *L, const char *key, int ne
view_options_set(win->view, flags);
} else if (strcmp(key, "wrapcolumn") == 0 || strcmp(key, "wc") == 0) {
view_wrapcolumn_set(win->view, luaL_checkint(L, next));
+ } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) {
+ view_tabwidth_set(win->view, luaL_checkint(L, next));
}
return 0;
}
@@ -2180,6 +2176,7 @@ static const struct luaL_Reg window_funcs[] = {
* @tfield[opt=false] boolean showspaces
* @tfield[opt=false] boolean showtabs
* @tfield[opt=0] int wrapcolumn {wc}
+ * @tfield[opt=8] int tabwidth {tw}
*/
static int window_options_index(lua_State *L) {
@@ -2218,6 +2215,9 @@ static int window_options_index(lua_State *L) {
} else if (strcmp(key, "wrapcolumn") == 0 || strcmp(key, "wc") == 0) {
lua_pushunsigned(L, view_wrapcolumn_get(win->view));
return 1;
+ } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) {
+ lua_pushinteger(L, view_tabwidth_get(win->view));
+ return 1;
}
}
return index_common(L);
diff --git a/vis-operators.c b/vis-operators.c
index 6523a85..a447543 100644
--- a/vis-operators.c
+++ b/vis-operators.c
@@ -102,7 +102,7 @@ static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) {
static size_t op_shift_right(Vis *vis, Text *txt, OperatorContext *c) {
char spaces[9] = " ";
- spaces[MIN(vis->tabwidth, LENGTH(spaces) - 1)] = '\0';
+ spaces[MIN(view_tabwidth_get(vis->win->view), LENGTH(spaces) - 1)] = '\0';
const char *tab = vis->expandtab ? spaces : "\t";
size_t tablen = strlen(tab);
size_t pos = text_line_begin(txt, c->range.end), prev_pos;
@@ -127,7 +127,7 @@ static size_t op_shift_right(Vis *vis, Text *txt, OperatorContext *c) {
static size_t op_shift_left(Vis *vis, Text *txt, OperatorContext *c) {
size_t pos = text_line_begin(txt, c->range.end), prev_pos;
- size_t tabwidth = vis->tabwidth, tablen;
+ size_t tabwidth = view_tabwidth_get(vis->win->view), tablen;
size_t newpos = c->pos;
/* if range ends at the begin of a line, skip line break */
diff --git a/vis.c b/vis.c
index 739e5c6..c3899db 100644
--- a/vis.c
+++ b/vis.c
@@ -498,7 +498,6 @@ Win *window_new_file(Vis *vis, File *file, enum UiOption options) {
mark_init(&win->saved_selections);
file->refcount++;
view_options_set(win->view, view_options_get(win->view));
- view_tabwidth_set(win->view, vis->tabwidth);
if (vis->windows)
vis->windows->prev = win;
@@ -695,7 +694,6 @@ Vis *vis_new(Ui *ui, VisEvent *event) {
return NULL;
vis->exit_status = -1;
vis->ui = ui;
- vis->tabwidth = 8;
vis->expandtab = false;
vis->change_colors = true;
for (size_t i = 0; i < LENGTH(vis->registers); i++)
@@ -1651,7 +1649,7 @@ void vis_insert_tab(Vis *vis) {
return;
}
char spaces[9];
- int tabwidth = MIN(vis->tabwidth, LENGTH(spaces) - 1);
+ int tabwidth = MIN(view_tabwidth_get(vis->win->view), LENGTH(spaces) - 1);
for (Selection *s = view_selections(win->view); s; s = view_selections_next(s)) {
size_t pos = view_cursors_pos(s);
int width = text_line_width_get(win->file->text, pos);