text: remove indent-related code from do_unindent()

master
David Lawrence Ramsey 2017-07-10 16:48:01 -05:00 committed by Benno Schulenberg
parent 109ad0915d
commit 42f5a84c6f
1 changed files with 0 additions and 64 deletions

View File

@ -384,23 +384,11 @@ void do_unindent(ssize_t cols)
{
bool indent_changed = FALSE;
/* Whether any indenting or unindenting was done. */
bool unindent = TRUE;
/* Whether we're unindenting text. */
char *line_indent = NULL;
/* The text added to each line in order to indent it. */
size_t line_indent_len = 0;
/* The length of the text added to each line in order to indent
* it. */
filestruct *top, *bot, *f;
size_t top_x, bot_x;
assert(openfile->current != NULL && openfile->current->data != NULL);
/* Otherwise, we're indenting, in which case the file will always be
* modified, so set indent_changed to TRUE. */
if (!unindent)
indent_changed = TRUE;
/* If the mark is on, use all lines covered by the mark. */
if (openfile->mark_set)
mark_order((const filestruct **)&top, &top_x,
@ -411,58 +399,11 @@ void do_unindent(ssize_t cols)
bot = top;
}
if (!unindent) {
/* Set up the text we'll be using as indentation. */
line_indent = charalloc(cols + 1);
if (ISSET(TABS_TO_SPACES)) {
/* Set the indentation to cols spaces. */
charset(line_indent, ' ', cols);
line_indent_len = cols;
} else {
/* Set the indentation to (cols / tabsize) tabs and (cols %
* tabsize) spaces. */
size_t num_tabs = cols / tabsize;
size_t num_spaces = cols % tabsize;
charset(line_indent, '\t', num_tabs);
charset(line_indent + num_tabs, ' ', num_spaces);
line_indent_len = num_tabs + num_spaces;
}
line_indent[line_indent_len] = '\0';
}
/* Go through each line of the text. */
for (f = top; f != bot->next; f = f->next) {
size_t line_len = strlen(f->data);
size_t indent_len = indent_length(f->data);
if (!unindent) {
/* If we're indenting, add the characters in line_indent to
* the beginning of the non-whitespace text of this line. */
f->data = charealloc(f->data, line_len + line_indent_len + 1);
charmove(&f->data[indent_len + line_indent_len],
&f->data[indent_len], line_len - indent_len + 1);
strncpy(f->data + indent_len, line_indent, line_indent_len);
openfile->totsize += line_indent_len;
/* Keep track of the change in the current line. */
if (openfile->mark_set && f == openfile->mark_begin &&
openfile->mark_begin_x >= indent_len)
openfile->mark_begin_x += line_indent_len;
if (f == openfile->current && openfile->current_x >= indent_len) {
openfile->current_x += line_indent_len;
openfile->placewewant = xplustabs();
}
/* If the NO_NEWLINES flag isn't set, and this is the
* magicline, add a new magicline. */
if (!ISSET(NO_NEWLINES) && f == openfile->filebot)
new_magicline();
} else {
size_t indent_col = strnlenpt(f->data, indent_len);
/* The length in columns of the indentation on this line. */
@ -503,13 +444,8 @@ void do_unindent(ssize_t cols)
/* We've unindented, so the indentation changed. */
indent_changed = TRUE;
}
}
}
if (!unindent)
/* Clean up. */
free(line_indent);
if (indent_changed) {
/* Throw away the undo stack, to prevent making mistakes when
* the user tries to undo something in the reindented text. */