vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit eb7024cfc396fd31a93d5ab33fa427224f667c26 parent 0a1be1d2d58faed4e2b4ac6ace3e6e339b5c5e64 Author: Marc André Tanner <mat@brain-dump.org> Date: Mon, 2 May 2016 16:46:22 +0200 vis: enable large file optimizations for files with long lines Diffstat:
| M | ui-curses.c | | | 14 | +++++++++++--- |
| M | ui.h | | | 5 | +++++ |
| M | vis.c | | | 19 | ------------------- |
| M | vis.h | | | 2 | -- |
4 files changed, 16 insertions(+), 24 deletions(-)
diff --git a/ui-curses.c b/ui-curses.c @@ -19,6 +19,7 @@ #include "ui-curses.h" #include "vis.h" +#include "vis-core.h" #include "text.h" #include "util.h" #include "text-util.h" @@ -638,14 +639,14 @@ static void ui_window_draw_status(UiWin *w) { UiCurses *uic = win->ui; Vis *vis = uic->vis; bool focused = uic->selwin == win; - const char *filename = vis_file_name(win->file); + const char *filename = win->file->name; const char *status = vis_mode_status(vis); wattrset(win->winstatus, focused ? A_REVERSE|A_BOLD : A_REVERSE); mvwhline(win->winstatus, 0, 0, ' ', win->width); mvwprintw(win->winstatus, 0, 0, "%s %s %s %s", focused && status ? status : "", filename ? filename : "[No Name]", - text_modified(vis_file_text(win->file)) ? "[+]" : "", + text_modified(win->file->text) ? "[+]" : "", vis_macro_recording(vis) ? "recording": ""); char buf[4*32] = "", *msg = buf; @@ -660,6 +661,8 @@ static void ui_window_draw_status(UiWin *w) { Cursor *cur = view_cursors_primary_get(win->view); size_t line = view_cursors_line(cur); size_t col = view_cursors_col(cur); + if (col > UI_LARGE_FILE_LINE_SIZE) + win->options |= UI_OPTION_LARGE_FILE; msg += sprintf(msg, "%zu, %zu", line, col); } @@ -740,7 +743,7 @@ static void ui_window_reload(UiWin *w, File *file) { UiCursesWin *win = (UiCursesWin*)w; win->file = file; win->sidebar_width = 0; - view_reload(win->view, vis_file_text(file)); + view_reload(win->view, file->text); ui_window_draw(w); } @@ -1008,6 +1011,11 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file, enum UiOption option win->next = uic->windows; uic->windows = win; + if (text_size(file->text) > UI_LARGE_FILE_SIZE) { + options |= UI_OPTION_LARGE_FILE; + options &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; + } + ui_window_options_set((UiWin*)win, options); return &win->uiwin; diff --git a/ui.h b/ui.h @@ -4,6 +4,11 @@ #include <stdbool.h> #include <stdarg.h> +/* enable large file optimization for files larger than: */ +#define UI_LARGE_FILE_SIZE (1 << 25) +/* enable large file optimization fo files containing lines longer than: */ +#define UI_LARGE_FILE_LINE_SIZE (1 << 16) + typedef struct Ui Ui; typedef struct UiWin UiWin; diff --git a/vis.c b/vis.c @@ -28,9 +28,6 @@ #include "vis-core.h" #include "sam.h" -/* enable large file optimization for files larger than: */ -#define LARGE_FILE (1 << 25) - static Macro *macro_get(Vis *vis, enum VisRegister); static void macro_replay(Vis *vis, const Macro *macro); static void vis_keys_process(Vis *vis); @@ -170,13 +167,6 @@ Win *window_new_file(Vis *vis, File *file) { file->refcount++; view_tabwidth_set(win->view, vis->tabwidth); - if (text_size(file->text) > LARGE_FILE) { - enum UiOption opt = view_options_get(win->view); - opt |= UI_OPTION_LARGE_FILE; - opt &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; - view_options_set(win->view, opt); - } - if (vis->windows) vis->windows->prev = win; win->next = vis->windows; @@ -1373,12 +1363,3 @@ View *vis_view(Vis *vis) { Win *vis_window(Vis *vis) { return vis->win; } - -Text *vis_file_text(File *file) { - return file->text; -} - -const char *vis_file_name(File *file) { - return file->name; -} - diff --git a/vis.h b/vis.h @@ -446,8 +446,6 @@ Regex *vis_regex(Vis*, const char *pattern); Text *vis_text(Vis*); View *vis_view(Vis*); Win *vis_window(Vis*); -Text *vis_file_text(File*); -const char *vis_file_name(File*); bool vis_theme_load(Vis*, const char *name);