From f295bba61f97ff0d3d43fcc156b78856f715ffad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 19 Mar 2017 12:29:13 +0100 Subject: Move :set horizon option implementaiton to lua --- lua/vis-std.lua | 9 ++++++++- sam.c | 6 ------ vis-cmds.c | 3 --- vis-core.h | 1 - vis-lua.c | 8 +++----- vis-lua.h | 2 +- vis.c | 3 +-- vis.h | 2 +- 8 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lua/vis-std.lua b/lua/vis-std.lua index 86f8f46..f7dc4f5 100644 --- a/lua/vis-std.lua +++ b/lua/vis-std.lua @@ -31,7 +31,13 @@ vis:option_register("syntax", "string", function(name) return true end, "Syntax highlighting lexer to use") -vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win, horizon_max) +vis:option_register("horizon", "number", function(horizon) + if not vis.win then return false end + vis.win.horizon = horizon + return true +end, "Number of bytes to consider for syntax highlighting") + +vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win) if win.syntax == nil or vis.lexers == nil then return end local lexer = vis.lexers.load(win.syntax) if lexer == nil then return end @@ -39,6 +45,7 @@ vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win, horizon_max) -- TODO: improve heuristic for initial style local viewport = win.viewport if not viewport then return end + local horizon_max = win.horizon or 32768 local horizon = viewport.start < horizon_max and viewport.start or horizon_max local view_start = viewport.start local lex_start = viewport.start - horizon diff --git a/sam.c b/sam.c index db82845..105d7b2 100644 --- a/sam.c +++ b/sam.c @@ -287,7 +287,6 @@ enum { OPTION_NUMBER_RELATIVE, OPTION_CURSOR_LINE, OPTION_COLOR_COLUMN, - OPTION_HORIZON, OPTION_SAVE_METHOD, OPTION_CHANGE_256COLORS, }; @@ -353,11 +352,6 @@ static const OptionDef options[] = { VIS_OPTION_TYPE_NUMBER|VIS_OPTION_NEED_WINDOW, VIS_HELP("Highlight a fixed column") }, - [OPTION_HORIZON] = { - { "horizon" }, - VIS_OPTION_TYPE_NUMBER|VIS_OPTION_NEED_WINDOW, - VIS_HELP("Number of bytes to consider for syntax highlighting") - }, [OPTION_SAVE_METHOD] = { { "savemethod" }, VIS_OPTION_TYPE_STRING|VIS_OPTION_NEED_WINDOW, diff --git a/vis-cmds.c b/vis-cmds.c index 6c54fe2..3ee782d 100644 --- a/vis-cmds.c +++ b/vis-cmds.c @@ -313,9 +313,6 @@ 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: - win->horizon = arg.i; - break; case OPTION_SAVE_METHOD: if (strcmp("auto", arg.s) == 0) { win->file->save_method = TEXT_SAVE_AUTO; diff --git a/vis-core.h b/vis-core.h index 386928e..f182e2a 100644 --- a/vis-core.h +++ b/vis-core.h @@ -148,7 +148,6 @@ struct Win { Win *parent; /* window which was active when showing the command prompt */ Mode *parent_mode; /* mode which was active when showing the command prompt */ 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 index 66a2677..e76693c 100644 --- a/vis-lua.c +++ b/vis-lua.c @@ -159,7 +159,7 @@ void vis_lua_file_save_post(Vis *vis, File *file, const char *path) { } 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, size_t horizon) { } +void vis_lua_win_highlight(Vis *vis, Win *win) { } void vis_lua_win_status(Vis *vis, Win *win) { window_status_update(vis, win); } #else @@ -2713,16 +2713,14 @@ void vis_lua_win_close(Vis *vis, Win *win) { * The window has been redrawn and the syntax highlighting needs to be performed. * @function win_highlight * @tparam Window win the window being redrawn - * @tparam int horizon the maximal number of bytes the lexer should look behind to synchronize parsing state * @see style */ -void vis_lua_win_highlight(Vis *vis, Win *win, size_t horizon) { +void vis_lua_win_highlight(Vis *vis, Win *win) { lua_State *L = vis->lua; vis_lua_event_get(L, "win_highlight"); if (lua_isfunction(L, -1)) { obj_ref_new(L, win, VIS_LUA_TYPE_WINDOW); - lua_pushunsigned(L, horizon); - pcall(vis, L, 2, 0); + pcall(vis, L, 1, 0); } lua_pop(L, 1); } diff --git a/vis-lua.h b/vis-lua.h index 4aba4a4..54dbd62 100644 --- a/vis-lua.h +++ b/vis-lua.h @@ -35,7 +35,7 @@ void vis_lua_file_save_post(Vis*, File*, const char *path); 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*, size_t horizon); +void vis_lua_win_highlight(Vis*, Win*); bool vis_lua_win_syntax(Vis*, Win*, const char *syntax); void vis_lua_win_status(Vis*, Win*); diff --git a/vis.c b/vis.c index 83e1431..4c93872 100644 --- a/vis.c +++ b/vis.c @@ -115,7 +115,7 @@ bool vis_event_emit(Vis *vis, enum VisEvents id, ...) { } else if (vis->event->win_close && id == VIS_EVENT_WIN_CLOSE) { vis->event->win_close(vis, win); } else if (vis->event->win_highlight && id == VIS_EVENT_WIN_HIGHLIGHT) { - vis->event->win_highlight(vis, win, win->horizon); + vis->event->win_highlight(vis, win); } else if (vis->event->win_status && id == VIS_EVENT_WIN_STATUS) { vis->event->win_status(vis, win); } @@ -480,7 +480,6 @@ Win *window_new_file(Vis *vis, File *file, enum UiOption options) { win->vis = vis; win->file = file; win->jumplist = ringbuf_alloc(31); - win->horizon = 1 << 15; win->view = view_new(file->text); win->ui = vis->ui->window_new(vis->ui, win, options); if (!win->jumplist || !win->view || !win->ui) { diff --git a/vis.h b/vis.h index 2b4fcf2..913a503 100644 --- a/vis.h +++ b/vis.h @@ -51,7 +51,7 @@ typedef struct { void (*file_close)(Vis*, File*); void (*win_open)(Vis*, Win*); void (*win_close)(Vis*, Win*); - void (*win_highlight)(Vis*, Win*, size_t horizon); + void (*win_highlight)(Vis*, Win*); void (*win_status)(Vis*, Win*); } VisEvent; -- cgit v1.2.3