Skip to content

Commit

Permalink
Feature: change tabsize dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhcefx committed May 27, 2024
1 parent d4d5349 commit 26028c4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/nanorc.5
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,9 @@ the line, column, and character positions.
Counts and reports on the status bar the number of lines, words,
and characters in the current buffer (or in the marked region).
.TP
.B settabsize
Prompts for a new tabsize to be set.
.TP
.B execute
Prompts for a program to execute. The program's output will be inserted
into the current buffer (or into a new buffer when \fBM\-F\fR is toggled).
Expand Down
4 changes: 4 additions & 0 deletions src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ void shortcut_init(void)
const char *wordcount_gist =
N_("Count the number of lines, words, and characters");
const char *suspend_gist = N_("Suspend the editor (return to the shell)");
const char *settabsize_gist = N_("Set new tabsize");
#endif
const char *refresh_gist = N_("Refresh (redraw) the current screen");
#ifdef ENABLE_WORDCOMPLETION
Expand Down Expand Up @@ -978,6 +979,8 @@ void shortcut_init(void)
#ifndef NANO_TINY
add_to_funcs(count_lines_words_and_characters, MMAIN,
N_("Word Count"), WITHORSANS(wordcount_gist), TOGETHER, VIEW);
add_to_funcs(do_set_tabsize, MMAIN,
N_("Set Tabsize"), WITHORSANS(settabsize_gist), TOGETHER, NOVIEW);
#endif

add_to_funcs(do_verbatim_input, MMAIN,
Expand Down Expand Up @@ -1355,6 +1358,7 @@ void shortcut_init(void)
add_to_sclist(MEXECUTE, "^Z", 0, do_suspend, 0);
add_to_sclist(MMAIN, "^Z", 0, suggest_ctrlT_ctrlZ, 0);
add_to_sclist(MMAIN, "M-D", 0, count_lines_words_and_characters, 0);
add_to_sclist(MMAIN, "M-4", 0, do_set_tabsize, 0);
#else
add_to_sclist(MMAIN, "M-H", 0, do_help, 0);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ void do_formatter(void);
#endif
#ifndef NANO_TINY
void count_lines_words_and_characters(void);
void do_set_tabsize(void);
#endif
void do_verbatim_input(void);
void complete_a_word(void);
Expand Down
2 changes: 2 additions & 0 deletions src/rcfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ keystruct *strtosc(const char *input)
s->func = do_find_bracket;
else if (!strcmp(input, "wordcount"))
s->func = count_lines_words_and_characters;
else if (!strcmp(input, "settabsize"))
s->func = do_set_tabsize;
else if (!strcmp(input, "recordmacro"))
s->func = record_macro;
else if (!strcmp(input, "runmacro"))
Expand Down
22 changes: 22 additions & 0 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -2969,6 +2969,28 @@ void count_lines_words_and_characters(void)
words, P_("word", "words", words),
chars, P_("character", "characters", chars));
}

/* Prompt user to set the new tabsize. We use the spell menu because
* it has no functions. */
void do_set_tabsize(void)
{
ssize_t new_tabsize = -1;
int response = do_prompt(MSPELL, "", NULL, edit_refresh, "New tabsize");

/* Cancel if no answer provided. */
if (response != 0) {
statusbar(_("Cancelled"));
return;
}

if (!parse_num(answer, &new_tabsize) || new_tabsize <= 0) {
statusline(AHEM, _("Requested tab size \"%s\" is invalid"), answer);
return;
}

tabsize = new_tabsize;
statusline(REMARK, _("Tabsize set to %d"), tabsize);
}
#endif /* !NANO_TINY */

/* Get verbatim input. */
Expand Down

0 comments on commit 26028c4

Please sign in to comment.