From 6f36cc9644ba86fff89f7bb8907a94fc5dca6ee4 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 4 Oct 2013 11:34:57 -0700 Subject: [PATCH] default to the next unread folder It means that for example: macro index R will for as expected. Signed-off-by: Karel Zak --- buffy.c | 34 +++++++++++++++++++++++++++++++++- buffy.h | 1 + curs_main.c | 4 ++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/buffy.c b/buffy.c index a5bbda9d9..1151547d1 100644 --- a/buffy.c +++ b/buffy.c @@ -669,8 +669,11 @@ static void buffy_check(BUFFY *tmp, struct stat *contex_sb) tmp->msg_unread = 0; tmp->msg_flagged = 0; nm_nonctx_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread); - if (tmp->msg_unread > 0) + if (tmp->msg_unread > 0) { BuffyCount++; + tmp->new = 1; + } + sb_set_update_time(); break; #endif } @@ -857,6 +860,35 @@ void mutt_buffy (char *s, size_t slen) *s = '\0'; } +#ifdef USE_NOTMUCH +void mutt_buffy_vfolder (char *s, size_t slen) +{ + BUFFY *tmp; + int pass, found = 0; + + if (mutt_buffy_check (0)) + { + for (pass = 0; pass < 2; pass++) { + for (tmp = VirtIncoming; tmp; tmp = tmp->next) + { + if ((found || pass) && tmp->new) + { + strfcpy (s, tmp->desc, slen); + return; + } + if (mutt_strcmp (s, tmp->path) == 0) + found = 1; + } + } + + mutt_buffy_check (1); /* buffy was wrong - resync things */ + } + + /* no folders with new mail */ + *s = '\0'; +} +#endif + /* fetch buffy object for given path, if present */ static BUFFY* buffy_get (const char *path) { diff --git a/buffy.h b/buffy.h index 9e3053c7f..0c491d959 100644 --- a/buffy.h +++ b/buffy.h @@ -54,6 +54,7 @@ WHERE short BuffyTimeout INITVAL (3); #ifdef USE_NOTMUCH WHERE BUFFY *VirtIncoming INITVAL (0); +void mutt_buffy_vfolder (char *s, size_t slen); #endif extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ diff --git a/curs_main.c b/curs_main.c index 5765217ad..00c2e6adb 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1536,6 +1536,10 @@ int mutt_index_menu (void) } #ifdef USE_NOTMUCH else if (op == OP_MAIN_CHANGE_VFOLDER) { + if (Context->magic == M_NOTMUCH) { + strfcpy(buf, Context->path, sizeof (buf)); + mutt_buffy_vfolder (buf, sizeof (buf)); + } mutt_enter_vfolder (cp, buf, sizeof (buf), &menu->redraw, 1); if (!buf[0]) { -- 2.50.0