From: David Lawrence Ramsey Date: Fri, 23 Jul 2004 12:30:40 +0000 (+0000) Subject: a few miscellaneous Pico compatibility tweaks and bugfixes (most X-Git-Tag: v1.3.4~44 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=8037fe076bc623f6af6237ab6825efab62c377e9;p=nano.git a few miscellaneous Pico compatibility tweaks and bugfixes (most importantly, a fix for a segfault when trying to full-justify a file with no paragraphs) git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1862 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 944f18f9..336a668f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -61,21 +61,34 @@ CVS code - shortcut_init() - Fix erroneous #ifdef so that nano compiles with --disable-justify again. (DLR; found by Mike Frysinger) + - Change the Cancel shortcut in the file browser to an Exit + shortcut, to be more compatible with the current version of + Pico. (DLR) thanks_for_all_the_fish() - Delete topwin, edit, and bottomwin. (David Benbennick) - nano.c: do_justify() - - Add on_next_line flag, used to indicate when we've moved to + - Add allow_respacing flag, used to indicate when we've moved to the next line after justifying the current line, and only run the respacing routine when it's true. This keeps the respacing routine from erroneously being run more than once on the same line. (DLR) + - Check for first_par_line's not being NULL and only run the + renumbering and cutbuffer-splicing routines depending on that + if that's the case. This fixes a segfault occurring when + trying to do full justification on a file with no paragraphs + (in which case there are no normal lines to renumber and no + backed-up lines to be stored in the cutbuffer or spliced back + in during unjustify). (DLR) do_exit() - Tweak for efficiency. (David Benbennick) main() - Move the reset_cursor() call to the beginning of the main input loop, and remove the apparently unnecessary wrefresh() call. (David Benbennick) +- nano.h: + - Reassign the key for full justification to Ctrl-U, for + compatibility with the current version of Pico. (DLR) - proto.h: - Change the variables in the prototypes for do_justify(), get_verbatim_kbinput(), and get_mouseinput() to match the ones @@ -108,6 +121,18 @@ CVS code - - Tweak the code to update the edit window just before getting statusbar input for efficiency, and update bottomwin just before then too. (David Benbennick) + - Don't delete the statusbar line on UnCut, since the current + version of Pico doesn't. (DLR) + line_len() + - Rename to help_line_len() so as not to conflict with the + line_len variable used elsewhere, and move inside the + DISABLE_HELP #ifdef surrounding do_help() since it's only + called in do_help(). (DLR) + do_help() + - Have help_line_len() properly return an int again, since its + value can't be larger than COLS. (DLR) + - Allow the user to exit the help browser via Ctrl-C as well as + Ctrl-X, for consistency with the file browser. (DLR) GNU nano 1.3.3 - 2004.06.28 - General: diff --git a/src/global.c b/src/global.c index e341f516..34e00834 100644 --- a/src/global.c +++ b/src/global.c @@ -323,7 +323,8 @@ void shortcut_init(int unjustify) const char *nano_multibuffer_msg = N_("Insert into new buffer"); #endif #ifndef DISABLE_BROWSER - const char *nano_gotodir_msg = N_("Go to directory"); + const char *nano_exit_browser_msg = N_("Exit from the file browser"); + const char *nano_goto_dir_msg = N_("Go to directory"); #endif #endif /* !DISABLE_HELP */ @@ -913,8 +914,8 @@ void shortcut_init(int unjustify) #endif ); - sc_init_one(&browser_list, NANO_CANCEL_KEY, cancel_msg, - IFHELP(nano_cancel_msg, NANO_NO_KEY), NANO_NO_KEY, + sc_init_one(&browser_list, NANO_EXIT_KEY, exit_msg, + IFHELP(nano_exit_browser_msg, NANO_NO_KEY), NANO_EXIT_FKEY, NANO_NO_KEY, VIEW, 0); sc_init_one(&browser_list, NANO_PREVPAGE_KEY, prev_page_msg, @@ -927,7 +928,7 @@ void shortcut_init(int unjustify) /* Translators: try to keep this string under 22 characters long */ sc_init_one(&browser_list, NANO_GOTO_KEY, N_("Go To Dir"), - IFHELP(nano_gotodir_msg, NANO_ALT_GOTO_KEY), NANO_GOTO_FKEY, + IFHELP(nano_goto_dir_msg, NANO_ALT_GOTO_KEY), NANO_GOTO_FKEY, NANO_NO_KEY, VIEW, 0); free_shortcutage(&gotodir_list); diff --git a/src/nano.c b/src/nano.c index 992f893c..f521ee27 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2638,12 +2638,15 @@ void do_justify(int full_justify) /* We are now done justifying the paragraph or the file, so clean * up. totlines, totsize, and current_y have been maintained above. * Set last_par_line to the new end of the paragraph, update - * fileage, and set current_x. Also, edit_refresh() needs the line - * numbers to be right, so renumber(). */ + * fileage, and renumber() since edit_refresh() needs the line + * numbers to be right (but only do the last two if we actually + * justified something). */ last_par_line = current->prev; - if (first_par_line->prev == NULL) - fileage = first_par_line; - renumber(first_par_line); + if (first_par_line != NULL) { + if (first_par_line->prev == NULL) + fileage = first_par_line; + renumber(first_par_line); + } edit_refresh(); @@ -2681,20 +2684,23 @@ void do_justify(int full_justify) current_y = current_y_save; edittop = edittop_save; - /* Splice the cutbuffer back into the file. */ - cutbottom->next = last_par_line->next; - cutbottom->next->prev = cutbottom; + /* Splice the cutbuffer back into the file, but only if we + * actually justified something. */ + if (first_par_line != NULL) { + cutbottom->next = last_par_line->next; + cutbottom->next->prev = cutbottom; /* The line numbers after the end of the paragraph have been * changed, so we change them back. */ - renumber(cutbottom->next); - if (first_par_line->prev != NULL) { - cutbuffer->prev = first_par_line->prev; - cutbuffer->prev->next = cutbuffer; - } else - fileage = cutbuffer; + renumber(cutbottom->next); + if (first_par_line->prev != NULL) { + cutbuffer->prev = first_par_line->prev; + cutbuffer->prev->next = cutbuffer; + } else + fileage = cutbuffer; - last_par_line->next = NULL; - free_filestruct(first_par_line); + last_par_line->next = NULL; + free_filestruct(first_par_line); + } /* Restore global variables from before the justify. */ totsize = totsize_save; diff --git a/src/nano.h b/src/nano.h index 34dbc755..98c9d0ac 100644 --- a/src/nano.h +++ b/src/nano.h @@ -434,7 +434,7 @@ typedef struct historyheadtype { #define NANO_PREVWORD_KEY NANO_ALT_SPACE #define NANO_PARABEGIN_KEY NANO_CONTROL_W #define NANO_PARAEND_KEY NANO_CONTROL_O -#define NANO_FULLJUSTIFY_KEY NANO_CONTROL_J +#define NANO_FULLJUSTIFY_KEY NANO_CONTROL_U #define NANO_VERBATIM_KEY NANO_ALT_V #ifndef NANO_SMALL diff --git a/src/proto.h b/src/proto.h index 32ac4855..abe135e3 100644 --- a/src/proto.h +++ b/src/proto.h @@ -554,8 +554,10 @@ void total_refresh(void); void display_main_list(void); void do_cursorpos(int constant); void do_cursorpos_void(void); -size_t line_len(const char *ptr); +#ifndef DISABLE_HELP +int help_line_len(const char *ptr); void do_help(void); +#endif void do_replace_highlight(int highlight_flag, const char *word); #ifdef DEBUG void dump_buffer(const filestruct *inptr); diff --git a/src/winio.c b/src/winio.c index 87e59306..70e300b5 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1669,10 +1669,8 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, } break; case NANO_CUT_KEY: - case NANO_UNCUT_KEY: /* If we're using restricted mode, the filename isn't blank, - * and we're at the "Write File" prompt, disable Cut and - * UnCut. */ + * and we're at the "Write File" prompt, disable Cut. */ if (!ISSET(RESTRICTED) || filename[0] == '\0' || s != writefile_list) { null_at(&answer, 0); xend = 0; @@ -3000,10 +2998,11 @@ void do_cursorpos_void(void) do_cursorpos(FALSE); } +#ifndef DISABLE_HELP /* Calculate the next line of help_text, starting at ptr. */ -size_t line_len(const char *ptr) +int help_line_len(const char *ptr) { - size_t j = 0; + int j = 0; while (*ptr != '\n' && *ptr != '\0' && j < COLS - 5) { ptr++; @@ -3026,7 +3025,6 @@ size_t line_len(const char *ptr) return j; } -#ifndef DISABLE_HELP /* Our dynamic, shortcut-list-compliant help function. */ void do_help(void) { @@ -3113,13 +3111,13 @@ void do_help(void) /* Calculate where in the text we should be, based on the * page. */ for (i = 0; i < line; i++) { - ptr += line_len(ptr); + ptr += help_line_len(ptr); if (*ptr == '\n') ptr++; } for (i = 0; i < editwinrows && *ptr != '\0'; i++) { - int j = line_len(ptr); + int j = help_line_len(ptr); mvwaddnstr(edit, i, 0, ptr, j); ptr += j; @@ -3130,7 +3128,8 @@ void do_help(void) skip_redisplay: kbinput = get_kbinput(edit, &meta_key); - } while (kbinput != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY); + } while (kbinput != NANO_CANCEL_KEY && kbinput != NANO_EXIT_KEY && + kbinput != NANO_EXIT_FKEY); #ifndef DISABLE_MOUSE currshortcut = oldshortcut;