commit 7e9799d42bff6126ce4bc78f8d82cda8f7af0919
parent d02c1993d8490bbc4838c7aeaa8b7c981488c9fe
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date: Mon, 10 Jul 2017 16:34:27 -0500
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.
Diffstat:
3 files changed, 17 insertions(+), 38 deletions(-)
diff --git a/src/global.c b/src/global.c
@@ -929,9 +929,9 @@ void shortcut_init(void)
N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW);
#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);
- add_to_funcs(do_unindent_void, MMAIN,
+ add_to_funcs(do_unindent, MMAIN,
N_("Unindent Text"), IFSCHELP(nano_unindent_msg), BLANKAFTER, NOVIEW);
#endif
#ifdef ENABLE_WORDCOMPLETION
@@ -1105,8 +1105,8 @@ void shortcut_init(void)
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-^", 0, do_copy_text, 0);
- add_to_sclist(MMAIN, "M-}", 0, do_indent_void, 0);
- add_to_sclist(MMAIN, "M-{", 0, do_unindent_void, 0);
+ add_to_sclist(MMAIN, "M-}", 0, do_indent, 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-E", 0, do_redo, 0);
#endif
@@ -1488,9 +1488,9 @@ sc *strtosc(const char *input)
#endif
#ifndef NANO_TINY
else if (!strcasecmp(input, "indent"))
- s->scfunc = do_indent_void;
+ s->scfunc = do_indent;
else if (!strcasecmp(input, "unindent"))
- s->scfunc = do_unindent_void;
+ s->scfunc = do_unindent;
else if (!strcasecmp(input, "scrollup"))
s->scfunc = do_scroll_up;
else if (!strcasecmp(input, "scrolldown"))
diff --git a/src/proto.h b/src/proto.h
@@ -523,10 +523,8 @@ void do_cut_next_word(void);
#endif
void do_tab(void);
#ifndef NANO_TINY
-void do_indent(ssize_t cols);
-void do_indent_void(void);
-void do_unindent(ssize_t cols);
-void do_unindent_void(void);
+void do_indent(void);
+void do_unindent(void);
#endif
bool white_string(const char *s);
#ifdef ENABLE_COMMENT
diff --git a/src/text.c b/src/text.c
@@ -282,7 +282,7 @@ void do_tab(void)
* positive or negative. If the TABS_TO_SPACES flag is set, indent or
* unindent by len spaces. Otherwise, indent or unindent by (len /
* tabsize) tabs and (len % tabsize) spaces. */
-void do_indent(ssize_t cols)
+void do_indent(void)
{
char *line_indent = NULL;
/* 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. */
- line_indent = charalloc(cols + 1);
+ line_indent = charalloc(tabsize + 1);
if (ISSET(TABS_TO_SPACES)) {
/* Set the indentation to cols spaces. */
- charset(line_indent, ' ', cols);
- line_indent_len = cols;
+ charset(line_indent, ' ', tabsize);
+ line_indent_len = tabsize;
} 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[0] = '\t';
+ line_indent_len = 1;
}
line_indent[line_indent_len] = '\0';
@@ -368,19 +363,12 @@ void do_indent(ssize_t cols)
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
* covered by the mark) len columns, depending on whether len is
* positive or negative. If the TABS_TO_SPACES flag is set, indent or
* unindent by len spaces. Otherwise, indent or unindent by (len /
* tabsize) tabs and (len % tabsize) spaces. */
-void do_unindent(ssize_t cols)
+void do_unindent(void)
{
bool indent_changed = FALSE;
/* 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);
/* The length in columns of the indentation on this line. */
- if (cols <= indent_col) {
- size_t indent_new = actual_x(f->data, indent_col - cols);
+ if (tabsize <= indent_col) {
+ size_t indent_new = actual_x(f->data, indent_col - tabsize);
/* The length of the indentation remaining on
* this line after we unindent. */
size_t indent_shift = indent_len - indent_new;
@@ -457,13 +445,6 @@ void do_unindent(ssize_t cols)
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 */
/* Test whether the string is empty or consists of only blanks. */