text: remove the last usage of cols in do_indent() and do_unindent()

Since all indentation and unindentation is by a tab, or by a tab's
worth of spaces, use tabsize directly.
master
David Lawrence Ramsey 2017-07-10 16:34:27 -05:00 committed by Benno Schulenberg
parent d02c1993d8
commit 7e9799d42b
3 changed files with 17 additions and 38 deletions

View File

@ -929,9 +929,9 @@ void shortcut_init(void)
N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW); N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW);
#ifndef NANO_TINY #ifndef NANO_TINY
add_to_funcs(do_indent_void, MMAIN, add_to_funcs(do_indent, MMAIN,
N_("Indent Text"), IFSCHELP(nano_indent_msg), TOGETHER, NOVIEW); N_("Indent Text"), IFSCHELP(nano_indent_msg), TOGETHER, NOVIEW);
add_to_funcs(do_unindent_void, MMAIN, add_to_funcs(do_unindent, MMAIN,
N_("Unindent Text"), IFSCHELP(nano_unindent_msg), BLANKAFTER, NOVIEW); N_("Unindent Text"), IFSCHELP(nano_unindent_msg), BLANKAFTER, NOVIEW);
#endif #endif
#ifdef ENABLE_WORDCOMPLETION #ifdef ENABLE_WORDCOMPLETION
@ -1105,8 +1105,8 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "F15", 0, do_mark, 0); add_to_sclist(MMAIN, "F15", 0, do_mark, 0);
add_to_sclist(MMAIN, "M-6", 0, do_copy_text, 0); add_to_sclist(MMAIN, "M-6", 0, do_copy_text, 0);
add_to_sclist(MMAIN, "M-^", 0, do_copy_text, 0); add_to_sclist(MMAIN, "M-^", 0, do_copy_text, 0);
add_to_sclist(MMAIN, "M-}", 0, do_indent_void, 0); add_to_sclist(MMAIN, "M-}", 0, do_indent, 0);
add_to_sclist(MMAIN, "M-{", 0, do_unindent_void, 0); add_to_sclist(MMAIN, "M-{", 0, do_unindent, 0);
add_to_sclist(MMAIN, "M-U", 0, do_undo, 0); add_to_sclist(MMAIN, "M-U", 0, do_undo, 0);
add_to_sclist(MMAIN, "M-E", 0, do_redo, 0); add_to_sclist(MMAIN, "M-E", 0, do_redo, 0);
#endif #endif
@ -1488,9 +1488,9 @@ sc *strtosc(const char *input)
#endif #endif
#ifndef NANO_TINY #ifndef NANO_TINY
else if (!strcasecmp(input, "indent")) else if (!strcasecmp(input, "indent"))
s->scfunc = do_indent_void; s->scfunc = do_indent;
else if (!strcasecmp(input, "unindent")) else if (!strcasecmp(input, "unindent"))
s->scfunc = do_unindent_void; s->scfunc = do_unindent;
else if (!strcasecmp(input, "scrollup")) else if (!strcasecmp(input, "scrollup"))
s->scfunc = do_scroll_up; s->scfunc = do_scroll_up;
else if (!strcasecmp(input, "scrolldown")) else if (!strcasecmp(input, "scrolldown"))

View File

@ -523,10 +523,8 @@ void do_cut_next_word(void);
#endif #endif
void do_tab(void); void do_tab(void);
#ifndef NANO_TINY #ifndef NANO_TINY
void do_indent(ssize_t cols); void do_indent(void);
void do_indent_void(void); void do_unindent(void);
void do_unindent(ssize_t cols);
void do_unindent_void(void);
#endif #endif
bool white_string(const char *s); bool white_string(const char *s);
#ifdef ENABLE_COMMENT #ifdef ENABLE_COMMENT

View File

@ -282,7 +282,7 @@ void do_tab(void)
* positive or negative. If the TABS_TO_SPACES flag is set, indent or * positive or negative. If the TABS_TO_SPACES flag is set, indent or
* unindent by len spaces. Otherwise, indent or unindent by (len / * unindent by len spaces. Otherwise, indent or unindent by (len /
* tabsize) tabs and (len % tabsize) spaces. */ * tabsize) tabs and (len % tabsize) spaces. */
void do_indent(ssize_t cols) void do_indent(void)
{ {
char *line_indent = NULL; char *line_indent = NULL;
/* The text added to each line in order to indent it. */ /* The text added to each line in order to indent it. */
@ -305,22 +305,17 @@ void do_indent(ssize_t cols)
} }
/* Set up the text we'll be using as indentation. */ /* Set up the text we'll be using as indentation. */
line_indent = charalloc(cols + 1); line_indent = charalloc(tabsize + 1);
if (ISSET(TABS_TO_SPACES)) { if (ISSET(TABS_TO_SPACES)) {
/* Set the indentation to cols spaces. */ /* Set the indentation to cols spaces. */
charset(line_indent, ' ', cols); charset(line_indent, ' ', tabsize);
line_indent_len = cols; line_indent_len = tabsize;
} else { } else {
/* Set the indentation to (cols / tabsize) tabs and (cols % /* Set the indentation to (cols / tabsize) tabs and (cols %
* tabsize) spaces. */ * tabsize) spaces. */
size_t num_tabs = cols / tabsize; line_indent[0] = '\t';
size_t num_spaces = cols % tabsize; line_indent_len = 1;
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'; line_indent[line_indent_len] = '\0';
@ -368,19 +363,12 @@ void do_indent(ssize_t cols)
refresh_needed = TRUE; refresh_needed = TRUE;
} }
/* Indent the current line, or all lines covered by the mark if the mark
* is on, tabsize columns. */
void do_indent_void(void)
{
do_indent(tabsize);
}
/* Indent or unindent the current line (or, if the mark is on, all lines /* Indent or unindent the current line (or, if the mark is on, all lines
* covered by the mark) len columns, depending on whether len is * covered by the mark) len columns, depending on whether len is
* positive or negative. If the TABS_TO_SPACES flag is set, indent or * positive or negative. If the TABS_TO_SPACES flag is set, indent or
* unindent by len spaces. Otherwise, indent or unindent by (len / * unindent by len spaces. Otherwise, indent or unindent by (len /
* tabsize) tabs and (len % tabsize) spaces. */ * tabsize) tabs and (len % tabsize) spaces. */
void do_unindent(ssize_t cols) void do_unindent(void)
{ {
bool indent_changed = FALSE; bool indent_changed = FALSE;
/* Whether any indenting or unindenting was done. */ /* Whether any indenting or unindenting was done. */
@ -406,8 +394,8 @@ void do_unindent(ssize_t cols)
size_t indent_col = strnlenpt(f->data, indent_len); size_t indent_col = strnlenpt(f->data, indent_len);
/* The length in columns of the indentation on this line. */ /* The length in columns of the indentation on this line. */
if (cols <= indent_col) { if (tabsize <= indent_col) {
size_t indent_new = actual_x(f->data, indent_col - cols); size_t indent_new = actual_x(f->data, indent_col - tabsize);
/* The length of the indentation remaining on /* The length of the indentation remaining on
* this line after we unindent. */ * this line after we unindent. */
size_t indent_shift = indent_len - indent_new; size_t indent_shift = indent_len - indent_new;
@ -457,13 +445,6 @@ void do_unindent(ssize_t cols)
refresh_needed = TRUE; refresh_needed = TRUE;
} }
} }
/* Unindent the current line, or all lines covered by the mark if the mark
* is on, tabsize columns. */
void do_unindent_void(void)
{
do_unindent(tabsize);
}
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
/* Test whether the string is empty or consists of only blanks. */ /* Test whether the string is empty or consists of only blanks. */