From: Chris Allegretta Date: Sun, 15 Nov 2015 06:07:15 +0000 (+0000) Subject: Backport of r5282 from trunk. X-Git-Tag: v2.4.3~18 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=55a2133817cdb8140a61c5f7fb21b15b7ad460e9;p=nano.git Backport of r5282 from trunk. git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_4_branch@5406 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index bef2e7e6..0f2f9c6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-06-28 Benno Schulenberg + * 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 * src/browser.c (browser_refresh): Limit the selected file to the diff --git a/src/global.c b/src/global.c index cd7f23f0..be274923 100644 --- a/src/global.c +++ b/src/global.c @@ -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); diff --git a/src/help.c b/src/help.c index a3c5477f..1d4d758c 100644 --- a/src/help.c +++ b/src/help.c @@ -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) diff --git a/src/nano.h b/src/nano.h index cf6d0587..db7be93b 100644 --- a/src/nano.h +++ b/src/nano.h @@ -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; diff --git a/src/rcfile.c b/src/rcfile.c index 358883da..d52e0a8c 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -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;