From: Rocco Rutte Date: Fri, 29 May 2009 14:40:40 +0000 (+0200) Subject: Fall back to search if no query exists for search-(next|opposite) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=816723e1e09f6073d7ade541df4e5402fe8147d6;p=neomutt Fall back to search if no query exists for search-(next|opposite) The pager had the fall-through to search, so for consistency do that in other menues as well. --- diff --git a/menu.c b/menu.c index 7fe753886..b562891e9 100644 --- a/menu.c +++ b/menu.c @@ -725,27 +725,21 @@ static int menu_search (MUTTMENU *menu, int op) char* searchBuf = menu->menu >= 0 && menu->menu < MENU_MAX ? SearchBuffers[menu->menu] : NULL; - if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE) + if (!(searchBuf && *searchBuf) || + (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE)) { - strfcpy (buf, searchBuf ? searchBuf : "", sizeof (buf)); - if (mutt_get_field ((op == OP_SEARCH) ? _("Search for: ") : - _("Reverse search for: "), - buf, sizeof (buf), M_CLEAR) != 0 || !buf[0]) + strfcpy (buf, searchBuf && *searchBuf ? searchBuf : "", sizeof (buf)); + if (mutt_get_field ((op == OP_SEARCH || op == OP_SEARCH_NEXT) + ? _("Search for: ") : _("Reverse search for: "), + buf, sizeof (buf), M_CLEAR) != 0 || !buf[0]) return (-1); if (menu->menu >= 0 && menu->menu < MENU_MAX) { mutt_str_replace (&SearchBuffers[menu->menu], buf); searchBuf = SearchBuffers[menu->menu]; } - menu->searchDir = (op == OP_SEARCH) ? M_SEARCH_DOWN : M_SEARCH_UP; - } - else - { - if (!searchBuf || !*searchBuf) - { - mutt_error _("No search pattern."); - return (-1); - } + menu->searchDir = (op == OP_SEARCH || op == OP_SEARCH_NEXT) ? + M_SEARCH_DOWN : M_SEARCH_UP; } searchDir = (menu->searchDir == M_SEARCH_UP) ? -1 : 1; diff --git a/pager.c b/pager.c index e67af057e..217652b1c 100644 --- a/pager.c +++ b/pager.c @@ -1567,7 +1567,7 @@ static struct mapping_t PagerHelpExtra[] = { int mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) { - static char searchbuf[STRING]; + static char searchbuf[STRING] = ""; char buffer[LONG_STRING]; char helpstr[SHORT_STRING*2]; char tmphelp[SHORT_STRING*2]; diff --git a/pattern.c b/pattern.c index 5d8a85b55..5581fb673 100644 --- a/pattern.c +++ b/pattern.c @@ -1401,15 +1401,17 @@ int mutt_search_command (int cur, int op) progress_t progress; const char* msg = NULL; - if (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE) + if (!(LastSearch && *LastSearch) || + (op != OP_SEARCH_NEXT && op != OP_SEARCH_OPPOSITE)) { - strfcpy (buf, LastSearch, sizeof (buf)); - if (mutt_get_field ((op == OP_SEARCH) ? _("Search for: ") : - _("Reverse search for: "), buf, sizeof (buf), + strfcpy (buf, LastSearch && *LastSearch ? LastSearch : "", sizeof (buf)); + if (mutt_get_field ((op == OP_SEARCH || op == OP_SEARCH_NEXT) ? + _("Search for: ") : _("Reverse search for: "), + buf, sizeof (buf), M_CLEAR | M_PATTERN) != 0 || !buf[0]) return (-1); - if (op == OP_SEARCH) + if (op == OP_SEARCH || op == OP_SEARCH_NEXT) unset_option (OPTSEARCHREVERSE); else set_option (OPTSEARCHREVERSE); @@ -1420,7 +1422,7 @@ int mutt_search_command (int cur, int op) mutt_check_simple (temp, sizeof (temp), NONULL (SimpleSearch)); if (!SearchPattern || mutt_strcmp (temp, LastSearchExpn)) - { + { set_option (OPTSEARCHINVALID); strfcpy (LastSearch, buf, sizeof (LastSearch)); mutt_message _("Compiling search pattern..."); @@ -1428,18 +1430,13 @@ int mutt_search_command (int cur, int op) err.data = error; err.dsize = sizeof (error); if ((SearchPattern = mutt_pattern_comp (temp, M_FULL_MSG, &err)) == NULL) - { + { mutt_error ("%s", error); return (-1); } mutt_clear_error (); } } - else if (!SearchPattern) - { - mutt_error _("No search pattern."); - return (-1); - } if (option (OPTSEARCHINVALID)) {