} Buf;
void buf_init(Buf* buf);
-size_t buf_load(Buf* buf, char* path);
+void buf_load(Buf* buf, char* path);
void buf_reload(Buf* buf);
void buf_save(Buf* buf);
size_t buf_end(Buf* buf);
size_t buf_byline(Buf* buf, size_t pos, int count);
void buf_findstr(Buf* buf, int dir, char* str, size_t* beg, size_t* end);
-size_t buf_setln(Buf* buf, size_t line);
-size_t buf_getln(Buf* buf, size_t off);
+void buf_setln(Buf* buf, Sel* sel, size_t line);
void buf_getcol(Buf* buf, Sel* p_sel);
void buf_setcol(Buf* buf, Sel* p_sel);
assert(buf->bufstart);
}
-size_t buf_load(Buf* buf, char* path) {
+void buf_load(Buf* buf, char* path) {
/* process the file path and address */
if (path && path[0] == '.' && path[1] == '/')
path += 2;
- size_t off = 0;
buf->path = stringdup(path);
- char* addr = strrchr(buf->path, ':');
- if (addr) *addr = '\0', addr++;
/* load the contents from the file */
int fd, nread;
}
if (fd > 0) close(fd);
- /* jump to address if we got one */
- if (addr)
- off = buf_setln(buf, strtoul(addr, NULL, 0));
-
/* reset buffer state */
buf->modified = false;
buf->modtime = modtime(buf->path);
buf_logclear(buf);
- return off;
}
void buf_reload(Buf* buf) {
free(runes);
}
-size_t buf_setln(Buf* buf, size_t line) {
+void buf_setln(Buf* buf, Sel* sel, size_t line) {
size_t curr = 0, end = buf_end(buf);
while (line > 1 && curr < end) {
size_t next = buf_byline(buf, curr, DOWN);
if (curr == next) break;
line--, curr = next;
}
- return curr;
-}
-
-size_t buf_getln(Buf* buf, size_t off) {
- size_t line = 1, curr = 0, end = buf_end(buf);
- while (curr < off && curr < end-1) {
- size_t next = buf_byline(buf, curr, DOWN);
- if (curr == next) break;
- line++, curr = next;
- }
- return line;
+ sel->beg = sel->end = curr;
}
void buf_getcol(Buf* buf, Sel* sel) {
view->sync_center = true;
/* load the file and jump to the address returned from the load function */
buf_init(&(view->buffer));
- if (file) {
- size_t pos = buf_load(&(view->buffer), file);
- if (pos > 0) {
- view_jumpto(view, false, pos);
- view_eol(view, false);
- view_selctx(view);
- }
- }
+ if (file) buf_load(&(view->buffer), file);
}
void view_reload(View* view) {
}
void view_setln(View* view, size_t line) {
- view_jumpto(view, false, buf_setln(&(view->buffer), line));
+ buf_setln(&(view->buffer), &(view->selection), line);
view->sync_center = true;
}