]> git.mdlowis.com Git - projs/tide.git/commitdiff
reworked setln api
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2018 02:07:02 +0000 (22:07 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 3 Apr 2018 02:07:02 +0000 (22:07 -0400)
inc/edit.h
lib/buf.c
lib/view.c

index 313e25b64883e0c21afcd4099a7bc9c564ee711e..722fdb7e25a9fbe81178f843f83baf18d010e8d2 100644 (file)
@@ -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);
 
index 37206a0a0190b1986a1ecfd26e19eada864e31be..70aba7c85c5656ee4dc3da5bc64aab665f42af05 100644 (file)
--- 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) {
index 53c367a139456aa7a1c8e1d8a975b0ce80e94bc7..d43019ece557afe6379308f0cd65f14440213eff 100644 (file)
@@ -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;
 }