]> git.mdlowis.com Git - projs/tide.git/commitdiff
added logic to open files at a given line number
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 3 Dec 2016 01:09:48 +0000 (20:09 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 3 Dec 2016 01:09:48 +0000 (20:09 -0500)
TODO.md
inc/edit.h
libedit/buf.c
libedit/view.c

diff --git a/TODO.md b/TODO.md
index d05a861247b423c4fa9b6eaf5d1143a71f9aa65a..c15d465b2d22f20b8dca86e6c0f990f59900a4c5 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,4 @@
 # Implementation Tweaks and Bug Fixes
-
 * Use select to check for error strings in exec.c
 * Should not be able to undo initial tag line text insertion
 * Disallow scrolling past end of buffer
index 5657d5afd46e96553ace46c6aaa3ec289add741e..d7b659766452e983b442e797d1dd75075edff515 100644 (file)
@@ -55,7 +55,7 @@ typedef struct {
     size_t col;
 } Sel;
 
-void buf_load(Buf* buf, char* path);
+unsigned buf_load(Buf* buf, char* path);
 void buf_save(Buf* buf);
 void buf_init(Buf* buf);
 unsigned buf_ins(Buf* buf, bool indent, unsigned off, Rune rune);
index d0e38c070ddaa0be9167badd23ea24281782287a..528928123617203d9e05fb26f2efcaec5fdaae97 100644 (file)
@@ -3,15 +3,18 @@
 #include <edit.h>
 #include <ctype.h>
 
-void buf_load(Buf* buf, char* path) {
-    if (!strcmp(path,"-")) {
+unsigned buf_load(Buf* buf, char* path) {
+    unsigned off = 0;
+    buf->path = stringdup(path);
+    char* addr = strrchr(buf->path, ':');
+    if (addr) *addr = '\0', addr++;
+    if (!strcmp(buf->path,"-")) {
         buf->charset = UTF_8;
         Rune r;
         while (RUNE_EOF != (r = fgetrune(stdin)))
             buf_ins(buf, false, buf_end(buf), r);
     } else {
-        FMap file = fmap(path);
-        buf->path = stringdup(path);
+        FMap file = fmap(buf->path);
         buf->charset = (file.buf ? charset(file.buf, file.len, &buf->crlf) : UTF_8);
         /* load the file contents if it has any */
         if (buf->charset > UTF_8) {
@@ -22,10 +25,13 @@ void buf_load(Buf* buf, char* path) {
             utf8load(buf, file);
         }
         funmap(file);
+        if (addr)
+            off = buf_setln(buf, strtoul(addr, NULL, 0));
     }
     buf->modified = false;
     free(buf->undo);
     buf->undo = NULL;
+    return off;
 }
 
 void buf_save(Buf* buf) {
@@ -235,7 +241,7 @@ unsigned buf_redo(Buf* buf, unsigned pos) {
 
 unsigned buf_setln(Buf* buf, unsigned line) {
     unsigned off = 0;
-    while (line > 0 && off < buf_end(buf))
+    while (line > 1 && off < buf_end(buf))
         line--, off = buf_byline(buf, off, DOWN);
     return off;
 }
index 1f45d4399830d2451d7b6bed059f5085a76f747e..b3e918d3f883bd70933c88acb5a68449f8e222e3 100644 (file)
@@ -153,8 +153,10 @@ static size_t getoffset(View* view, size_t row, size_t col) {
 void view_init(View* view, char* file) {
     memset(view, 0, sizeof(View));
     buf_init(&(view->buffer));
-    if (file)
-        buf_load(&(view->buffer), file);
+    if (file) {
+        view->selection.end = buf_load(&(view->buffer), file);
+        view->selection.beg = view->selection.end;
+    }
 }
 
 size_t view_limitrows(View* view, size_t maxrows, size_t ncols) {