From a30eb78006b3c0e5b7744a6b8412e6d5d7164b23 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Mon, 9 Feb 2009 04:03:20 +0000 Subject: [PATCH] 2009-02-09 Chris Allegretta * New option -q, --quiet, rcfile option "quiet" implemented. Skips printing errors about the rcfile and asking user to press enter. Also, nano should now only ask for one enter press when there is an error when not using -q. Based on discussion between Eitan Adler and Mike Frysinger. * rcfile.c (parse_keybinding) - Significant cleanups and fixes for detecting and reporting errors in key bindings code. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4374 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 8 ++++++++ doc/man/nano.1 | 4 ++++ doc/man/nanorc.5 | 5 +++++ src/nano.c | 10 ++++++++-- src/nano.h | 1 + src/rcfile.c | 49 +++++++++++++++++++++++++----------------------- 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index ea83190b..1628c2a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-02-09 Chris Allegretta + * New option -q, --quiet, rcfile option "quiet" implemented. Skips printing + errors about the rcfile and asking user to press enter. Also, nano should + now only ask for one enter press when there is an error when not using -q. + Based on discussion between Eitan Adler and Mike Frysinger. + * rcfile.c (parse_keybinding) - Significant cleanups and fixes for + detecting and reporting errors in key bindings code. + 2009-02-08 Chris Allegretta * Make reset_multidata reset more lines, since contrary to previous problems the syntax highlting is now too *un*ambitious, causing display glitches when diff --git a/doc/man/nano.1 b/doc/man/nano.1 index 04e2722a..2a08983f 100644 --- a/doc/man/nano.1 +++ b/doc/man/nano.1 @@ -172,6 +172,10 @@ chroot. Preserve the XON and XOFF sequences (^Q and ^S) so they will be caught by the terminal. .TP +.B \-q (\-\-quiet) +Do not report errors in the nanorc file and ask them to +be acknowledged by pressing enter at startup. +.TP .B \-r \fIcols\fP (\-\-fill=\fIcols\fP) Wrap lines at column \fIcols\fP. If this value is 0 or less, wrapping will occur at the width of the screen less \fIcols\fP columns, allowing diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index 35d18820..31fdf44e 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -145,6 +145,11 @@ paragraphs. They cannot contain blank characters. Only closing punctuation, optionally followed by closing brackets, can end sentences. The default value is "\fI!.?\fP". .TP +.B set/unset quiet +\fBnano\fP will not report errors in the nanorc file and ask them to +be acknowledged by pressing enter at startup. If this is used it should +be placed at the top of the file to be fully effective. +.TP .B set/unset quickblank Do quick statusbar blanking. Statusbar messages will disappear after 1 keystroke instead of 25. diff --git a/src/nano.c b/src/nano.c index 3d3bbfe6..2d01995b 100644 --- a/src/nano.c +++ b/src/nano.c @@ -879,6 +879,8 @@ void usage(void) #endif print_opt("-p", "--preserve", N_("Preserve XON (^Q) and XOFF (^S) keys")); + print_opt("-q", "--quiet", + N_("Silently ignore startup issues like rc file errors")); #ifndef DISABLE_WRAPJUSTIFY print_opt(_("-r <#cols>"), _("--fill=<#cols>"), N_("Set wrapping point at column #cols")); @@ -1930,6 +1932,7 @@ int main(int argc, char **argv) {"operatingdir", 1, NULL, 'o'}, #endif {"preserve", 0, NULL, 'p'}, + {"quiet", 0, NULL, 'q'}, #ifndef DISABLE_WRAPJUSTIFY {"fill", 1, NULL, 'r'}, #endif @@ -1993,11 +1996,11 @@ int main(int argc, char **argv) while ((optchr = #ifdef HAVE_GETOPT_LONG getopt_long(argc, argv, - "h?ABC:DEFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz", + "h?ABC:DEFHIKLNOQ:RST:UVWY:abcdefgijklmo:pqr:s:tvwxz", long_options, NULL) #else getopt(argc, argv, - "h?ABC:DEFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz") + "h?ABC:DEFHIKLNOQ:RST:UVWY:abcdefgijklmo:pqr:s:tvwxz") #endif ) != -1) { switch (optchr) { @@ -2125,6 +2128,9 @@ int main(int argc, char **argv) case 'p': SET(PRESERVE); break; + case 'q': + SET(QUIET); + break; #ifndef DISABLE_WRAPJUSTIFY case 'r': if (!parse_num(optarg, &wrap_at)) { diff --git a/src/nano.h b/src/nano.h index 0d725de5..039bb3ee 100644 --- a/src/nano.h +++ b/src/nano.h @@ -471,6 +471,7 @@ typedef struct subnfunc { #define WORD_BOUNDS (1<<28) #define NO_NEWLINES (1<<29) #define BOLD_TEXT (1<<30) +#define QUIET (1<<31) /* Flags for which menus in which a given function should be present */ #define MMAIN (1<<0) diff --git a/src/rcfile.c b/src/rcfile.c index d0d985c1..dd4c059e 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -84,6 +84,7 @@ static const rcoption rcopts[] = { {"historylog", HISTORYLOG}, {"matchbrackets", 0}, {"noconvert", NO_CONVERT}, + {"quiet", QUIET}, {"quickblank", QUICK_BLANK}, {"smarthome", SMART_HOME}, {"smooth", SMOOTH_SCROLL}, @@ -117,6 +118,9 @@ void rcfile_error(const char *msg, ...) { va_list ap; + if (ISSET(QUIET)) + return; + fprintf(stderr, "\n"); if (lineno > 0) { errors = TRUE; @@ -388,41 +392,41 @@ void parse_keybinding(char *ptr) if (keycopy[0] != 'M' && keycopy[0] != '^' && keycopy[0] != 'F' && keycopy[0] != 'K') { rcfile_error( - N_("keybindings must begin with \"^\", \"M\", or \"F\"\n")); + N_("keybindings must begin with \"^\", \"M\", or \"F\"")); return; } funcptr = ptr; ptr = parse_next_word(ptr); - if (funcptr == NULL) { + if (!strcmp(funcptr, "")) { rcfile_error( - N_("Must specify function to bind key to\n")); + N_("Must specify function to bind key to")); return; } menuptr = ptr; ptr = parse_next_word(ptr); - if (menuptr == NULL) { + if (!strcmp(menuptr, "")) { rcfile_error( /* Note to translators, do not translate the word "all" in the sentence below, everything else is fine */ - N_("Must specify menu bind key to (or \"all\")\n")); - return; - } - - menu = strtomenu(menuptr); - if (menu < 1) { - rcfile_error( - N_("Could not map name \"%s\" to a menu\n"), menuptr); + N_("Must specify menu to bind key to (or \"all\")")); return; } newsc = strtosc(menu, funcptr); if (newsc == NULL) { rcfile_error( - N_("Could not map name \"%s\" to a function\n"), funcptr); + N_("Could not map name \"%s\" to a function"), funcptr); + return; + } + + menu = strtomenu(menuptr); + if (menu < 1) { + rcfile_error( + N_("Could not map name \"%s\" to a menu"), menuptr); return; } @@ -444,7 +448,7 @@ void parse_keybinding(char *ptr) if (check_bad_binding(newsc)) { rcfile_error( - N_("Sorry, keystr \"%s\" is an illegal binding\n"), newsc->keystr); + N_("Sorry, keystr \"%s\" is an illegal binding"), newsc->keystr); return; } @@ -1057,15 +1061,6 @@ void parse_rcfile(FILE *rcstream lineno = 0; check_vitals_mapped(); - - if (errors) { - errors = FALSE; - fprintf(stderr, - _("\nPress Enter to continue starting nano.\n")); - while (getchar() != '\n') - ; - } - return; } @@ -1146,6 +1141,14 @@ void do_rcfile(void) free(nanorc); nanorc = NULL; + if (errors && !ISSET(QUIET)) { + errors = FALSE; + fprintf(stderr, + _("\nPress Enter to continue starting nano.\n")); + while (getchar() != '\n') + ; + } + #ifdef ENABLE_COLOR set_colorpairs(); #endif