]> git.mdlowis.com Git - projs/tide.git/commitdiff
General cleanup and removal of buffer locking. last remnant of modal editing
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 10 Nov 2016 23:12:05 +0000 (18:12 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 10 Nov 2016 23:12:05 +0000 (18:12 -0500)
inc/edit.h
inc/utf.h
libedit/buf.c
libedit/mouse.c
tests/buf.c
xedit.c
xpick.c

index 06e5a385b030a1530e26a632888088e9e95e9f10..4a0d16ac0ecd7ebf6398acca8f60ffb5e610c301 100644 (file)
@@ -36,7 +36,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 locked;      /* tracks current mode */
     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 */
@@ -61,8 +60,6 @@ void buf_del(Buf* buf, unsigned pos);
 unsigned buf_undo(Buf* buf, unsigned pos);
 unsigned buf_redo(Buf* buf, unsigned pos);
 Rune buf_get(Buf* buf, unsigned pos);
-void buf_setlocked(Buf* buf, bool locked);
-bool buf_locked(Buf* buf);
 bool buf_iseol(Buf* buf, unsigned pos);
 unsigned buf_bol(Buf* buf, unsigned pos);
 unsigned buf_eol(Buf* buf, unsigned pos);
index 82ad5a8a7745f3ce8176a76eaad5c9578b0c957d..3bacfe9d04ca4068292531753e80e8233cce03a5 100644 (file)
--- a/inc/utf.h
+++ b/inc/utf.h
@@ -1,10 +1,10 @@
 enum {
-    UTF_MAX   = 6u,           /* maximum number of bytes that make up a rune */
-    RUNE_SELF = 0x80,         /* byte values larger than this are *not* ascii */
-    RUNE_ERR  = 0xFFFD,       /* rune value representing an error */
-    RUNE_MAX  = 0x10FFFF,     /* Maximum decodable rune value */
-    RUNE_EOF  = UINT32_MAX,   /* rune value representing end of file */
-    RUNE_CRLF = UINT32_MAX-1, /* rune value representing a \r\n sequence */
+    UTF_MAX   = 6u,       /* maximum number of bytes that make up a rune */
+    RUNE_SELF = 0x80,     /* byte values larger than this are *not* ascii */
+    RUNE_ERR  = 0xFFFD,   /* rune value representing an error */
+    RUNE_MAX  = 0x10FFFF, /* Maximum decodable rune value */
+    RUNE_EOF  = -1,       /* rune value representing end of file */
+    RUNE_CRLF = -2,       /* rune value representing a \r\n sequence */
 };
 
 /* Represents a unicode code point */
index deed804bc08eb3dd5fa82d5f24307d0ecf2097e2..7fd22fd2a50b00de2e450803df7a06829b22493b 100644 (file)
@@ -3,7 +3,6 @@
 #include <edit.h>
 
 void buf_load(Buf* buf, char* path) {
-    buf_setlocked(buf, false);
     if (!strcmp(path,"-")) {
         buf->charset = UTF_8;
         Rune r;
@@ -23,8 +22,9 @@ void buf_load(Buf* buf, char* path) {
         }
         funmap(file);
     }
-    buf_setlocked(buf, true);
     buf->modified = false;
+    free(buf->undo);
+    buf->undo = NULL;
 }
 
 void buf_save(Buf* buf) {
@@ -74,7 +74,6 @@ static void syncgap(Buf* buf, unsigned off) {
 }
 
 void buf_init(Buf* buf) {
-    buf->locked   = true;
     buf->modified = false;
     buf->charset  = DEFAULT_CHARSET;
     buf->crlf     = DEFAULT_CRLF;
@@ -89,9 +88,7 @@ void buf_init(Buf* buf) {
 
 static void log_insert(Log** list, unsigned beg, unsigned end) {
     Log* log = *list;
-    if (!log || log->locked || !log->insert ||
-        (log->data.ins.beg && beg < log->data.ins.beg-1) ||
-        (end > log->data.ins.end+1)) {
+    if (!log || log->locked || !log->insert || (end != log->data.ins.end+1)) {
         Log* newlog  = (Log*)calloc(sizeof(Log), 1);
         newlog->insert = true;
         newlog->data.ins.beg = beg;
@@ -141,7 +138,6 @@ static void insert(Buf* buf, unsigned off, Rune rune) {
 }
 
 void buf_ins(Buf* buf, unsigned off, Rune rune) {
-    if (buf->locked) { return; }
     buf->modified = true;
     log_insert(&(buf->undo), off, off+1);
     insert(buf, off, rune);
@@ -153,7 +149,6 @@ static void delete(Buf* buf, unsigned off) {
 }
 
 void buf_del(Buf* buf, unsigned off) {
-    if (buf->locked) { return; }
     buf->modified = true;
     Rune r = buf_get(buf, off);
     log_delete(&(buf->undo), off, &r, 1);
@@ -209,16 +204,6 @@ Rune buf_get(Buf* buf, unsigned off) {
         return *(buf->gapend + (off - bsz));
 }
 
-void buf_setlocked(Buf* buf, bool locked) {
-    if (locked && buf->undo)
-        buf->undo->locked = true;
-    buf->locked = locked;
-}
-
-bool buf_locked(Buf* buf) {
-    return buf->locked;
-}
-
 bool buf_iseol(Buf* buf, unsigned off) {
     Rune r = buf_get(buf, off);
     return (r == '\n' || r == RUNE_CRLF);
@@ -373,8 +358,6 @@ char* buf_getstr(Buf* buf, unsigned beg, unsigned end) {
 }
 
 unsigned buf_putstr(Buf* buf, unsigned beg, unsigned end, char* str) {
-    bool locked = buf_locked(buf);
-    buf_setlocked(buf, false);
     /* delete the selected text first */
     for (unsigned i = beg; ((end-beg) > 1) && (i <= end); i++)
         buf_del(buf, beg);
@@ -385,6 +368,5 @@ unsigned buf_putstr(Buf* buf, unsigned beg, unsigned end, char* str) {
         while (!utf8decode(&rune, &length, *str++));
         buf_ins(buf, beg++, rune);
     }
-    buf_setlocked(buf, locked);
     return beg;
 }
index 81a5086fd6b33dbf533d147fdddfab09586cd1b8..b910f152fbc17e454ed6ba6ed98d06c41708b4b4 100644 (file)
@@ -30,19 +30,19 @@ void selection(MouseEvent* mevnt) {
     } else if (risword(r)) {
         SelBeg = buf_bow(&Buffer, SelEnd);
         SelEnd = buf_eow(&Buffer, SelEnd);
-        if (!buf_locked(&Buffer)) SelEnd++;
+        SelEnd++;
     } else if (r == '(' || r == ')') {
         SelBeg = buf_lscan(&Buffer, SelEnd, '(');
         SelEnd = buf_rscan(&Buffer, SelEnd, ')');
-        if (!buf_locked(&Buffer)) SelEnd++;
+        SelEnd++;
     } else if (r == '[' || r == ']') {
         SelBeg = buf_lscan(&Buffer, SelEnd, '[');
         SelEnd = buf_rscan(&Buffer, SelEnd, ']');
-        if (!buf_locked(&Buffer)) SelEnd++;
+        SelEnd++;
     } else if (r == '{' || r == '}') {
         SelBeg = buf_lscan(&Buffer, SelEnd, '{');
         SelEnd = buf_rscan(&Buffer, SelEnd, '}');
-        if (!buf_locked(&Buffer)) SelEnd++;
+        SelEnd++;
     } else {
         bigword(mevnt);
     }
index 8c8acee8892b3e692af76eb3b682be419f68ad7a..cb4d877e28b92d474be9abea58b011bb83f66969 100644 (file)
@@ -23,7 +23,6 @@ static void set_buffer_text(char* str) {
     TestBuf.crlf = 1;
     for (Rune* curr = TestBuf.bufstart; curr < TestBuf.bufend; curr++)
         *curr = '-';
-    TestBuf.locked = false;
     while (*str)
         buf_ins(&TestBuf, i++, (Rune)*str++);
 }
@@ -92,42 +91,6 @@ TEST_SUITE(BufferTests) {
      *************************************************************************/
     /* Undo/Redo
      *************************************************************************/
-    /* Locking
-     *************************************************************************/
-    TEST(buf_setlocked should lock the buffer to prevent changes) {
-        TestBuf.locked = false;
-        if (TestBuf.undo) { free(TestBuf.undo); TestBuf.undo = NULL; }
-        buf_setlocked(&TestBuf, true);
-        CHECK(TestBuf.locked);
-    }
-
-    TEST(buf_setlocked should lock the buffer to prevent changes and lock the last undo op) {
-        Log log;
-        TestBuf.locked = false;
-        TestBuf.undo = &log;
-        buf_setlocked(&TestBuf, true);
-        CHECK(TestBuf.locked);
-        CHECK(TestBuf.undo->locked);
-    }
-
-    TEST(buf_setlocked should unlock the buffer) {
-        Log log;
-        TestBuf.locked = true;
-        TestBuf.undo = &log;
-        buf_setlocked(&TestBuf, false);
-        CHECK(!TestBuf.locked);
-    }
-
-    TEST(buf_islocked should return true if locked) {
-        TestBuf.locked = true;
-        CHECK(buf_locked(&TestBuf));
-    }
-
-    TEST(buf_islocked should return false if locked) {
-        TestBuf.locked = false;
-        CHECK(!buf_locked(&TestBuf));
-    }
-
     /* Accessors
      *************************************************************************/
     // buf_get
diff --git a/xedit.c b/xedit.c
index 6a1ffe0d604ce8ee59dfed477d89b035cde694ff..6535ce743e7db5c61dfc7916840a7660e0c4a383 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -266,7 +266,6 @@ int main(int argc, char** argv) {
     buf_init(&Buffer);
     if (argc > 1)
         buf_load(&Buffer, argv[1]);
-    buf_setlocked(&Buffer, false);
     /* initialize the display engine */
     x11_init(&Config);
     x11_window("edit", Width, Height);
diff --git a/xpick.c b/xpick.c
index 610c1230d7a1a31f4913cb159f8ff8fa7003ab81..ac36baf4e5708c87563ecdc6577e7b7563361fc2 100644 (file)
--- a/xpick.c
+++ b/xpick.c
@@ -215,7 +215,6 @@ int main(int argc, char** argv) {
     load_choices();
     /* initialize the filter edit buffer */
     buf_init(&Query);
-    buf_setlocked(&Query, false);
     /* initialize the display engine */
     x11_init(&Config);
     x11_dialog("pick", Width, Height);