diff --git a/src/text.c b/src/text.c index b5ba75e6..975ed7a7 100644 --- a/src/text.c +++ b/src/text.c @@ -351,14 +351,14 @@ void do_indent(void) * number of bytes this whitespace occupies. Otherwise, return zero. */ size_t length_of_white(const char *text) { - size_t bytes_of_white = 1; + size_t bytes_of_white = 0; while (TRUE) { if (*text == '\t') - return bytes_of_white; + return ++bytes_of_white; if (*text != ' ') - return 0; + return bytes_of_white; if (bytes_of_white == tabsize) return tabsize; @@ -414,15 +414,16 @@ void do_unindent(void) bot = top; } - /* If any of the lines cannot be unindented and does not consist of - * only whitespace, we don't change anything. */ + /* Check if there is a line that can be unindented. */ for (line = top; line != bot->next; line = line->next) { - if (length_of_white(line->data) == 0 && !white_string(line->data)) { - statusline(HUSH, _("Can unindent only by a full tab size")); - return; - } + if (length_of_white(line->data) != 0) + break; } + /* If none of the lines can be unindented, there is nothing to do. */ + if (line == bot->next) + return; + add_undo(UNINDENT); /* Go through each of the lines and remove their leading indent. */