Win *window_new_file(Vis *vis, File *file) { Win *win = calloc(1, sizeof(Win)); if (!win) return NULL; win->vis = vis; win->file = file; win->jumplist = ringbuf_alloc(31); win->view = view_new(file->text, vis->lua); win->ui = vis->ui->window_new(vis->ui, win->view, file, UI_OPTION_STATUSBAR); if (!win->jumplist || !win->view || !win->ui) { window_free(win); return NULL; } 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; vis->windows = win; vis->win = win; vis->ui->window_focus(win->ui); for (size_t i = 0; i < LENGTH(win->modes); i++) win->modes[i].parent = &vis_modes[i]; if (vis->event && vis->event->win_open) vis->event->win_open(vis, win); return win; }
bool vis_window_split(Win *original) { Win *win = window_new_file(original->vis, original->file, UI_OPTION_STATUSBAR); if (!win) return false; for (size_t i = 0; i < LENGTH(win->modes); i++) { if (original->modes[i].bindings) win->modes[i].bindings = map_new(); if (win->modes[i].bindings) map_copy(win->modes[i].bindings, original->modes[i].bindings); } win->file = original->file; win->file->refcount++; vis_window_syntax_set(win, vis_window_syntax_get(original)); view_options_set(win->view, view_options_get(original->view)); view_cursor_to(win->view, view_cursor_get(original->view)); return true; }