tweaks: rename three variables, for more contrast

master
Benno Schulenberg 2017-09-10 13:04:03 +02:00
parent fc0e16f6bc
commit abf7ac48a1
1 changed files with 28 additions and 29 deletions

View File

@ -276,27 +276,27 @@ void do_tab(void)
#ifndef NANO_TINY #ifndef NANO_TINY
/* Add an indent to the line in f. */ /* Add an indent to the line in f. */
void indent_a_line(filestruct *f, char *line_indent) void indent_a_line(filestruct *f, char *indentation)
{ {
size_t line_indent_len = strlen(line_indent); size_t length = strlen(f->data);
size_t line_len = strlen(f->data); size_t indent_len = strlen(indentation);
/* If the indent is empty, don't change the line. */ /* If the indent is empty, don't change the line. */
if (line_indent_len == 0) if (indent_len == 0)
return; return;
/* Add the fabricated indentation to the beginning of the line. */ /* Add the fabricated indentation to the beginning of the line. */
f->data = charealloc(f->data, line_len + line_indent_len + 1); f->data = charealloc(f->data, length + indent_len + 1);
charmove(&f->data[line_indent_len], f->data, line_len + 1); charmove(&f->data[indent_len], f->data, length + 1);
strncpy(f->data, line_indent, line_indent_len); strncpy(f->data, indentation, indent_len);
openfile->totsize += line_indent_len; openfile->totsize += indent_len;
/* Compensate for the change in the current line. */ /* Compensate for the change in the current line. */
if (openfile->mark_set && f == openfile->mark_begin) if (openfile->mark_set && f == openfile->mark_begin)
openfile->mark_begin_x += line_indent_len; openfile->mark_begin_x += indent_len;
if (f == openfile->current) { if (f == openfile->current) {
openfile->current_x += line_indent_len; openfile->current_x += indent_len;
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
} }
} }
@ -306,7 +306,7 @@ void indent_a_line(filestruct *f, char *line_indent)
* 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 = charalloc(tabsize + 1); char *indentation = charalloc(tabsize + 1);
/* The whitespace added to each line in order to indent it. */ /* The whitespace added to each line in order to indent it. */
filestruct *top, *bot, *f; filestruct *top, *bot, *f;
size_t top_x, bot_x; size_t top_x, bot_x;
@ -328,27 +328,27 @@ void do_indent(void)
/* If all lines are empty, there is nothing to do. */ /* If all lines are empty, there is nothing to do. */
if (f == bot->next) { if (f == bot->next) {
free(line_indent); free(indentation);
return; return;
} }
/* Set the indentation to either a bunch of spaces or a single tab. */ /* Set the indentation to either a bunch of spaces or a single tab. */
if (ISSET(TABS_TO_SPACES)) { if (ISSET(TABS_TO_SPACES)) {
charset(line_indent, ' ', tabsize); charset(indentation, ' ', tabsize);
line_indent[tabsize] = '\0'; indentation[tabsize] = '\0';
} else { } else {
line_indent[0] = '\t'; indentation[0] = '\t';
line_indent[1] = '\0'; indentation[1] = '\0';
} }
/* Go through each of the lines, but skip empty ones. */ /* Go through each of the lines, but skip empty ones. */
for (f = top; f != bot->next; f = f->next) { for (f = top; f != bot->next; f = f->next) {
char *real_indent = (f->data[0] == '\0') ? "" : line_indent; char *real_indent = (f->data[0] == '\0') ? "" : indentation;
indent_a_line(f, real_indent); indent_a_line(f, real_indent);
} }
free(line_indent); free(indentation);
/* Throw away the undo stack, to prevent making mistakes when /* Throw away the undo stack, to prevent making mistakes when
* the user tries to undo something in the indented text. */ * the user tries to undo something in the indented text. */
@ -380,33 +380,32 @@ size_t length_of_white(const char *text)
} }
/* Remove an indent from the line in f. */ /* Remove an indent from the line in f. */
void unindent_a_line(filestruct *f, size_t line_indent_len) void unindent_a_line(filestruct *f, size_t indent_len)
{ {
size_t line_len = strlen(f->data); size_t length = strlen(f->data);
/* If the indent is empty, don't change the line. */ /* If the indent is empty, don't change the line. */
if (line_indent_len == 0) if (indent_len == 0)
return; return;
/* Remove the first tab's worth of whitespace from this line. */ /* Remove the first tab's worth of whitespace from this line. */
charmove(f->data, &f->data[line_indent_len], charmove(f->data, &f->data[indent_len], length - indent_len + 1);
line_len - line_indent_len + 1); null_at(&f->data, length - indent_len + 1);
null_at(&f->data, line_len - line_indent_len + 1);
openfile->totsize -= line_indent_len; openfile->totsize -= indent_len;
/* Compensate for the change in the current line. */ /* Compensate for the change in the current line. */
if (openfile->mark_set && f == openfile->mark_begin) { if (openfile->mark_set && f == openfile->mark_begin) {
if (openfile->mark_begin_x < line_indent_len) if (openfile->mark_begin_x < indent_len)
openfile->mark_begin_x = 0; openfile->mark_begin_x = 0;
else else
openfile->mark_begin_x -= line_indent_len; openfile->mark_begin_x -= indent_len;
} }
if (f == openfile->current) { if (f == openfile->current) {
if (openfile->current_x < line_indent_len) if (openfile->current_x < indent_len)
openfile->current_x = 0; openfile->current_x = 0;
else else
openfile->current_x -= line_indent_len; openfile->current_x -= indent_len;
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
} }
} }