tweaks: condense or improve some comments
Also reshuffle an initialization and drop two useless asserts.master
parent
bd770ea2e7
commit
1b2a091de9
33
src/text.c
33
src/text.c
|
@ -280,35 +280,27 @@ void do_tab(void)
|
||||||
* depending on whether --tabstospaces is in effect. */
|
* depending on whether --tabstospaces is in effect. */
|
||||||
void do_indent(void)
|
void do_indent(void)
|
||||||
{
|
{
|
||||||
char *line_indent = NULL;
|
char *line_indent = charalloc(tabsize + 1);
|
||||||
/* The text added to each line in order to indent it. */
|
/* The whitespace added to each line in order to indent it. */
|
||||||
size_t line_indent_len = 0;
|
size_t line_indent_len = 0;
|
||||||
/* The length of the text added to each line in order to indent
|
/* The number of bytes added to each line in order to indent it. */
|
||||||
* it. */
|
|
||||||
filestruct *top, *bot, *f;
|
filestruct *top, *bot, *f;
|
||||||
size_t top_x, bot_x;
|
size_t top_x, bot_x;
|
||||||
|
|
||||||
assert(openfile->current != NULL && openfile->current->data != NULL);
|
/* Use either all the marked lines or just the current line. */
|
||||||
|
|
||||||
/* If the mark is on, use all lines covered by the mark. */
|
|
||||||
if (openfile->mark_set)
|
if (openfile->mark_set)
|
||||||
mark_order((const filestruct **)&top, &top_x,
|
mark_order((const filestruct **)&top, &top_x,
|
||||||
(const filestruct **)&bot, &bot_x, NULL);
|
(const filestruct **)&bot, &bot_x, NULL);
|
||||||
/* Otherwise, use the current line. */
|
|
||||||
else {
|
else {
|
||||||
top = openfile->current;
|
top = openfile->current;
|
||||||
bot = top;
|
bot = top;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up the text we'll be using as indentation. */
|
/* Set the indentation to either a bunch of spaces or a single tab. */
|
||||||
line_indent = charalloc(tabsize + 1);
|
|
||||||
|
|
||||||
if (ISSET(TABS_TO_SPACES)) {
|
if (ISSET(TABS_TO_SPACES)) {
|
||||||
/* Set the indentation to tabsize spaces. */
|
|
||||||
charset(line_indent, ' ', tabsize);
|
charset(line_indent, ' ', tabsize);
|
||||||
line_indent_len = tabsize;
|
line_indent_len = tabsize;
|
||||||
} else {
|
} else {
|
||||||
/* Set the indentation to a tab. */
|
|
||||||
line_indent[0] = '\t';
|
line_indent[0] = '\t';
|
||||||
line_indent_len = 1;
|
line_indent_len = 1;
|
||||||
}
|
}
|
||||||
|
@ -386,33 +378,30 @@ void do_unindent(void)
|
||||||
filestruct *top, *bot, *f;
|
filestruct *top, *bot, *f;
|
||||||
size_t top_x, bot_x;
|
size_t top_x, bot_x;
|
||||||
|
|
||||||
assert(openfile->current != NULL && openfile->current->data != NULL);
|
/* Use either all the marked lines or just the current line. */
|
||||||
|
|
||||||
/* If the mark is on, use all lines covered by the mark. */
|
|
||||||
if (openfile->mark_set)
|
if (openfile->mark_set)
|
||||||
mark_order((const filestruct **)&top, &top_x,
|
mark_order((const filestruct **)&top, &top_x,
|
||||||
(const filestruct **)&bot, &bot_x, NULL);
|
(const filestruct **)&bot, &bot_x, NULL);
|
||||||
/* Otherwise, use the current line. */
|
|
||||||
else {
|
else {
|
||||||
top = openfile->current;
|
top = openfile->current;
|
||||||
bot = top;
|
bot = top;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Go through the lines to check whether they a) are empty or blank
|
/* If any of the lines cannot be unindented and does not consist of
|
||||||
* or b) start with a tab's worth of whitespace. */
|
* only whitespace, we don't change anything. */
|
||||||
for (f = top; f != bot->next; f = f->next) {
|
for (f = top; f != bot->next; f = f->next) {
|
||||||
if (!white_string(f->data) && length_of_white(f->data) == 0) {
|
if (length_of_white(f->data) == 0 && !white_string(f->data)) {
|
||||||
statusline(HUSH, _("Can unindent only by a full tab size"));
|
statusline(HUSH, _("Can unindent only by a full tab size"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Go through each line of the text. */
|
/* Go through each of the lines and remove their leading indent. */
|
||||||
for (f = top; f != bot->next; f = f->next) {
|
for (f = top; f != bot->next; f = f->next) {
|
||||||
size_t line_len = strlen(f->data);
|
size_t line_len = strlen(f->data);
|
||||||
size_t indent_len = length_of_white(f->data);
|
size_t indent_len = length_of_white(f->data);
|
||||||
|
|
||||||
/* If the line consists of a small amount of whitespace, skip it. */
|
/* If this line cannot be unindeted, simply skip it. */
|
||||||
if (indent_len == 0)
|
if (indent_len == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue