about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-28 21:21:07 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-28 21:21:17 -0800
commit418fce4464764e8c8e1cc8f5d5bfbcc9c88185e1 (patch)
tree48530248ff90483982247c7176fc9e42d0fa79ce
parent3203bf7afffe19128fe107afcae44791d817730b (diff)
downloadteliva-418fce4464764e8c8e1cc8f5d5bfbcc9c88185e1.tar.gz
auto-indent
-rw-r--r--src/kilo.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/kilo.c b/src/kilo.c
index 4b5e3dc..5b9fd76 100644
--- a/src/kilo.c
+++ b/src/kilo.c
@@ -1063,7 +1063,13 @@ static void editorProcessKeypress(lua_State* L) {
     int c = getch();
     switch(c) {
     case ENTER:
-        editorInsertNewline();
+        {
+            erow* oldrow = &E.row[E.rowoff + E.cy];
+            editorInsertNewline();
+            /* auto-indent */
+            for (int x = 0; x < oldrow->size && oldrow->chars[x] == ' '; ++x)
+                editorInsertChar(' ');
+        }
         break;
     case CTRL_C:
         if (Previous_error != NULL)