From 754b1cec7a39723b415ee76e797e587a7b5054dc Mon Sep 17 00:00:00 2001 From: "David B. Lamkins" Date: Tue, 19 Apr 2016 22:51:29 +0200 Subject: vis: add :set horizon option 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. --- view.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'view.c') 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) -- cgit v1.2.3