]> git.mdlowis.com Git - projs/tide.git/commitdiff
implemented expand tabs mode
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 2 Dec 2016 02:29:16 +0000 (21:29 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 2 Dec 2016 02:29:16 +0000 (21:29 -0500)
TODO.md
inc/edit.h
libedit/buf.c
libedit/view.c

diff --git a/TODO.md b/TODO.md
index bba87b2b045aac2ab97f114084c2460a1372322f..89d3c46aae61f3976b946c8c61a3659bdfc1bb8d 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,6 @@
 # Implementation Tweaks and Bug Fixes
 
+* Auto indent mode
 * 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
@@ -7,12 +8,8 @@
 * Implement minimal regex search (per Kernighan article)
 * Implement fuzzy file/buffer/tag picker
 * Implement omnicomplete pop-up
-* Mode to expand tabs to spaces
-* Auto indent mode
 * off by one error on scrolling up with wrapped lines
 * block selection should handle brace-balancing
-* Right click should fetch file if it exists, search otherwise
-    * directories in browse?
 
 # Internals and Miscellaneous
 
index 2bd49713906a978a34cad025878cb63e89cbb525..d71a61d72b491c516eaed26ef85da81a53c19d2d 100644 (file)
@@ -57,7 +57,7 @@ typedef struct {
 void buf_load(Buf* buf, char* path);
 void buf_save(Buf* buf);
 void buf_init(Buf* buf);
-void buf_ins(Buf* buf, unsigned pos, Rune);
+unsigned buf_ins(Buf* buf, unsigned pos, Rune);
 void buf_del(Buf* buf, unsigned pos);
 unsigned buf_undo(Buf* buf, unsigned pos);
 unsigned buf_redo(Buf* buf, unsigned pos);
index 658cd198a7881b2050f7a7eb14d3bba5d113efeb..e4179cb7808357afac0e7bec4648768bf7cbcf2d 100644 (file)
@@ -74,16 +74,17 @@ static void syncgap(Buf* buf, unsigned off) {
 }
 
 void buf_init(Buf* buf) {
-    buf->modified = false;
-    buf->charset  = DEFAULT_CHARSET;
-    buf->crlf     = DEFAULT_CRLF;
-    buf->bufsize  = BufSize;
-    buf->bufstart = (Rune*)malloc(buf->bufsize * sizeof(Rune));
-    buf->bufend   = buf->bufstart + buf->bufsize;
-    buf->gapstart = buf->bufstart;
-    buf->gapend   = buf->bufend;
-    buf->undo     = NULL;
-    buf->redo     = NULL;
+    buf->modified    = false;
+    buf->expand_tabs = true;
+    buf->charset     = DEFAULT_CHARSET;
+    buf->crlf        = DEFAULT_CRLF;
+    buf->bufsize     = BufSize;
+    buf->bufstart    = (Rune*)malloc(buf->bufsize * sizeof(Rune));
+    buf->bufend      = buf->bufstart + buf->bufsize;
+    buf->gapstart    = buf->bufstart;
+    buf->gapend      = buf->bufend;
+    buf->undo        = NULL;
+    buf->redo        = NULL;
 }
 
 static void log_insert(Log** list, unsigned beg, unsigned end) {
@@ -151,11 +152,18 @@ static void clear_redo(Buf* buf) {
     buf->redo = NULL;
 }
 
-void buf_ins(Buf* buf, unsigned off, Rune rune) {
+unsigned buf_ins(Buf* buf, unsigned off, Rune rune) {
     buf->modified = true;
-    log_insert(&(buf->undo), off, off+1);
+    if (buf->expand_tabs && rune == '\t') {
+        size_t n = (TabWidth - ((off - buf_bol(buf, off)) % TabWidth));
+        log_insert(&(buf->undo), off, off+n);
+        for(; n > 0; n--) insert(buf, off++, ' ');
+    } else {
+        log_insert(&(buf->undo), off, off+1);
+        insert(buf, off++, rune);
+    }
     clear_redo(buf);
-    insert(buf, off, rune);
+    return off;
 }
 
 static void delete(Buf* buf, unsigned off) {
index 1d11bb795420e72b76abd6cccf151e66a9964d1c..8908f8e94ebd71f00f140ab452e27874f4fe3ace 100644 (file)
@@ -372,10 +372,10 @@ void view_insert(View* view, Rune rune) {
         return;
     if (num_selected(view->selection))
         view_delete(view, RIGHT, false);
-    buf_ins(&(view->buffer), view->selection.end++, rune);
+    view->selection.end = buf_ins(&(view->buffer), view->selection.end, rune);
     view->selection.beg = view->selection.end;
     view->selection.col = buf_getcol(&(view->buffer), view->selection.end);
-    view->sync_needed = true;
+    view->sync_needed   = true;
 }
 
 void view_delete(View* view, int dir, bool byword) {