diff -u -r nano/global.c nano-testpatch/global.c --- nano/global.c Tue Apr 23 07:50:40 2002 +++ nano-testpatch/global.c Wed Apr 24 03:50:35 2002 @@ -556,6 +556,15 @@ NANO_OPENNEXT_KEY, 0, 0, VIEW, open_nextfile_void); #endif +#ifndef NANO_SMALL + sc_init_one(&main_list, NANO_NEXTWORD_KEY, _("Next Word"), + IFHELP(_("Move forward one word"),) + 0, 0, 0, VIEW, do_next_word_void); + sc_init_one(&main_list, -9, _("Prev Word"), + IFHELP(_("Move backward one word"),) NANO_PREVWORD_KEY, 0, 0, + VIEW, do_prev_word_void); +#endif + free_shortcutage(&whereis_list); sc_init_one(&whereis_list, NANO_HELP_KEY, diff -u -r nano/nano.c nano-testpatch/nano.c --- nano/nano.c Tue Apr 23 07:50:40 2002 +++ nano-testpatch/nano.c Wed Apr 24 02:40:27 2002 @@ -872,6 +872,11 @@ } } +int do_next_word_void(void) { + do_next_word(); + return 0; +} + /* the same thing for backwards */ void do_prev_word(void) { @@ -945,6 +950,11 @@ } } + +int do_prev_word_void(void) { + do_prev_word(); + return 0; +} #endif /* NANO_SMALL */ #ifndef DISABLE_WRAPPING @@ -2478,9 +2488,9 @@ #ifndef DISABLE_HELP void help_init(void) { - int i, sofar = 0, meta_shortcut = 0, helplen; + int i, sofar = 0, helplen; long allocsize = 1; /* How much space we're gonna need for the help text */ - char buf[BUFSIZ] = "", *ptr = NULL; + char *ptr = NULL; #ifndef NANO_SMALL toggle *t; #endif @@ -2604,64 +2614,60 @@ /* Now add the text we want */ strcpy(help_text, ptr); + sofar = strlen(help_text); /* Now add our shortcut info */ s = currshortcut; for (i = 0; i <= helplen - 1; i++) { - if (s->val > 0 && s->val < 'a') - sofar = snprintf(buf, BUFSIZ, "^%c ", s->val + 64); - else { - if (s->altval > 0) { - sofar = 0; - meta_shortcut = 1; - } - else - sofar = snprintf(buf, BUFSIZ, " "); - } + int meta_shortcut = 0; + + if (s->val > 0 && s->val < 32) + sofar += sprintf(help_text + sofar, "^%c\t", s->val + 64); +#ifndef NANO_SMALL + else if (s->val == NANO_CONTROL_SPACE) + sofar += sprintf(help_text + sofar, "^%s\t", _("Space")); +#endif + else if (s->altval > 0) + meta_shortcut = 1; + else + help_text[sofar++] = '\t'; if (!meta_shortcut) { if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64)) - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, "(F%d) ", - s->misc1 - KEY_F0); - else - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " "); + sofar += sprintf(help_text + sofar, "(F%d)", + s->misc1 - KEY_F0); + help_text[sofar++] = '\t'; } - if (s->altval > 0 && s->altval < 91 - && (s->altval - 32) > 32) - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, - (meta_shortcut ? "M-%c " : "(M-%c) "), - s->altval - 32); - else if (s->altval >= 'a') - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, - (meta_shortcut ? "M-%c " : "(M-%c) "), - s->altval - 32); - else if (s->altval > 0) - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, - (meta_shortcut ? "M-%c " : "(M-%c) "), - s->altval); +#ifndef NANO_SMALL + if (s->altval == NANO_ALT_SPACE) + sofar += sprintf(help_text + sofar, "M-%s", _("Space")); + else +#endif + if (s->altval > 0) + sofar += sprintf(help_text + sofar, + (meta_shortcut ? "M-%c" : "(M-%c)"), s->altval - + ((64 < s->altval && s->altval < 91) || 'a' < s->altval + ? 32 : 0)); /* Hack */ else if (s->val >= 'a') - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, - (meta_shortcut ? "(M-%c) " : "M-%c "), - s->val - 32); - else - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, " "); + sofar += sprintf(help_text + sofar, + (meta_shortcut ? "(M-%c)\t" : "M-%c\t"), s->val - 32); + + help_text[sofar++] = '\t'; if (meta_shortcut) { if (s->misc1 > KEY_F0 && s->misc1 <= KEY_F(64)) - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, - "(F%d) ", s->misc1 - KEY_F0); - else - sofar += snprintf(&buf[sofar], BUFSIZ - sofar, - " "); + sofar += sprintf(help_text + sofar, + "(F%d)", s->misc1 - KEY_F0); + help_text[sofar++] = '\t'; + help_text[sofar++] = '\t'; } if (s->help != NULL) - snprintf(&buf[sofar], BUFSIZ - sofar, "%s", s->help); + sofar += sprintf(help_text + sofar, "%s", s->help); - strcat(help_text, buf); - strcat(help_text, "\n"); + help_text[sofar++] = '\n'; s = s->next; } @@ -2670,15 +2676,14 @@ /* And the toggles... */ if (currshortcut == main_list) for (t = toggles; t != NULL; t = t->next) { - sofar = snprintf(buf, BUFSIZ, - "M-%c ", t->val - 32); + sofar += sprintf(help_text + sofar, "M-%c\t\t\t", + t->val - 32); if (t->desc != NULL) { - snprintf(&buf[sofar], BUFSIZ - sofar, _("%s enable/disable"), - t->desc); + sofar += sprintf(help_text + sofar, + _("%s enable/disable"), t->desc); + } + help_text[sofar++] = '\n'; } - strcat(help_text, buf); - strcat(help_text, "\n"); - } #endif /* !NANO_SMALL */ } #endif @@ -3155,13 +3160,6 @@ modify_control_seq = 1; keyhandled = 1; break; -#ifndef NANO_SMALL - case ' ': - /* If control-space is next word, Alt-space should be previous word */ - do_prev_word(); - keyhandled = 1; - break; -#endif case '[': switch (kbinput = wgetch(edit)) { case '1': /* Alt-[-1-[0-5,7-9] = F1-F8 in X at least */ @@ -3296,19 +3294,16 @@ break; #endif -#if !defined (NANO_SMALL) && defined (HAVE_REGEX_H) - case NANO_BRACKET_KEY: - do_find_bracket(); - keyhandled = 1; - break; -#endif - default: /* Check for the altkey defs.... */ for (s = main_list; s != NULL; s = s->next) if (kbinput == s->altval || - kbinput == s->altval - 32) { - kbinput = s->val; + kbinput == s->altval - 32) { + if (ISSET(VIEW_MODE) && !s->viewok) + print_view_warning(); + else + s->func(); + keyhandled = 1; break; } #ifndef NANO_SMALL @@ -3405,11 +3400,6 @@ #endif case 0: /* Erg */ -#ifndef NANO_SMALL - do_next_word(); - break; -#endif - case -1: /* Stuff that we don't want to do squat */ case 410: /* Must ignore this, it gets sent when we resize */ case 29: /* Ctrl-] */ diff -u -r nano/nano.h nano-testpatch/nano.h --- nano/nano.h Tue Apr 23 07:50:40 2002 +++ nano-testpatch/nano.h Wed Apr 24 04:15:38 2002 @@ -172,6 +172,9 @@ /* Control key sequences, changing these would be very very bad */ +#ifndef NANO_SMALL +# define NANO_CONTROL_SPACE 0 +#endif #define NANO_CONTROL_A 1 #define NANO_CONTROL_B 2 #define NANO_CONTROL_C 3 @@ -235,6 +238,9 @@ #define NANO_ALT_LCARAT '<' #define NANO_ALT_RCARAT '>' #define NANO_ALT_BRACKET ']' +#ifndef NANO_SMALL +# define NANO_ALT_SPACE ' ' +#endif /* Some semi-changeable keybindings; don't play with unless you're sure you know what you're doing */ @@ -298,6 +304,10 @@ #define NANO_OPENNEXT_ALTKEY NANO_ALT_PERIOD #define NANO_BRACKET_KEY NANO_ALT_BRACKET #define NANO_EXTCMD_KEY NANO_CONTROL_X +#ifndef NANO_SMALL +# define NANO_NEXTWORD_KEY NANO_CONTROL_SPACE +# define NANO_PREVWORD_KEY NANO_ALT_SPACE +#endif #define TOGGLE_CONST_KEY NANO_ALT_C #define TOGGLE_AUTOINDENT_KEY NANO_ALT_I diff -u -r nano/proto.h nano-testpatch/proto.h --- nano/proto.h Tue Apr 23 07:50:40 2002 +++ nano-testpatch/proto.h Wed Apr 24 02:40:27 2002 @@ -141,6 +141,11 @@ int check_operating_dir(char *currpath, int allow_tabcomp); #endif +#ifndef NANO_SMALL +int do_next_word_void(void); +int do_prev_word_void(void); +#endif /* !NANO_SMALL */ + int do_writeout(char *path, int exiting, int append); int do_gotoline(int line, int save_pos); int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword); @@ -188,7 +193,7 @@ void titlebar(char *path); void previous_line(void); void center_cursor(void); -void bottombars(shortcut *s); +void bottombars(const shortcut *s); void blank_statusbar_refresh(void); void nperror(const char *s); void *mallocstrcpy(char *dest, char *src); diff -u -r nano/winio.c nano-testpatch/winio.c --- nano/winio.c Tue Apr 23 07:50:41 2002 +++ nano-testpatch/winio.c Wed Apr 24 04:05:13 2002 @@ -25,6 +25,7 @@ #include #include #include +#include #include "proto.h" #include "nano.h" @@ -579,17 +580,24 @@ reset_cursor(); } -void onekey(char *keystroke, const char *desc, int len) +/* Write a shortcut key to the help area at the bottom of the window. + * keystroke is e.g. "^G" and desc is e.g. "Get Help". + * We are careful to write exactly len characters, even if len is + * very small and keystroke and desc are long. */ +static void onekey(const char *keystroke, const char *desc, int len) { - int i; - wattron(bottomwin, A_REVERSE); - waddstr(bottomwin, keystroke); + waddnstr(bottomwin, keystroke, len); wattroff(bottomwin, A_REVERSE); - waddch(bottomwin, ' '); - waddnstr(bottomwin, desc, len - 3); - for (i = strlen(desc); i < len - 3; i++) - waddch(bottomwin, ' '); + len -= strlen(keystroke); + if (len > 0) { + waddch(bottomwin, ' '); + len--; + waddnstr(bottomwin, desc, len); + len -= strlen(desc); + for (; len > 0; len--) + waddch(bottomwin, ' '); + } } void clear_bottomwin(void) @@ -601,21 +609,21 @@ mvwaddstr(bottomwin, 2, 0, hblank); } -void bottombars(shortcut *s) +void bottombars(const shortcut *s) { int i, j, numcols; - char keystr[10]; - shortcut *t; + char keystr[4]; int slen; - if (s == main_list) - slen = MAIN_VISIBLE; - else - slen = length_of_list(s); - if (ISSET(NO_HELP)) return; + if (s == main_list) { + slen = MAIN_VISIBLE; + assert(MAIN_VISIBLE <= length_of_list(s)); + } else + slen = length_of_list(s); + #ifdef ENABLE_COLOR color_on(bottomwin, COLOR_BOTTOMBARS); if (!colors[COLOR_BOTTOMBARS - FIRST_COLORNUM].set || @@ -623,40 +631,43 @@ wattroff(bottomwin, A_REVERSE); #endif - /* Determine how many extra spaces are needed to fill the bottom of the screen */ - if (slen < 2) - numcols = 6; - else - numcols = (slen + (slen % 2)) / 2; + /* There will be this many columns of shortcuts */ + numcols = (slen + (slen % 2)) / 2; clear_bottomwin(); - t = s; for (i = 0; i < numcols; i++) { for (j = 0; j <= 1; j++) { - wmove(bottomwin, 1 + j, i * ((COLS - 1) / numcols)); + wmove(bottomwin, 1 + j, i * (COLS / numcols)); - if (t->val < 97) - snprintf(keystr, 10, "^%c", t->val + 64); +#ifndef NANO_SMALL + if (s->val == NANO_CONTROL_SPACE) + strcpy(keystr, "^ "); else - snprintf(keystr, 10, "M-%c", t->val - 32); - - onekey(keystr, t->desc, (COLS - 1) / numcols); - - if (t->next == NULL) - break; - t = t->next; - } - +#endif /* !NANO_SMALL */ + if (s->val > 0) { + if (s->val < 64) + sprintf(keystr, "^%c", s->val + 64); + else + sprintf(keystr, "M-%c", s->val - 32); + } else if (s->altval > 0) + sprintf(keystr, "M-%c", s->altval); + + onekey(keystr, s->desc, COLS / numcols); + + s = s->next; + if (s == NULL) + goto break_completely_out; + } } +break_completely_out: #ifdef ENABLE_COLOR color_off(bottomwin, COLOR_BOTTOMBARS); #endif wrefresh(bottomwin); - } /* If modified is not already set, set it and update titlebar */ @@ -1381,7 +1392,6 @@ char *yesstr; /* String of yes characters accepted */ char *nostr; /* Same for no */ char *allstr; /* And all, surprise! */ - char shortstr[5]; /* Temp string for above */ #ifndef DISABLE_MOUSE #ifdef NCURSES_MOUSE_VERSION MEVENT mevent; @@ -1405,18 +1415,20 @@ /* Remove gettext call for keybindings until we clear the thing up */ if (!ISSET(NO_HELP)) { + char shortstr[3]; /* Temp string for Y, N, A */ + wmove(bottomwin, 1, 0); - snprintf(shortstr, 3, " %c", yesstr[0]); + sprintf(shortstr, " %c", yesstr[0]); onekey(shortstr, _("Yes"), 16); if (all) { - snprintf(shortstr, 3, " %c", allstr[0]); + shortstr[1] = allstr[0]; onekey(shortstr, _("All"), 16); } wmove(bottomwin, 2, 0); - snprintf(shortstr, 3, " %c", nostr[0]); + shortstr[1] = nostr[0]; onekey(shortstr, _("No"), 16); onekey("^C", _("Cancel"), 16);