diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-05-21 12:29:59 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-05-22 00:05:30 +0200 |
| commit | 29f8d2488cfe86678e65e73c58e36d7c48a0e11b (patch) | |
| tree | bc58ec4a206c1a5d393a67837acb5ea1cce02193 | |
| parent | b36ddb65334b4de406304786abfbde85b1e9a4e4 (diff) | |
| download | vis-29f8d2488cfe86678e65e73c58e36d7c48a0e11b.tar.gz vis-29f8d2488cfe86678e65e73c58e36d7c48a0e11b.tar.xz | |
vis: consider :set horizon setting when syntax highlighting
| -rw-r--r-- | view.c | 11 | ||||
| -rw-r--r-- | view.h | 2 | ||||
| -rw-r--r-- | vis-cmds.c | 2 | ||||
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis-lua.c | 7 | ||||
| -rw-r--r-- | vis-lua.h | 2 | ||||
| -rw-r--r-- | vis.c | 3 | ||||
| -rw-r--r-- | vis.h | 2 | ||||
| -rw-r--r-- | vis.lua | 3 |
9 files changed, 11 insertions, 22 deletions
@@ -88,8 +88,6 @@ struct View { Cursor *cursors; /* all cursors currently active */ Selection *selections; /* all selected regions */ int cursor_generation; /* used to filter out newly created cursors during iteration */ - 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; @@ -568,7 +566,6 @@ View *view_new(Text *text, ViewEvent *events) { view->text = text; view->tabwidth = 8; - view->horizon = 1 << 15; view_options_set(view, 0); if (!view_resize(view, 1, 1)) { @@ -865,14 +862,6 @@ 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) @@ -95,8 +95,6 @@ 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 @@ -291,7 +291,7 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor view_colorcolumn_set(win->view, arg.i); break; case OPTION_HORIZON: - view_horizon_set(win->view, arg.u); + win->horizon = arg.u; break; } @@ -135,6 +135,7 @@ struct Win { Mode *parent_mode; /* mode which was active when showing the command prompt */ ViewEvent event; /* callbacks from view.[ch] */ char *lexer_name; /* corresponds to filename in lexers/ subdirectory */ + size_t horizon; /* max bytes to consider for syntax coloring before viewport */ Win *prev, *next; /* neighbouring windows */ }; @@ -28,7 +28,7 @@ void vis_lua_file_save(Vis *vis, File *file) { } void vis_lua_file_close(Vis *vis, File *file) { } void vis_lua_win_open(Vis *vis, Win *win) { } void vis_lua_win_close(Vis *vis, Win *win) { } -void vis_lua_win_highlight(Vis *vis, Win *win) { } +void vis_lua_win_highlight(Vis *vis, Win *win, size_t horizon) { } bool vis_lua_win_syntax(Vis *vis, Win *win, const char *syntax) { return true; } bool vis_theme_load(Vis *vis, const char *name) { return true; } @@ -1276,12 +1276,13 @@ void vis_lua_win_close(Vis *vis, Win *win) { lua_pop(L, 1); } -void vis_lua_win_highlight(Vis *vis, Win *win) { +void vis_lua_win_highlight(Vis *vis, Win *win, size_t horizon) { lua_State *L = vis->lua; vis_lua_event_get(L, "win_highlight"); if (lua_isfunction(L, -1)) { obj_ref_new(L, win, "vis.window"); - pcall(vis, L, 1, 0); + lua_pushunsigned(L, horizon); + pcall(vis, L, 2, 0); } lua_pop(L, 1); } @@ -25,7 +25,7 @@ void vis_lua_file_save(Vis*, File*); void vis_lua_file_close(Vis*, File*); void vis_lua_win_open(Vis*, Win*); void vis_lua_win_close(Vis*, Win*); -void vis_lua_win_highlight(Vis*, Win*); +void vis_lua_win_highlight(Vis*, Win*, size_t horizon); bool vis_lua_win_syntax(Vis*, Win*, const char *syntax); #endif @@ -157,7 +157,7 @@ static void window_highlight(void *ctx) { Win *win = ctx; Vis *vis = win->vis; if (!win->file->internal && vis->event && vis->event->win_highlight) - vis->event->win_highlight(vis, win); + vis->event->win_highlight(vis, win, win->horizon); } Win *window_new_file(Vis *vis, File *file) { @@ -168,6 +168,7 @@ Win *window_new_file(Vis *vis, File *file) { win->file = file; win->jumplist = ringbuf_alloc(31); win->event.data = win; + win->horizon = 1 << 15; win->view = view_new(file->text, &win->event); win->ui = vis->ui->window_new(vis->ui, win->view, file, UI_OPTION_STATUSBAR); if (!win->jumplist || !win->view || !win->ui) { @@ -33,7 +33,7 @@ typedef struct { void (*file_close)(Vis*, File*); void (*win_open)(Vis*, Win*); void (*win_close)(Vis*, Win*); - void (*win_highlight)(Vis*, Win*); + void (*win_highlight)(Vis*, Win*, size_t horizon); bool (*win_syntax)(Vis*, Win*, const char *syntax); } VisEvent; @@ -250,7 +250,7 @@ vis.events.win_syntax = function(win, name) return true end -vis.events.win_highlight = function(win) +vis.events.win_highlight = function(win, horizon_max) if win.syntax == nil or vis.lexers == nil then return end @@ -261,7 +261,6 @@ vis.events.win_highlight = function(win) -- TODO: improve heuristic for initial style local viewport = win.viewport - local horizon_max = 32768 local horizon = viewport.start < horizon_max and viewport.start or horizon_max local view_start = viewport.start local lex_start = viewport.start - horizon |
