From: Michael D. Lowis Date: Tue, 3 Apr 2018 02:07:02 +0000 (-0400) Subject: reworked setln api X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d587c8d515b9c68f6b31b4fa71e80ae34c5d820f;p=projs%2Ftide.git reworked setln api --- diff --git a/inc/edit.h b/inc/edit.h index 313e25b..722fdb7 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -50,7 +50,7 @@ typedef struct { } 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); @@ -82,8 +82,7 @@ size_t buf_byword(Buf* buf, size_t pos, int count); 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); diff --git a/lib/buf.c b/lib/buf.c index 37206a0..70aba7c 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -38,14 +38,11 @@ void buf_init(Buf* buf) { 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; @@ -64,15 +61,10 @@ size_t buf_load(Buf* buf, char* path) { } 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) { @@ -410,24 +402,14 @@ void buf_findstr(Buf* buf, int dir, char* str, size_t* beg, size_t* end) { 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) { diff --git a/lib/view.c b/lib/view.c index 53c367a..d43019e 100644 --- a/lib/view.c +++ b/lib/view.c @@ -35,14 +35,7 @@ void view_init(View* view, char* file) { 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) { @@ -222,7 +215,7 @@ void view_eof(View* view, bool extsel) { } 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; }