| 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(-)
--- |
| 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; |