diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-04-22 10:25:19 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-04-22 10:25:19 +0200 |
| commit | 5fd810ecfe499e10841b1d428241eb4040f83759 (patch) | |
| tree | 75e96b44334fdeb6d62b881cb94ada1af7a6b01f | |
| parent | 0f75e5fbc07047d8758ec8966f64745fe271edee (diff) | |
| download | vis-5fd810ecfe499e10841b1d428241eb4040f83759.tar.gz vis-5fd810ecfe499e10841b1d428241eb4040f83759.tar.xz | |
Better variable naming (VisText -> File)
Therefore vis->win->text->data becomes vis->win->file->text.
| -rw-r--r-- | config.def.h | 8 | ||||
| -rw-r--r-- | editor.c | 164 | ||||
| -rw-r--r-- | editor.h | 14 | ||||
| -rw-r--r-- | vis.c | 100 |
4 files changed, 143 insertions, 143 deletions
diff --git a/config.def.h b/config.def.h index bb7d86e..8d61a5a 100644 --- a/config.def.h +++ b/config.def.h @@ -460,7 +460,7 @@ static KeyBinding vis_mode_visual_line[] = { static void vis_mode_visual_line_enter(Mode *old) { Win *win = vis->win->win; - window_cursor_to(win, text_line_begin(vis->win->text->data, window_cursor_get(win))); + window_cursor_to(win, text_line_begin(vis->win->file->text, window_cursor_get(win))); if (!old->visual) { window_selection_start(vis->win->win); vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_TEXTOBJ]; @@ -564,11 +564,11 @@ static KeyBinding vis_mode_insert[] = { static void vis_mode_insert_leave(Mode *old) { /* make sure we can recover the current state after an editing operation */ - text_snapshot(vis->win->text->data); + text_snapshot(vis->win->file->text); } static void vis_mode_insert_idle(void) { - text_snapshot(vis->win->text->data); + text_snapshot(vis->win->file->text); } static void vis_mode_insert_input(const char *str, size_t len) { @@ -590,7 +590,7 @@ static KeyBinding vis_mode_replace[] = { static void vis_mode_replace_leave(Mode *old) { /* make sure we can recover the current state after an editing operation */ - text_snapshot(vis->win->text->data); + text_snapshot(vis->win->file->text); } static void vis_mode_replace_input(const char *str, size_t len) { @@ -6,18 +6,18 @@ #include "editor.h" #include "util.h" -static void vis_text_free(Editor *ed, VisText *text); -static VisText *vis_text_new(Editor *ed, const char *filename); -static EditorWin *editor_window_new_text(Editor *ed, VisText *text); +static void file_free(Editor *ed, File *file); +static File *file_new(Editor *ed, const char *filename); +static EditorWin *editor_window_new_file(Editor *ed, File *file); static void editor_window_free(EditorWin *win); static void editor_windows_invalidate(Editor *ed, size_t start, size_t end); static void editor_window_selection_changed(void *data, Filerange *sel) { - VisText *text = ((EditorWin*)data)->text; + File *file = ((EditorWin*)data)->file; if (text_range_valid(sel)) { - text->marks[MARK_SELECTION_START] = text_mark_set(text->data, sel->start); - text->marks[MARK_SELECTION_END] = text_mark_set(text->data, sel->end); + file->marks[MARK_SELECTION_START] = text_mark_set(file->text, sel->start); + file->marks[MARK_SELECTION_END] = text_mark_set(file->text, sel->end); } } @@ -26,25 +26,25 @@ void editor_windows_arrange(Editor *ed, enum UiLayout layout) { } bool editor_window_reload(EditorWin *win) { - const char *filename = text_filename_get(win->text->data); + const char *filename = text_filename_get(win->file->text); /* can't reload unsaved file */ if (!filename) return false; - VisText *text = vis_text_new(win->editor, filename); - if (!text) + File *file = file_new(win->editor, filename); + if (!file) return false; - vis_text_free(win->editor, win->text); - win->text = text; - window_reload(win->win, text->data); + file_free(win->editor, win->file); + win->file = file; + window_reload(win->win, file->text); return true; } bool editor_window_split(EditorWin *original) { - EditorWin *win = editor_window_new_text(original->editor, original->text); + EditorWin *win = editor_window_new_file(original->editor, original->file); if (!win) return false; - win->text = original->text; - win->text->refcount++; + win->file = original->file; + win->file->refcount++; window_syntax_set(win->win, window_syntax_get(original->win)); window_cursor_to(win->win, window_cursor_get(original->win)); editor_draw(win->editor); @@ -52,7 +52,7 @@ bool editor_window_split(EditorWin *original) { } void editor_window_jumplist_add(EditorWin *win, size_t pos) { - Mark mark = text_mark_set(win->text->data, pos); + Mark mark = text_mark_set(win->file->text, pos); if (mark && win->jumplist) ringbuf_add(win->jumplist, mark); } @@ -63,7 +63,7 @@ size_t editor_window_jumplist_prev(EditorWin *win) { Mark mark = ringbuf_prev(win->jumplist); if (!mark) return cur; - size_t pos = text_mark_get(win->text->data, mark); + size_t pos = text_mark_get(win->file->text, mark); if (pos != EPOS && pos != cur) return pos; } @@ -76,7 +76,7 @@ size_t editor_window_jumplist_next(EditorWin *win) { Mark mark = ringbuf_next(win->jumplist); if (!mark) return cur; - size_t pos = text_mark_get(win->text->data, mark); + size_t pos = text_mark_get(win->file->text, mark); if (pos != EPOS && pos != cur) return pos; } @@ -94,7 +94,7 @@ size_t editor_window_changelist_prev(EditorWin *win) { win->changelist.index = 0; else win->changelist.index++; - size_t newpos = text_history_get(win->text->data, win->changelist.index); + size_t newpos = text_history_get(win->file->text, win->changelist.index); if (newpos == EPOS) win->changelist.index--; else @@ -108,7 +108,7 @@ size_t editor_window_changelist_next(EditorWin *win) { win->changelist.index = 0; else if (win->changelist.index > 0) win->changelist.index--; - size_t newpos = text_history_get(win->text->data, win->changelist.index); + size_t newpos = text_history_get(win->file->text, win->changelist.index); if (newpos == EPOS) win->changelist.index++; else @@ -142,7 +142,7 @@ void editor_window_prev(Editor *ed) { static void editor_windows_invalidate(Editor *ed, size_t start, size_t end) { for (EditorWin *win = ed->windows; win; win = win->next) { - if (ed->win != win && ed->win->text == win->text) { + if (ed->win != win && ed->win->file == win->file) { Filerange view = window_viewport_get(win->win); if ((view.start <= start && start <= view.end) || (view.start <= end && end <= view.end)) @@ -229,19 +229,19 @@ static void editor_window_free(EditorWin *win) { free(win); } -static EditorWin *editor_window_new_text(Editor *ed, VisText *text) { +static EditorWin *editor_window_new_file(Editor *ed, File *file) { EditorWin *win = calloc(1, sizeof(EditorWin)); if (!win) return NULL; win->editor = ed; - win->text = text; + win->file = file; win->events = (ViewEvent) { .data = win, .selection = editor_window_selection_changed, }; win->jumplist = ringbuf_alloc(31); - win->win = window_new(text->data, &win->events); - win->ui = ed->ui->window_new(ed->ui, win->win, text->data); + win->win = window_new(file->text, &win->events); + win->ui = ed->ui->window_new(ed->ui, win->win, file->text); if (!win->jumplist || !win->win || !win->ui) { editor_window_free(win); return NULL; @@ -256,73 +256,73 @@ static EditorWin *editor_window_new_text(Editor *ed, VisText *text) { return win; } -static void vis_text_free(Editor *ed, VisText *text) { - if (!text) +static void file_free(Editor *ed, File *file) { + if (!file) return; - if (--text->refcount > 0) + if (--file->refcount > 0) return; - text_free(text->data); + text_free(file->text); - if (text->prev) - text->prev->next = text->next; - if (text->next) - text->next->prev = text->prev; - if (ed->texts == text) - ed->texts = text->next; - free(text); -} - -static VisText *vis_text_new_text(Editor *ed, Text *data) { - VisText *text = calloc(1, sizeof(*text)); - if (!text) + if (file->prev) + file->prev->next = file->next; + if (file->next) + file->next->prev = file->prev; + if (ed->files == file) + ed->files = file->next; + free(file); +} + +static File *file_new_text(Editor *ed, Text *text) { + File *file = calloc(1, sizeof(*file)); + if (!file) return NULL; - text->data = data; - text->refcount++; - if (ed->texts) - ed->texts->prev = text; - text->next = ed->texts; - ed->texts = text; - return text; + file->text = text; + file->refcount++; + if (ed->files) + ed->files->prev = file; + file->next = ed->files; + ed->files = file; + return file; } -static VisText *vis_text_new(Editor *ed, const char *filename) { +static File *file_new(Editor *ed, const char *filename) { if (filename) { /* try to detect whether the same file is already open in another window * TODO: do this based on inodes */ - for (VisText *txt = ed->texts; txt; txt = txt->next) { - const char *f = text_filename_get(txt->data); - if (f && strcmp(f, filename) == 0) { - txt->refcount++; - return txt; + for (File *file = ed->files; file; file = file->next) { + const char *name = text_filename_get(file->text); + if (name && strcmp(name, filename) == 0) { + file->refcount++; + return file; } } } - Text *data = text_load(filename); - if (!data && filename && errno == ENOENT) - data = text_load(NULL); - if (!data) + Text *text = text_load(filename); + if (!text && filename && errno == ENOENT) + text = text_load(NULL); + if (!text) return NULL; if (filename) - text_filename_set(data, filename); + text_filename_set(text, filename); - VisText *text = vis_text_new_text(ed, data); - if (!text) { - text_free(data); + File *file = file_new_text(ed, text); + if (!file) { + text_free(text); return NULL; } - return text; + return file; } bool editor_window_new(Editor *ed, const char *filename) { - VisText *text = vis_text_new(ed, filename); - if (!text) + File *file = file_new(ed, filename); + if (!file) return false; - EditorWin *win = editor_window_new_text(ed, text); + EditorWin *win = editor_window_new_file(ed, file); if (!win) { - vis_text_free(ed, text); + file_free(ed, file); return false; } @@ -341,17 +341,17 @@ bool editor_window_new(Editor *ed, const char *filename) { } bool editor_window_new_fd(Editor *ed, int fd) { - Text *data = text_load_fd(fd); - if (!data) + Text *text = text_load_fd(fd); + if (!text) return false; - VisText *text = vis_text_new_text(ed, data); - if (!text) { - vis_text_free(ed, text); + File *file = file_new_text(ed, text); + if (!file) { + file_free(ed, file); return false; } - EditorWin *win = editor_window_new_text(ed, text); + EditorWin *win = editor_window_new_file(ed, file); if (!win) { - vis_text_free(ed, text); + file_free(ed, file); return false; } return true; @@ -359,7 +359,7 @@ bool editor_window_new_fd(Editor *ed, int fd) { void editor_window_close(EditorWin *win) { Editor *ed = win->editor; - vis_text_free(ed, win->text); + file_free(ed, win->file); if (win->prev) win->prev->next = win->next; if (win->next) @@ -386,13 +386,13 @@ Editor *editor_new(Ui *ui) { ed->expandtab = false; if (!(ed->prompt = calloc(1, sizeof(EditorWin)))) goto err; - if (!(ed->prompt->text = calloc(1, sizeof(VisText)))) + if (!(ed->prompt->file = calloc(1, sizeof(File)))) goto err; - if (!(ed->prompt->text->data = text_load(NULL))) + if (!(ed->prompt->file->text = text_load(NULL))) goto err; - if (!(ed->prompt->win = window_new(ed->prompt->text->data, NULL))) + if (!(ed->prompt->win = window_new(ed->prompt->file->text, NULL))) goto err; - if (!(ed->prompt->ui = ed->ui->prompt_new(ed->ui, ed->prompt->win, ed->prompt->text->data))) + if (!(ed->prompt->ui = ed->ui->prompt_new(ed->ui, ed->prompt->win, ed->prompt->file->text))) goto err; if (!(ed->search_pattern = text_regex_new())) goto err; @@ -407,7 +407,7 @@ void editor_free(Editor *ed) { return; while (ed->windows) editor_window_close(ed->windows); - vis_text_free(ed, ed->prompt->text); + file_free(ed, ed->prompt->file); editor_window_free(ed->prompt); text_regex_free(ed->search_pattern); for (int i = 0; i < REG_LAST; i++) @@ -447,12 +447,12 @@ void editor_delete_key(Editor *ed) { } void editor_insert(Editor *ed, size_t pos, const char *c, size_t len) { - text_insert(ed->win->text->data, pos, c, len); + text_insert(ed->win->file->text, pos, c, len); editor_windows_invalidate(ed, pos, pos + len); } void editor_delete(Editor *ed, size_t pos, size_t len) { - text_delete(ed->win->text->data, pos, len); + text_delete(ed->win->file->text, pos, len); editor_windows_invalidate(ed, pos, pos + len); } @@ -16,7 +16,7 @@ typedef struct EditorWin EditorWin; #include "ring-buffer.h" #include "map.h" -typedef struct VisText VisText; +typedef struct File File; typedef union { bool b; @@ -81,7 +81,7 @@ typedef struct { size_t (*cmd)(const Arg*); /* a custom movement based on user input from vis.c */ size_t (*win)(Win*); /* a movement based on current window content from window.h */ size_t (*txt)(Text*, size_t pos); /* a movement form text-motions.h */ - size_t (*vistxt)(VisText*, size_t pos); + size_t (*file)(File*, size_t pos); enum { LINEWISE = 1 << 0, CHARWISE = 1 << 1, @@ -191,11 +191,11 @@ enum Mark { MARK_LAST, }; -struct VisText { - Text *data; +struct File { + Text *text; int refcount; Mark marks[MARK_LAST]; - VisText *next, *prev; + File *next, *prev; }; typedef struct { @@ -206,7 +206,7 @@ typedef struct { struct EditorWin { Editor *editor; /* editor instance to which this window belongs */ UiWin *ui; - VisText *text; /* underlying text management */ + File *file; /* file being displayed in this window */ Win *win; /* window for the text area */ ViewEvent events; RingBuffer *jumplist; /* LRU jump management */ @@ -216,7 +216,7 @@ struct EditorWin { struct Editor { Ui *ui; - VisText *texts; + File *files; EditorWin *windows; /* list of windows */ EditorWin *win; /* currently active window */ Syntax *syntaxes; /* NULL terminated array of syntax definitions */ @@ -143,9 +143,9 @@ static size_t search_word_backward(Text *txt, size_t pos); static size_t search_forward(Text *txt, size_t pos); static size_t search_backward(Text *txt, size_t pos); /* goto action.mark */ -static size_t mark_goto(VisText *txt, size_t pos); +static size_t mark_goto(File *txt, size_t pos); /* goto first non-blank char on line pointed by action.mark */ -static size_t mark_line_goto(VisText *txt, size_t pos); +static size_t mark_line_goto(File *txt, size_t pos); /* goto to next occurence of action.key to the right */ static size_t to(Text *txt, size_t pos); /* goto to position before next occurence of action.key to the right */ @@ -203,8 +203,8 @@ static Movement moves[] = { [MOVE_RIGHT_TO] = { .txt = to, .type = LINEWISE|INCLUSIVE }, [MOVE_LEFT_TILL] = { .txt = till_left, .type = LINEWISE }, [MOVE_RIGHT_TILL] = { .txt = till, .type = LINEWISE|INCLUSIVE }, - [MOVE_MARK] = { .vistxt = mark_goto, .type = LINEWISE|JUMP|IDEMPOTENT }, - [MOVE_MARK_LINE] = { .vistxt = mark_line_goto, .type = LINEWISE|JUMP|IDEMPOTENT }, + [MOVE_MARK] = { .file = mark_goto, .type = LINEWISE|JUMP|IDEMPOTENT }, + [MOVE_MARK_LINE] = { .file = mark_line_goto, .type = LINEWISE|JUMP|IDEMPOTENT }, [MOVE_SEARCH_WORD_FORWARD] = { .txt = search_word_forward, .type = LINEWISE|JUMP }, [MOVE_SEARCH_WORD_BACKWARD]= { .txt = search_word_backward, .type = LINEWISE|JUMP }, [MOVE_SEARCH_FORWARD] = { .txt = search_forward, .type = LINEWISE|JUMP }, @@ -431,7 +431,7 @@ static bool exec_command(char type, const char *cmdline); static void op_delete(OperatorContext *c) { size_t len = c->range.end - c->range.start; c->reg->linewise = c->linewise; - register_put(c->reg, vis->win->text->data, &c->range); + register_put(c->reg, vis->win->file->text, &c->range); editor_delete(vis, c->range.start, len); window_cursor_to(vis->win->win, c->range.start); } @@ -443,11 +443,11 @@ static void op_change(OperatorContext *c) { static void op_yank(OperatorContext *c) { c->reg->linewise = c->linewise; - register_put(c->reg, vis->win->text->data, &c->range); + register_put(c->reg, vis->win->file->text, &c->range); } static void op_put(OperatorContext *c) { - Text *txt = vis->win->text->data; + Text *txt = vis->win->file->text; size_t pos = window_cursor_get(vis->win->win); if (c->arg->i > 0) { if (c->reg->linewise) @@ -476,7 +476,7 @@ static const char *expand_tab(void) { } static void op_shift_right(OperatorContext *c) { - Text *txt = vis->win->text->data; + Text *txt = vis->win->file->text; size_t pos = text_line_begin(txt, c->range.end), prev_pos; const char *tab = expand_tab(); size_t tablen = strlen(tab); @@ -495,7 +495,7 @@ static void op_shift_right(OperatorContext *c) { } static void op_shift_left(OperatorContext *c) { - Text *txt = vis->win->text->data; + Text *txt = vis->win->file->text; size_t pos = text_line_begin(txt, c->range.end), prev_pos; size_t tabwidth = editor_tabwidth_get(vis), tablen; @@ -527,7 +527,7 @@ static void op_case_change(OperatorContext *c) { char *buf = malloc(len); if (!buf) return; - len = text_bytes_get(vis->win->text->data, c->range.start, len, buf); + len = text_bytes_get(vis->win->file->text, c->range.start, len, buf); size_t rem = len; for (char *cur = buf; rem > 0; cur++, rem--) { int ch = (unsigned char)*cur; @@ -541,14 +541,14 @@ static void op_case_change(OperatorContext *c) { } } - text_delete(vis->win->text->data, c->range.start, len); - text_insert(vis->win->text->data, c->range.start, buf, len); + text_delete(vis->win->file->text, c->range.start, len); + text_insert(vis->win->file->text, c->range.start, buf, len); editor_draw(vis); free(buf); } static void op_join(OperatorContext *c) { - Text *txt = vis->win->text->data; + Text *txt = vis->win->file->text; size_t pos = text_line_begin(txt, c->range.end), prev_pos; Filerange sel = window_selection_get(vis->win->win); /* if a selection ends at the begin of a line, skip line break */ @@ -583,13 +583,13 @@ static void op_repeat_replace(OperatorContext *c) { size_t chars = 0, len = vis->buffer_repeat.len; if (!len) return; - const char *data = vis->buffer_repeat.data; + const char *text = vis->buffer_repeat.data; for (size_t i = 0; i < len; i++) { - if (ISUTF8(data[i])) + if (ISUTF8(text[i])) chars++; } - Iterator it = text_iterator_get(vis->win->text->data, c->pos); + Iterator it = text_iterator_get(vis->win->file->text, c->pos); while (chars-- > 0) text_iterator_char_next(&it, NULL); editor_delete(vis, c->pos, it.pos - c->pos); @@ -637,15 +637,15 @@ static size_t search_backward(Text *txt, size_t pos) { static void mark_set(const Arg *arg) { size_t pos = window_cursor_get(vis->win->win); - vis->win->text->marks[arg->i] = text_mark_set(vis->win->text->data, pos); + vis->win->file->marks[arg->i] = text_mark_set(vis->win->file->text, pos); } -static size_t mark_goto(VisText *txt, size_t pos) { - return text_mark_get(txt->data, txt->marks[vis->action.mark]); +static size_t mark_goto(File *txt, size_t pos) { + return text_mark_get(txt->text, txt->marks[vis->action.mark]); } -static size_t mark_line_goto(VisText *txt, size_t pos) { - return text_line_start(txt->data, mark_goto(txt, pos)); +static size_t mark_line_goto(File *txt, size_t pos) { + return text_line_start(txt->text, mark_goto(txt, pos)); } static size_t to(Text *txt, size_t pos) { @@ -807,7 +807,7 @@ static void replace(const Arg *arg) { buffer_put(&vis->buffer_repeat, k.str, strlen(k.str)); editor_delete_key(vis); editor_insert_key(vis, k.str, strlen(k.str)); - text_snapshot(vis->win->text->data); + text_snapshot(vis->win->file->text); window_cursor_to(vis->win->win, pos); } @@ -896,10 +896,10 @@ static void selection_end(const Arg *arg) { size_t pos = window_cursor_get(vis->win->win); Filerange sel = window_selection_get(vis->win->win); if (pos == sel.start) { - pos = text_char_prev(vis->win->text->data, sel.end); + pos = text_char_prev(vis->win->file->text, sel.end); } else { pos = sel.start; - sel.start = text_char_prev(vis->win->text->data, sel.end); + sel.start = text_char_prev(vis->win->file->text, sel.end); sel.end = pos; } window_selection_set(vis->win->win, &sel); @@ -923,7 +923,7 @@ static void mark_line(const Arg *arg) { } static void undo(const Arg *arg) { - size_t pos = text_undo(vis->win->text->data); + size_t pos = text_undo(vis->win->file->text); if (pos != EPOS) { window_cursor_to(vis->win->win, pos); /* redraw all windows in case some display the same file */ @@ -932,7 +932,7 @@ static void undo(const Arg *arg) { } static void redo(const Arg *arg) { - size_t pos = text_redo(vis->win->text->data); + size_t pos = text_redo(vis->win->file->text); if (pos != EPOS) { window_cursor_to(vis->win->win, pos); /* redraw all windows in case some display the same file */ @@ -1093,10 +1093,10 @@ static void copy_indent_from_previous_line(Win *win, Text *text) { static void insert_newline(const Arg *arg) { insert(&(const Arg){ .s = - text_newlines_crnl(vis->win->text->data) ? "\r\n" : "\n" }); + text_newlines_crnl(vis->win->file->text) ? "\r\n" : "\n" }); if (vis->autoindent) - copy_indent_from_previous_line(vis->win->win, vis->win->text->data); + copy_indent_from_previous_line(vis->win->win, vis->win->file->text); } static void put(const Arg *arg) { @@ -1129,7 +1129,7 @@ static void switchmode(const Arg *arg) { /** action processing: execut the operator / movement / text object */ static void action_do(Action *a) { - Text *txt = vis->win->text->data; + Text *txt = vis->win->file->text; Win *win = vis->win->win; size_t pos = window_cursor_get(win); int count = MAX(1, a->count); @@ -1148,8 +1148,8 @@ static void action_do(Action *a) { pos = a->movement->txt(txt, pos); else if (a->movement->win) pos = a->movement->win(win); - else if (a->movement->vistxt) - pos = a->movement->vistxt(vis->win->text, pos); + else if (a->movement->file) + pos = a->movement->file(vis->win->file, pos); else pos = a->movement->cmd(&a->arg); if (pos == EPOS || a->movement->type & IDEMPOTENT) @@ -1445,9 +1445,9 @@ static bool cmd_open(Filerange *range, enum CmdOpt opt, const char *argv[]) { } static bool is_window_closeable(EditorWin *win) { - if (!text_modified(win->text->data)) + if (!text_modified(win->file->text)) return true; - return win->text->refcount > 1; + return win->file->refcount > 1; } static void info_unsaved_changes(void) { @@ -1480,7 +1480,7 @@ static bool cmd_quit(Filerange *range, enum CmdOpt opt, const char *argv[]) { } static bool cmd_xit(Filerange *range, enum CmdOpt opt, const char *argv[]) { - if (text_modified(vis->win->text->data) && !cmd_write(range, opt, argv)) { + if (text_modified(vis->win->file->text) && !cmd_write(range, opt, argv)) { if (!(opt & CMD_OPT_FORCE)) return false; } @@ -1488,14 +1488,14 @@ static bool cmd_xit(Filerange *range, enum CmdOpt opt, const char *argv[]) { } static bool cmd_bdelete(Filerange *range, enum CmdOpt opt, const char *argv[]) { - Text *txt = vis->win->text->data; + Text *txt = vis->win->file->text; if (text_modified(txt) && !(opt & CMD_OPT_FORCE)) { info_unsaved_changes(); return false; } for (EditorWin *next, *win = vis->windows; win; win = next) { next = win->next; - if (win->text->data == txt) + if (win->file->text == txt) editor_window_close(win); } if (!vis->windows) @@ -1506,7 +1506,7 @@ static bool cmd_bdelete(Filerange *range, enum CmdOpt opt, const char *argv[]) { static bool cmd_qall(Filerange *range, enum CmdOpt opt, const char *argv[]) { for (EditorWin *next, *win = vis->windows; win; win = next) { next = win->next; - if (!text_modified(vis->win->text->data) || (opt & CMD_OPT_FORCE)) + if (!text_modified(vis->win->file->text) || (opt & CMD_OPT_FORCE)) editor_window_close(win); } if (!vis->windows) @@ -1520,7 +1520,7 @@ static bool cmd_read(Filerange *range, enum CmdOpt opt, const char *argv[]) { size_t pos = window_cursor_get(vis->win->win); for (const char **file = &argv[1]; *file; file++) { int fd = open(*file, O_RDONLY); - char *data = NULL; + char *text = NULL; struct stat info; if (fd == -1) goto err; @@ -1529,17 +1529,17 @@ static bool cmd_read(Filerange *range, enum CmdOpt opt, const char *argv[]) { if (!S_ISREG(info.st_mode)) goto err; // XXX: use lseek(fd, 0, SEEK_END); instead? - data = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (data == MAP_FAILED) + text = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (text == MAP_FAILED) goto err; - text_insert(vis->win->text->data, pos, data, info.st_size); + text_insert(vis->win->file->text, pos, text, info.st_size); pos += info.st_size; err: if (fd != -1) close(fd); - if (data && data != MAP_FAILED) - munmap(data, info.st_size); + if (text && text != MAP_FAILED) + munmap(text, info.st_size); } editor_draw(vis); return true; @@ -1593,7 +1593,7 @@ static bool cmd_wq(Filerange *range, enum CmdOpt opt, const char *argv[]) { } static bool cmd_write(Filerange *range, enum CmdOpt opt, const char *argv[]) { - Text *text = vis->win->text->data; + Text *text = vis->win->file->text; if (!argv[1]) argv[1] = text_filename_get(text); if (!argv[1]) { @@ -1617,7 +1617,7 @@ static bool cmd_write(Filerange *range, enum CmdOpt opt, const char *argv[]) { static bool cmd_saveas(Filerange *range, enum CmdOpt opt, const char *argv[]) { if (cmd_write(range, opt, argv)) { - text_filename_set(vis->win->text->data, argv[1]); + text_filename_set(vis->win->file->text, argv[1]); return true; } return false; @@ -1626,8 +1626,8 @@ static bool cmd_saveas(Filerange *range, enum CmdOpt opt, const char *argv[]) { static Filepos parse_pos(char **cmd) { size_t pos = EPOS; Win *win = vis->win->win; - Text *txt = vis->win->text->data; - Mark *marks = vis->win->text->marks; + Text *txt = vis->win->file->text; + Mark *marks = vis->win->file->marks; switch (**cmd) { case '.': pos = text_line_begin(txt, window_cursor_get(win)); @@ -1682,9 +1682,9 @@ static Filepos parse_pos(char **cmd) { } static Filerange parse_range(char **cmd) { - Text *txt = vis->win->text->data; + Text *txt = vis->win->file->text; Filerange r = text_range_empty(); - Mark *marks = vis->win->text->marks; + Mark *marks = vis->win->file->marks; switch (**cmd) { case '%': r.start = 0; @@ -1740,7 +1740,7 @@ static bool exec_cmdline_command(const char *cmdline) { free(line); return false; } - range = (Filerange){ .start = 0, .end = text_size(vis->win->text->data) }; + range = (Filerange){ .start = 0, .end = text_size(vis->win->file->text) }; } /* skip leading white space */ while (*name == ' ') |
