tled: update autoindent only if prefix is empty - neatvi - [fork] simple vi-type editor with UTF-8 support
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit c7dcceb5c62060da479326a72bc9e1170f18654c
parent f57f8c4f0b99d1c293036dd028859fa16e03f847
Author: Ali Gholami Rudi 
Date:   Sat, 23 May 2015 14:43:52 +0430

led: update autoindent only if prefix is empty

Diffstat:
  M led.c                               |      14 ++++++++------

1 file changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/led.c b/led.c
t@@ -230,7 +230,7 @@ char *led_input(char *pref, char *post, char *ai, int ai_max, char **kmap)
 {
         struct sbuf *sb = sbuf_make();
         char *first_ai = NULL;
-        int key, i, ai_len;
+        int key, i;
         while (1) {
                 char *ln = led_line(pref, post, ai, ai_max, &key, kmap);
                 if (pref)
t@@ -244,13 +244,15 @@ char *led_input(char *pref, char *post, char *ai, int ai_max, char **kmap)
                                 key == '\n' ? "" : post, *kmap);
                 if (key == '\n')
                         term_chr('\n');
+                if (!pref || !pref[0]) {        /* updating autoindent */
+                        int ai_len = ai_max ? strlen(ai) : 0;
+                        for (i = 0; isspace((unsigned char) ln[i]); i++)
+                                if (ai_len < ai_max)
+                                        ai[ai_len++] = ln[i];
+                        ai[ai_len] = '\0';
+                }
                 pref = NULL;
                 term_kill();
-                ai_len = ai_max ? strlen(ai) : 0;
-                for (i = 0; isspace((unsigned char) ln[i]); i++)
-                        if (ai_len < ai_max)
-                                ai[ai_len++] = ln[i];
-                ai[ai_len] = '\0';
                 free(ln);
                 if (key != '\n')
                         break;