diff --git a/ChangeLog b/ChangeLog index e61685bcf601e9cfefa67a958d83754a0cbe41ce..c0e720d93436634707c7e5c87d722985f83e4ee3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -70,6 +70,11 @@ CVS code - text and the first and last file in the file browser via Meta-\ (Meta-|) and Meta-/ (Meta-?). Changes to do_browser(), shortcut_init(), and do_help(). (DLR) + - Allow unjustifying if we resize the window immediately after + justifying, as Pico does, and make input handling across + resizes more consistent. Changes to handle_sigwinch(), + main(), get_kbinput(), parse_kbinput(), get_byte_kbinput(), + and get_unicode_kbinput(); removal of reset_kbinput(). (DLR) - browser.c: do_browser() - Reference NANO_GOTODIR_(ALT|F)?KEY instead of diff --git a/src/global.c b/src/global.c index a6a09b54f11d392e1f534fb7f5878969cb5b9d6d..969218d80bf3f8e1c91a8509a1a6f5c5df34b170 100644 --- a/src/global.c +++ b/src/global.c @@ -23,7 +23,13 @@ #include "proto.h" -/* Global variables */ +/* Global variables. */ +#ifndef NANO_TINY +sigjmp_buf jmpbuf; + /* Used to return to main() or the unjustify routine in + * do_justify() after a SIGWINCH. */ +#endif + #ifndef DISABLE_WRAPJUSTIFY ssize_t fill = 0; /* The column where we will wrap lines. */ @@ -188,7 +194,7 @@ filestruct *replacebot = NULL; /* The bottom of the replace string history list. */ #endif -/* Regular expressions */ +/* Regular expressions. */ #ifdef HAVE_REGEX_H regex_t search_regexp; /* The compiled regular expression to use in searches. */ diff --git a/src/nano.c b/src/nano.c index 43f8e52d108cd9d1528604b3fb3651f365b34301..0dcdcba6ddd768fe65058e8b0144dce012cb81a9 100644 --- a/src/nano.c +++ b/src/nano.c @@ -40,10 +40,6 @@ #include <getopt.h> #endif -#ifndef NANO_TINY -#include <setjmp.h> -#endif - #ifdef ENABLE_NANORC static bool no_rcfiles = FALSE; /* Should we ignore all rcfiles? */ @@ -53,11 +49,6 @@ static struct termios oldterm; static struct sigaction act; /* For all our fun signal handlers. */ -#ifndef NANO_TINY -static sigjmp_buf jmpbuf; - /* Used to return to main() after a SIGWINCH. */ -#endif - /* Create a new filestruct node. Note that we specifically do not set * prevnode->next equal to the new line. */ filestruct *make_new_node(filestruct *prevnode) @@ -1060,16 +1051,6 @@ RETSIGTYPE handle_sigwinch(int signal) if (filepart != NULL) unpartition_filestruct(&filepart); -#ifndef DISABLE_JUSTIFY - /* If the justify buffer isn't empty, blow away the text in it and - * display the shortcut list with UnCut. */ - if (jusbuffer != NULL) { - free_filestruct(jusbuffer); - jusbuffer = NULL; - shortcut_init(FALSE); - } -#endif - #ifdef USE_SLANG /* Slang curses emulation brain damage, part 1: If we just do what * curses does here, it'll only work properly if the resize made the @@ -1100,9 +1081,6 @@ RETSIGTYPE handle_sigwinch(int signal) currshortcut = main_list; total_refresh(); - /* Reset all the input routines that rely on character sequences. */ - reset_kbinput(); - /* Jump back to the main loop. */ siglongjmp(jmpbuf, 1); } @@ -2147,11 +2125,6 @@ int main(int argc, char **argv) display_main_list(); -#ifndef NANO_TINY - /* Return here after a SIGWINCH. */ - sigsetjmp(jmpbuf, 1); -#endif - display_buffer(); while (TRUE) { @@ -2160,6 +2133,11 @@ int main(int argc, char **argv) /* Make sure the cursor is in the edit window. */ reset_cursor(); +#ifndef NANO_TINY + /* Return here after a SIGWINCH. */ + sigsetjmp(jmpbuf, 1); +#endif + /* If constant cursor position display is on, and there are no * keys waiting in the input buffer, display the current cursor * position on the statusbar. */ diff --git a/src/nano.h b/src/nano.h index 2a0e9c3c20ac6adc29acc322367919405f0f4a4c..093717b1360c47d12cc98aa2a8b2526d0710efef 100644 --- a/src/nano.h +++ b/src/nano.h @@ -100,6 +100,9 @@ #ifdef HAVE_REGEX_H #include <regex.h> #endif +#ifndef NANO_TINY +#include <setjmp.h> +#endif #include <assert.h> /* If no vsnprintf(), use the version from glib 2.x. */ @@ -412,6 +415,7 @@ typedef struct rcoption { #define NANO_CONTROL_7 31 #define NANO_CONTROL_8 127 +/* Meta key sequences. */ #define NANO_ALT_SPACE ' ' #define NANO_ALT_LPARENTHESIS '(' #define NANO_ALT_RPARENTHESIS ')' @@ -607,11 +611,12 @@ typedef struct rcoption { #define TOGGLE_MAC_KEY NANO_ALT_M #endif /* !NANO_TINY */ -#define MAIN_VISIBLE 12 - #define VIEW TRUE #define NOVIEW FALSE +/* The maximum number of entries displayed in the main shortcut list. */ +#define MAIN_VISIBLE 12 + /* The minimum editor window columns and rows required for nano to work * correctly. */ #define MIN_EDITOR_COLS 4 diff --git a/src/proto.h b/src/proto.h index c373e0d82a75f7cd96e43ea68ab50a22349f20c1..0552a3ab4b3c5ea492fc92473d4604df57e94a3d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -27,6 +27,10 @@ #include "nano.h" /* Public externs. See global.c for descriptions of them. */ +#ifndef NANO_TINY +extern sigjmp_buf jmpbuf; +#endif + #ifndef DISABLE_WRAPJUSTIFY extern ssize_t fill; extern ssize_t wrap_at; @@ -708,33 +712,18 @@ void dump_filestruct_reverse(void); #endif /* Public functions in winio.c. */ -#ifndef NANO_TINY -void reset_kbinput(void); -#endif void get_key_buffer(WINDOW *win); size_t get_key_buffer_len(void); void unget_input(int *input, size_t input_len); void unget_kbinput(int kbinput, bool meta_key, bool func_key); int *get_input(WINDOW *win, size_t input_len); int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key); -int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key -#ifndef NANO_TINY - , bool reset -#endif - ); +int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key); int get_escape_seq_kbinput(const int *seq, size_t seq_len, bool *ignore_seq); int get_escape_seq_abcd(int kbinput); -int get_byte_kbinput(int kbinput -#ifndef NANO_TINY - , bool reset -#endif - ); -long get_unicode_kbinput(int kbinput -#ifndef NANO_TINY - , bool reset -#endif - ); +int get_byte_kbinput(int kbinput); +long get_unicode_kbinput(int kbinput); int get_control_kbinput(int kbinput); void unparse_kbinput(char *output, size_t output_len); int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len); diff --git a/src/text.c b/src/text.c index 70978930f9e17d5d6727ce270a4d00fc0c84eabf..4b6fa325b4202f7e9cd5a9aff86b336943e738a9 100644 --- a/src/text.c +++ b/src/text.c @@ -1655,6 +1655,11 @@ void do_justify(bool full_justify) edit_refresh(); +#ifndef NANO_TINY + /* Return here after a SIGWINCH. */ + sigsetjmp(jmpbuf, 1); +#endif + statusbar(_("Can now UnJustify!")); /* If constant cursor position display is on, make sure the current diff --git a/src/winio.c b/src/winio.c index 62875e69e2c1ef40ae6e2c3243c2174d09402f63..edabd33c35604ea8ae74748c480b199f565e682a 100644 --- a/src/winio.c +++ b/src/winio.c @@ -106,16 +106,6 @@ static bool disable_cursorpos = FALSE; * Note that Center (5) on the numeric keypad with NumLock off can also * be the Begin key. */ -#ifndef NANO_TINY -/* Reset all the input routines that rely on character sequences. */ -void reset_kbinput(void) -{ - parse_kbinput(NULL, NULL, NULL, TRUE); - get_byte_kbinput(0, TRUE); - get_unicode_kbinput(0, TRUE); -} -#endif - /* Read in a sequence of keystrokes from win and save them in the * default keystroke buffer. This should only be called when the * default keystroke buffer is empty. */ @@ -327,11 +317,7 @@ int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key) /* Read in a character and interpret it. Continue doing this until * we get a recognized value or sequence. */ - while ((kbinput = parse_kbinput(win, meta_key, func_key -#ifndef NANO_TINY - , FALSE -#endif - )) == ERR); + while ((kbinput = parse_kbinput(win, meta_key, func_key)) == ERR); return kbinput; } @@ -340,24 +326,11 @@ int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key) * sequences into their corresponding key values. Set meta_key to TRUE * when we get a meta key sequence, and set func_key to TRUE when we get * a function key. Assume nodelay(win) is FALSE. */ -int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key -#ifndef NANO_TINY - , bool reset -#endif - ) - +int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) { static int escapes = 0, byte_digits = 0; int *kbinput, retval = ERR; -#ifndef NANO_TINY - if (reset) { - escapes = 0; - byte_digits = 0; - return ERR; - } -#endif - *meta_key = FALSE; *func_key = FALSE; @@ -584,11 +557,7 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key int byte; byte_digits++; - byte = get_byte_kbinput(*kbinput -#ifndef NANO_TINY - , FALSE -#endif - ); + byte = get_byte_kbinput(*kbinput); if (byte != ERR) { char *byte_mb; @@ -1193,23 +1162,11 @@ int get_escape_seq_abcd(int kbinput) /* Translate a byte sequence: turn a three-digit decimal number from * 000 to 255 into its corresponding byte value. */ -int get_byte_kbinput(int kbinput -#ifndef NANO_TINY - , bool reset -#endif - ) +int get_byte_kbinput(int kbinput) { static int byte_digits = 0, byte = 0; int retval = ERR; -#ifndef NANO_TINY - if (reset) { - byte_digits = 0; - byte = 0; - return ERR; - } -#endif - /* Increment the byte digit counter. */ byte_digits++; @@ -1277,24 +1234,12 @@ int get_byte_kbinput(int kbinput /* Translate a Unicode sequence: turn a six-digit hexadecimal number * from 000000 to 10FFFF (case-insensitive) into its corresponding * multibyte value. */ -long get_unicode_kbinput(int kbinput -#ifndef NANO_TINY - , bool reset -#endif - ) +long get_unicode_kbinput(int kbinput) { static int uni_digits = 0; static long uni = 0; long retval = ERR; -#ifndef NANO_TINY - if (reset) { - uni_digits = 0; - uni = 0; - return ERR; - } -#endif - /* Increment the Unicode digit counter. */ uni_digits++; @@ -1499,11 +1444,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) while ((kbinput = get_input(win, 1)) == NULL); /* Check whether the first keystroke is a hexadecimal digit. */ - uni = get_unicode_kbinput(*kbinput -#ifndef NANO_TINY - , FALSE -#endif - ); + uni = get_unicode_kbinput(*kbinput); /* If the first keystroke isn't a hexadecimal digit, put back the * first keystroke. */ @@ -1518,11 +1459,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len) while (uni == ERR) { while ((kbinput = get_input(win, 1)) == NULL); - uni = get_unicode_kbinput(*kbinput -#ifndef NANO_TINY - , FALSE -#endif - ); + uni = get_unicode_kbinput(*kbinput); } /* Put back the multibyte equivalent of the Unicode value. */