aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-05-21 12:29:59 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-05-22 00:05:30 +0200
commit29f8d2488cfe86678e65e73c58e36d7c48a0e11b (patch)
treebc58ec4a206c1a5d393a67837acb5ea1cce02193
parentb36ddb65334b4de406304786abfbde85b1e9a4e4 (diff)
downloadvis-29f8d2488cfe86678e65e73c58e36d7c48a0e11b.tar.gz
vis-29f8d2488cfe86678e65e73c58e36d7c48a0e11b.tar.xz
vis: consider :set horizon setting when syntax highlighting
-rw-r--r--view.c11
-rw-r--r--view.h2
-rw-r--r--vis-cmds.c2
-rw-r--r--vis-core.h1
-rw-r--r--vis-lua.c7
-rw-r--r--vis-lua.h2
-rw-r--r--vis.c3
-rw-r--r--vis.h2
-rw-r--r--vis.lua3
9 files changed, 11 insertions, 22 deletions
diff --git a/view.c b/view.c
index ec06b9e..e67dc42 100644
--- 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
index ac036fb..2e58593 100644
--- 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
index 4c68d28..da20369 100644
--- 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
index 6d463df..74de5a1 100644
--- 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
index c239f63..ad017b1 100644
--- 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
index 7a37402..8811f55 100644
--- 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
index f23deba..9e05a6b 100644
--- 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
index 5e80ce8..132cc18 100644
--- 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
index 59d0590..297c09e 100644
--- 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