]> git.mdlowis.com Git - projs/tide.git/commitdiff
Implemented copyindent and fixed right-click find bug. Also fixed a path issue in...
authorMichael D. Lowis <mike.lowis@gentex.com>
Fri, 2 Dec 2016 17:10:33 +0000 (12:10 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Fri, 2 Dec 2016 17:10:33 +0000 (12:10 -0500)
TODO.md
inc/edit.h
libedit/buf.c
libedit/charset.c
libedit/utf8.c
libedit/view.c
xfilepick
xpick.c

diff --git a/TODO.md b/TODO.md
index 89d3c46aae61f3976b946c8c61a3659bdfc1bb8d..0f82b2372ebff5c479927088741e646f34ffa3d2 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -1,6 +1,6 @@
 # Implementation Tweaks and Bug Fixes
 
-* Auto indent mode
+* 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
 * track down double click bug for selecting whole line
index d71a61d72b491c516eaed26ef85da81a53c19d2d..7177c6239d3581457e26c0f883b5f3231891d2f8 100644 (file)
@@ -37,7 +37,6 @@ typedef struct buf {
     char* path;       /* the path to the open file */
     int charset;      /* the character set of the buffer */
     int crlf;         /* tracks whether the file uses dos style line endings */
-    bool modified;    /* tracks whether the buffer has been modified */
     size_t bufsize;   /* size of the buffer in runes */
     Rune* bufstart;   /* start of the data buffer */
     Rune* bufend;     /* end of the data buffer */
@@ -45,7 +44,9 @@ typedef struct buf {
     Rune* gapend;     /* end of the gap */
     Log* undo;        /* undo list */
     Log* redo;        /* redo list */
+    bool modified;    /* tracks whether the buffer has been modified */
     bool expand_tabs; /* tracks current mode */
+    bool copy_indent; /* copy the indent level from the previous line on new lines */
 } Buf;
 
 typedef struct {
@@ -57,7 +58,7 @@ typedef struct {
 void buf_load(Buf* buf, char* path);
 void buf_save(Buf* buf);
 void buf_init(Buf* buf);
-unsigned buf_ins(Buf* buf, unsigned pos, Rune);
+unsigned buf_ins(Buf* buf, bool indent, unsigned off, Rune rune);
 void buf_del(Buf* buf, unsigned pos);
 unsigned buf_undo(Buf* buf, unsigned pos);
 unsigned buf_redo(Buf* buf, unsigned pos);
index e4179cb7808357afac0e7bec4648768bf7cbcf2d..3a8573ce025cae5ce9f3443cf90422a3242f36b4 100644 (file)
@@ -1,13 +1,14 @@
 #include <stdc.h>
 #include <utf.h>
 #include <edit.h>
+#include <ctype.h>
 
 void buf_load(Buf* buf, char* path) {
     if (!strcmp(path,"-")) {
         buf->charset = UTF_8;
         Rune r;
         while (RUNE_EOF != (r = fgetrune(stdin)))
-            buf_ins(buf, buf_end(buf), r);
+            buf_ins(buf, false, buf_end(buf), r);
     } else {
         FMap file = fmap(path);
         buf->path = stringdup(path);
@@ -76,6 +77,7 @@ static void syncgap(Buf* buf, unsigned off) {
 void buf_init(Buf* buf) {
     buf->modified    = false;
     buf->expand_tabs = true;
+    buf->copy_indent = true;
     buf->charset     = DEFAULT_CHARSET;
     buf->crlf        = DEFAULT_CRLF;
     buf->bufsize     = BufSize;
@@ -152,7 +154,13 @@ static void clear_redo(Buf* buf) {
     buf->redo = NULL;
 }
 
-unsigned buf_ins(Buf* buf, unsigned off, Rune rune) {
+static unsigned getindent(Buf* buf, unsigned off) {
+    off = buf_bol(buf, off);
+    for (; off < buf_end(buf) && isspace(buf_get(buf, off)); off++);
+    return buf_getcol(buf, off) / TabWidth;
+}
+
+unsigned buf_ins(Buf* buf, bool indent, unsigned off, Rune rune) {
     buf->modified = true;
     if (buf->expand_tabs && rune == '\t') {
         size_t n = (TabWidth - ((off - buf_bol(buf, off)) % TabWidth));
@@ -162,6 +170,11 @@ unsigned buf_ins(Buf* buf, unsigned off, Rune rune) {
         log_insert(&(buf->undo), off, off+1);
         insert(buf, off++, rune);
     }
+    if (indent && buf->copy_indent && (rune == '\n' || rune == RUNE_CRLF)) {
+        unsigned indent = getindent(buf, off-1);
+        for (; indent > 0; indent--)
+            off = buf_ins(buf, indent, off, '\t');
+    }
     clear_redo(buf);
     return off;
 }
@@ -270,7 +283,7 @@ unsigned buf_rscan(Buf* buf, unsigned pos, Rune r) {
 static int range_match(Buf* buf, unsigned dbeg, unsigned dend, unsigned mbeg, unsigned mend) {
     unsigned n1 = dend-dbeg, n2 = mend-mbeg;
     if (n1 != n2) return n1-n2;
-    for (; n1; n1--, dbeg++, mbeg++) {
+    for (; n1 > 0; n1--, dbeg++, mbeg++) {
         int cmp = buf_get(buf, dbeg) - buf_get(buf, mbeg);
         if (cmp != 0) return cmp;
     }
@@ -281,8 +294,8 @@ void buf_find(Buf* buf, size_t* beg, size_t* end) {
     unsigned dbeg = *beg, dend = *end;
     unsigned mbeg = dend+1, mend = mbeg + (dend-dbeg);
     while (mend != dbeg) {
-        if ((buf_get(buf, mbeg) == buf_get(buf, dbeg)) &&
-            (buf_get(buf, mend) == buf_get(buf, dend)) &&
+        if ((buf_get(buf, mbeg)   == buf_get(buf, dbeg)) &&
+            (buf_get(buf, mend-1) == buf_get(buf, dend-1)) &&
             (0 == range_match(buf,dbeg,dend,mbeg,mend)))
         {
             *beg = mbeg;
index 336e317ba4904b25dce898344ace5be06ce5fa51..87f9b0618c2d3be93b2ac582981a86083ae80c69 100644 (file)
@@ -49,7 +49,7 @@ int charset(const uint8_t* buf, size_t len, int* crlf) {
 
 void binload(Buf* buf, FMap file) {
     for (size_t i = 0; i < file.len; i++)
-        buf_ins(buf, buf_end(buf), file.buf[i]);
+        buf_ins(buf, false, buf_end(buf), file.buf[i]);
 }
 
 void binsave(Buf* buf, FILE* file) {
index 78325dc21205449fe65c6857c6a70002176836b7..986505ea07d833116063830a962be329b9bef70d 100644 (file)
@@ -91,7 +91,7 @@ void utf8load(Buf* buf, FMap file) {
         Rune r = 0;
         size_t len = 0;
         while (!utf8decode(&r, &len, file.buf[i++]));
-        buf_ins(buf, buf_end(buf), r);
+        buf_ins(buf, false, buf_end(buf), r);
     }
 }
 
index 8908f8e94ebd71f00f140ab452e27874f4fe3ace..1f45d4399830d2451d7b6bed059f5085a76f747e 100644 (file)
@@ -372,7 +372,7 @@ void view_insert(View* view, Rune rune) {
         return;
     if (num_selected(view->selection))
         view_delete(view, RIGHT, false);
-    view->selection.end = buf_ins(&(view->buffer), view->selection.end, rune);
+    view->selection.end = buf_ins(&(view->buffer), true, view->selection.end, rune);
     view->selection.beg = view->selection.end;
     view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
     view->sync_needed   = true;
@@ -457,7 +457,7 @@ void view_append(View* view, char* str) {
     if (view->selection.end != end)
         view->selection = (Sel){ .beg = end, .end = end };
     if (!num_selected(view->selection) && !buf_iseol(&(view->buffer), view->selection.end-1)) {
-        buf_ins(&(view->buffer), view->selection.end++, '\n');
+        buf_ins(&(view->buffer), false, view->selection.end++, '\n');
         view->selection.beg++;
     }
     view_putstr(view, str);
index 9467b55b3fa792e77554c7d9a13076f1effe11f9..503b9e05eb19d9cb7c667bc1545c890f7e342bd9 100755 (executable)
--- a/xfilepick
+++ b/xfilepick
@@ -3,4 +3,4 @@ if [ "$#" -ne 1 ]; then
     echo "Usage: $0 <dir>"
     exit 1
 fi
-find $1 -not -path '*/\.*' -type f | ./xpick
+find $1 -not -path '*/\.*' -type f | xpick
diff --git a/xpick.c b/xpick.c
index 30980ab7ae1c51d78b059ecbde34afb27ece2878..1008c5ddb6d1f4487dafc230438bc01f08495c8d 100644 (file)
--- a/xpick.c
+++ b/xpick.c
@@ -187,7 +187,7 @@ static void keyboard_input(int mods, uint32_t key) {
             break;
         default:
             ChoiceIdx = 0;
-            buf_ins(&Query, Pos++, key);
+            buf_ins(&Query, false, Pos++, key);
             break;
     }
     score();