Giving each toggle a sequence number, to be able to show them in a fixed order.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5282 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2015-07-06 17:51:17 +00:00
parent 05fb283034
commit 5ac6a87522
5 changed files with 35 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2015-06-28 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (add_to_sclist), src/help.c (help_init), src/nano.h,
src/rcfile.c (parse_binding): When defining the toggles, give each
of them a sequence number, so that, when they are rebound, they can
still be listed in the original order in the help text.
GNU nano 2.4.2 - 2015.07.05
2015-06-28 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (browser_refresh): Limit the selected file to the

View File

@ -314,6 +314,7 @@ void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *h
void add_to_sclist(int menu, const char *scstring, void (*func)(void), int toggle)
{
static sc *tailsc;
static int counter = 0;
sc *s = (sc *)nmalloc(sizeof(sc));
/* Start the list, or tack on the next item. */
@ -328,6 +329,8 @@ void add_to_sclist(int menu, const char *scstring, void (*func)(void), int toggl
s->menu = menu;
s->scfunc = func;
s->toggle = toggle;
if (toggle)
s->ordinal = ++counter;
s->keystr = (char *) scstring;
s->type = strtokeytype(scstring);
assign_keyinfo(s);

View File

@ -444,14 +444,28 @@ void help_init(void)
#ifndef NANO_TINY
/* And the toggles... */
if (currmenu == MMAIN)
if (currmenu == MMAIN) {
int maximum = 0, counter = 0;
/* First see how many toggles there are. */
for (s = sclist; s != NULL; s = s->next) {
if (s->scfunc == do_toggle_void)
maximum = (s->toggle && s->ordinal > maximum) ? s->ordinal : maximum;
}
/* Now show them in the original order. */
while (counter < maximum) {
counter++;
for (s = sclist; s != NULL; s = s->next) {
if (s->toggle && s->ordinal == counter) {
ptr += sprintf(ptr, "%s\t\t%s %s\n", (s->menu == MMAIN ? s->keystr : ""),
_(flagtostr(s->toggle)), _("enable/disable"));
if (s->toggle == NO_COLOR_SYNTAX || s->toggle == TABS_TO_SPACES)
ptr += sprintf(ptr, "\n");
break;
}
}
}
}
#ifndef DISABLE_NANORC
if (old_whitespace)

View File

@ -452,6 +452,9 @@ typedef struct sc {
/* The function we're going to run. */
int toggle;
/* If a toggle, what we're toggling. */
int ordinal;
/* The how-manieth toggle this is, in order to be able to
* keep them in sequence. */
struct sc *next;
/* Next in the list. */
} sc;

View File

@ -559,6 +559,13 @@ void parse_binding(char *ptr, bool dobind)
}
if (dobind) {
/* If this is a toggle, copy its sequence number. */
if (newsc->scfunc == do_toggle_void) {
for (s = sclist; s != NULL; s = s->next)
if (newsc->toggle == s->toggle)
newsc->ordinal = s->ordinal;
} else
newsc->ordinal = 0;
/* Add the new shortcut at the start of the list. */
newsc->next = sclist;
sclist = newsc;