Skip to content

Commit

Permalink
vis: add :set horizon option
Browse files Browse the repository at this point in the history
Can be used to specify the number of bytes before the visible area
to consider for syntax highlighting.

Defaults to 32K for now, whereas before it was 16K.
  • Loading branch information
TieDyedDevil authored and martanne committed Apr 19, 2016
1 parent aab8b6c commit 754b1ce
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ Operators can be forced to work line wise by specifying `V`.

highlight the given column

horizon number default 32768 (32K)

how far back the lexer will look to synchronize parsing

theme name default dark-16.lua | solarized.lua (16 | 256 color)

use the given theme / color scheme for syntax highlighting
Expand Down
17 changes: 13 additions & 4 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ struct View {
lua_State *lua; /* lua state used for syntax highlighting */
int cursor_generation; /* used to filter out newly created cursors during iteration */
char *lexer_name;
size_t horizon; /* maximal number of bytes to consider for syntax highlighting
* before the visible area */
bool need_update; /* whether view has been redrawn */
bool large_file; /* optimize for displaying large files */
int colorcolumn;
Expand Down Expand Up @@ -137,11 +139,9 @@ static void view_syntax_color(View *view) {
if (lua_isnil(L, -1))
return;

/* maximal number of bytes to consider for syntax highlighting before
* the visible area */
const size_t lexer_before_max = 16384;
/* absolute position to start syntax highlighting */
const size_t lexer_start = view->start >= lexer_before_max ? view->start - lexer_before_max : 0;
const size_t lexer_start = view->start >= view->horizon ?
view->start - view->horizon : 0;
/* number of bytes used for syntax highlighting before visible are */
size_t lexer_before = view->start - lexer_start;
/* number of bytes to read in one go */
Expand Down Expand Up @@ -753,6 +753,7 @@ View *view_new(Text *text, lua_State *lua) {
view->text = text;
view->lua = lua;
view->tabwidth = 8;
view->horizon = 1 << 15;
view_options_set(view, 0);

if (!view_resize(view, 1, 1)) {
Expand Down Expand Up @@ -1052,6 +1053,14 @@ int view_colorcolumn_get(View *view) {
return view->colorcolumn;
}

void view_horizon_set(View *view, size_t bytes) {
view->horizon = bytes;
}

size_t view_horizon_get(View *view) {
return view->horizon;
}

size_t view_screenline_goto(View *view, int n) {
size_t pos = view->start;
for (Line *line = view->topline; --n > 0 && line != view->lastline; line = line->next)
Expand Down
2 changes: 2 additions & 0 deletions view.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ void view_options_set(View*, enum UiOption options);
enum UiOption view_options_get(View*);
void view_colorcolumn_set(View*, int col);
int view_colorcolumn_get(View*);
void view_horizon_set(View*, size_t bytes);
size_t view_horizon_get(View*);

/* A view can manage multiple cursors, one of which (the main cursor) is always
* placed within the visible viewport. All functions named view_cursor_* operate
Expand Down
5 changes: 5 additions & 0 deletions vis-cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor
OPTION_CURSOR_LINE,
OPTION_THEME,
OPTION_COLOR_COLUMN,
OPTION_HORIZON,
};

/* definitions have to be in the same order as the enum above */
Expand All @@ -73,6 +74,7 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor
[OPTION_CURSOR_LINE] = { { "cursorline", "cul" }, OPTION_TYPE_BOOL },
[OPTION_THEME] = { { "theme" }, OPTION_TYPE_STRING },
[OPTION_COLOR_COLUMN] = { { "colorcolumn", "cc" }, OPTION_TYPE_NUMBER },
[OPTION_HORIZON] = { { "horizon" }, OPTION_TYPE_UNSIGNED },
};

if (!vis->options) {
Expand Down Expand Up @@ -242,6 +244,9 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor
case OPTION_COLOR_COLUMN:
view_colorcolumn_set(win->view, arg.i);
break;
case OPTION_HORIZON:
view_horizon_set(win->view, arg.u);
break;
}

return true;
Expand Down

0 comments on commit 754b1ce

Please sign in to comment.