aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--view.c17
-rw-r--r--view.h2
-rw-r--r--vis-cmds.c5
4 files changed, 24 insertions, 4 deletions
diff --git a/README.md b/README.md
index d4aa2b7..96bbec5 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/view.c b/view.c
index 875185e..06f2365 100644
--- a/view.c
+++ b/view.c
@@ -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;
@@ -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 */
@@ -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)) {
@@ -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)
diff --git a/view.h b/view.h
index 14f01d3..8460116 100644
--- a/view.h
+++ b/view.h
@@ -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
diff --git a/vis-cmds.c b/vis-cmds.c
index 401d77d..7d3e0ab 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -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 */
@@ -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) {
@@ -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;