diff --git a/ChangeLog b/ChangeLog index 28e14ea..6d1283f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2014-04-11 Andrew Ho + * Add bracket flashing. + 2010-11-15 Chris Allegretta * Add a section to the FAQ about using nanorc on Win32 systems. diff --git a/NEWS b/NEWS index bd73632..0f2b4d4 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +2014.04.11 - GNU nano 2.2.6p adds bracket flashing to nano 2.2.6. + 2010.11.22 - GNU nano 2.2.6 "Pimp my BBS" wants you to go to www.desertbus.org and donate a few bucks for the great Child's Play Charity! This is just a small release to diff --git a/configure b/configure index 238dbf9..f2447f5 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.65 for GNU nano 2.2.6. +# Generated by GNU Autoconf 2.65 for GNU nano 2.2.6p. # # Report bugs to . # @@ -552,8 +552,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='GNU nano' PACKAGE_TARNAME='nano' -PACKAGE_VERSION='2.2.6' -PACKAGE_STRING='GNU nano 2.2.6' +PACKAGE_VERSION='2.2.6p' +PACKAGE_STRING='GNU nano 2.2.6p' PACKAGE_BUGREPORT='nano-devel@gnu.org' PACKAGE_URL='http://www.gnu.org/software/nano/' @@ -1300,7 +1300,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures GNU nano 2.2.6 to adapt to many kinds of systems. +\`configure' configures GNU nano 2.2.6p to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1371,7 +1371,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of GNU nano 2.2.6:";; + short | recursive ) echo "Configuration of GNU nano 2.2.6p:";; esac cat <<\_ACEOF @@ -1492,7 +1492,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -GNU nano configure 2.2.6 +GNU nano configure 2.2.6p generated by GNU Autoconf 2.65 Copyright (C) 2009 Free Software Foundation, Inc. @@ -1863,7 +1863,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by GNU nano $as_me 2.2.6, which was +It was created by GNU nano $as_me 2.2.6p, which was generated by GNU Autoconf 2.65. Invocation command line was $ $0 $@ @@ -2782,7 +2782,7 @@ fi # Define the identity of the package. PACKAGE='nano' - VERSION='2.2.6' + VERSION='2.2.6p' cat >>confdefs.h <<_ACEOF @@ -8884,7 +8884,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by GNU nano $as_me 2.2.6, which was +This file was extended by GNU nano $as_me 2.2.6p, which was generated by GNU Autoconf 2.65. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -8952,7 +8952,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -GNU nano config.status 2.2.6 +GNU nano config.status 2.2.6p configured by $0, generated by GNU Autoconf 2.65, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 6388c03..14193a3 100644 --- a/configure.ac +++ b/configure.ac @@ -20,7 +20,7 @@ # # $Id: configure.ac 4516 2010-08-11 02:42:32Z astyanax $ -AC_INIT([GNU nano], [2.2.6], [nano-devel@gnu.org], [nano]) +AC_INIT([GNU nano], [2.2.6p], [nano-devel@gnu.org], [nano]) AC_CONFIG_SRCDIR([src/nano.c]) AC_CANONICAL_TARGET([]) AM_INIT_AUTOMAKE diff --git a/src/global.c b/src/global.c index ae14a49..5658923 100644 --- a/src/global.c +++ b/src/global.c @@ -86,6 +86,10 @@ openfilestruct *openfile = NULL; char *matchbrackets = NULL; /* The opening and closing brackets that can be found by bracket * searches. */ +char *flashbrackets = NULL; + /* The closing brackets that we will flash open brackets for. */ +int flashed = FALSE; + /* Whether we just flashed a bracket or not. */ #endif #if !defined(NANO_TINY) && defined(ENABLE_NANORC) diff --git a/src/nano.c b/src/nano.c index e4e2222..873ba0a 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1644,6 +1644,16 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool reset_multis(openfile->current, FALSE); } #endif + +#ifndef NANO_TINY + /* If we previously flashed a bracket, + * redraw to un-highlight it. */ + if (flashed == TRUE) { + edit_refresh_needed = TRUE; + flashed = FALSE; + } +#endif + if (edit_refresh_needed) { #ifdef DEBUG fprintf(stderr, "running edit_refresh() as edit_refresh_needed is true\n"); @@ -2006,11 +2016,31 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) #ifdef ENABLE_COLOR reset_multis(openfile->current, FALSE); #endif + +#ifndef NANO_TINY + /* If we previously flashed a bracket, redraw to un-highlight it. */ + if (flashed == TRUE) { + edit_refresh(); + edit_refresh_needed = FALSE; + flashed = FALSE; + } +#endif + if (edit_refresh_needed == TRUE) { edit_refresh(); edit_refresh_needed = FALSE; } else update_line(openfile->current, openfile->current_x); + +#ifndef NANO_TINY + /* If input was a close bracket, highlight it. */ + if (output_len == 1 && output[0] && strchr(flashbrackets, output[0])) { + assert(openfile->current_x > 0); + openfile->current_x--; + do_flash_bracket(); + openfile->current_x++; + } +#endif } int main(int argc, char **argv) @@ -2513,6 +2543,11 @@ int main(int argc, char **argv) /* If matchbrackets wasn't specified, set its default value. */ if (matchbrackets == NULL) matchbrackets = mallocstrcpy(NULL, "(<[{)>]}"); + + /* Set default for closing brackets we will flash opening brackets for. */ + if (flashbrackets == NULL) + flashbrackets = mallocstrcpy(NULL, ")]}"); + flashed = FALSE; #endif #if !defined(NANO_TINY) && defined(ENABLE_NANORC) diff --git a/src/proto.h b/src/proto.h index e05eefe..7ad8c6d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -58,6 +58,8 @@ extern openfilestruct *openfile; #ifndef NANO_TINY extern char *matchbrackets; +extern char *flashbrackets; +extern int flashed; #endif #if !defined(NANO_TINY) && defined(ENABLE_NANORC) @@ -601,6 +603,8 @@ void do_gotopos(ssize_t pos_line, size_t pos_x, ssize_t pos_y, size_t #ifndef NANO_TINY bool find_bracket_match(bool reverse, const char *bracket_set); void do_find_bracket(void); +void do_flash_bracket(void); +void do_find_or_flash_bracket(int); #ifdef ENABLE_NANORC bool history_has_changed(void); #endif @@ -783,6 +787,7 @@ void display_main_list(void); void do_cursorpos(bool constant); void do_cursorpos_void(void); void do_replace_highlight(bool highlight, const char *word); +void highlight_char(WINDOW *win, int y, int x, char c); const char *flagtostr(int flag); const subnfunc *sctofunc(sc *s); const subnfunc *getfuncfromkey(WINDOW *win); diff --git a/src/search.c b/src/search.c index 4b93045..24c5a1b 100644 --- a/src/search.c +++ b/src/search.c @@ -1175,10 +1175,19 @@ bool find_bracket_match(bool reverse, const char *bracket_set) /* Search for a match to the bracket at the current cursor position, if * there is one. */ -void do_find_bracket(void) +void do_find_bracket(void) { + do_find_or_flash_bracket(0); +} + +void do_flash_bracket(void) { + do_find_or_flash_bracket(1); +} + +void do_find_or_flash_bracket(int is_flash) { filestruct *current_save; - size_t current_x_save, pww_save; + size_t current_x_save, pww_save, ps_save; + ssize_t lineno_save; const char *ch; /* The location in matchbrackets of the bracket at the current * cursor position. */ @@ -1219,6 +1228,8 @@ void do_find_bracket(void) current_save = openfile->current; current_x_save = openfile->current_x; pww_save = openfile->placewewant; + ps_save = get_page_start(xplustabs() + 1); + lineno_save = openfile->current->lineno; /* If we're on an opening bracket, which must be in the first half * of matchbrackets, we want to search forwards for a closing @@ -1269,10 +1280,42 @@ void do_find_bracket(void) found_ch, NULL); count += (strncmp(found_ch, ch, ch_len) == 0) ? 1 : -1; - /* If count is zero, we've found a matching bracket. Update - * the screen and get out. */ + /* If count is zero, we've found a matching bracket. */ if (count == 0) { - edit_redraw(current_save, pww_save); + if (is_flash) { + /* If we are flashing, highlight matching bracket, + * then restore where we were. */ + ssize_t lineno = openfile->current->lineno; + size_t ps = get_page_start(openfile->placewewant); + if (lineno < openfile->edittop->lineno || + lineno >= openfile->edittop->lineno + maxrows || + (lineno == lineno_save && xplustabs() < ps_save) || + (lineno != lineno_save && + openfile->placewewant >= COLS)) { + /* Off screen, so just update statusbar. */ + if (lineno == lineno_save) { + statusbar(_("Matched col %ld: %s"), + xplustabs() + 1, + openfile->current->data); + } else { + statusbar(_("Matched line %ld: %s"), + openfile->current->lineno, + openfile->current->data); + } + } else { + /* Screen just shifted, calculate new x position. */ + int y = openfile->current_y; + int x = openfile->placewewant - ps_save; + highlight_char(edit, y, x, found_ch[0]); + flashed = TRUE; + } + openfile->current = current_save; + openfile->current_x = current_x_save; + openfile->placewewant = pww_save; + } else { + /* If not flashing, move cursor to matching bracket. */ + edit_redraw(current_save, pww_save); + } break; } } else { diff --git a/src/winio.c b/src/winio.c index 1aef2a9..fa66cb5 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3419,6 +3419,14 @@ void do_replace_highlight(bool highlight, const char *word) wattroff(edit, reverse_attr); } +/* Highlight a character */ +void highlight_char(WINDOW *win, int y, int x, char c) { + wmove(win, y, x); + wattron(win, A_REVERSE); + waddch(win, c); + wattroff(win, A_REVERSE); +} + #ifdef NANO_EXTRA #define CREDIT_LEN 55 #define XLCREDIT_LEN 8