vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 6a7149346a9e7cfe7d2cfe045897f0a9b65f8453 parent b3d0887380ac89d23dc890e6732967e4846390a3 Author: Marc André Tanner <mat@brain-dump.org> Date: Sat, 21 May 2016 12:29:59 +0200 vis: consider :set horizon setting when syntax highlighting Diffstat:
| M | view.c | | | 11 | ----------- |
| M | view.h | | | 2 | -- |
| M | vis-cmds.c | | | 2 | +- |
| M | vis-core.h | | | 1 | + |
| M | vis-lua.c | | | 7 | ++++--- |
| M | vis-lua.h | | | 2 | +- |
| M | vis.c | | | 3 | ++- |
| M | vis.h | | | 2 | +- |
| M | vis.lua | | | 3 | +-- |
9 files changed, 11 insertions(+), 22 deletions(-)
diff --git a/view.c b/view.c @@ -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) diff --git a/view.h b/view.h @@ -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 diff --git a/vis-cmds.c b/vis-cmds.c @@ -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; } diff --git a/vis-core.h b/vis-core.h @@ -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 */ }; diff --git a/vis-lua.c b/vis-lua.c @@ -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); } diff --git a/vis-lua.h b/vis-lua.h @@ -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 diff --git a/vis.c b/vis.c @@ -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) { diff --git a/vis.h b/vis.h @@ -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; diff --git a/vis.lua b/vis.lua @@ -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