From: David Sterba Date: Thu, 24 May 2012 13:34:53 +0000 (+0200) Subject: main: add command to limit to only current thread X-Git-Tag: neomutt-20160404~8^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=17b056433727144787b1630f870d19b5a2a5d484;p=neomutt main: add command to limit to only current thread Add command to limit view on the thread from any of its message. Predefined on command L, though the lowercase 'l' would be better (less keystrokes), but it's already occupied by a not-so-useful command "show limit". Tested on large folders, no performance problems observed. Search in current thread is not implemented. Signed-off-by: David Sterba --- diff --git a/OPS b/OPS index 8414a8b33..659c50f2f 100644 --- a/OPS +++ b/OPS @@ -176,6 +176,7 @@ OP_VERSION "show the Mutt version number and date" OP_VIEW_ATTACH "view attachment using mailcap entry if necessary" OP_VIEW_ATTACHMENTS "show MIME attachments" OP_WHAT_KEY "display the keycode for a key press" +OP_LIMIT_CURRENT_THREAD "limit view to current thread" OP_MAIN_SHOW_LIMIT "show currently active limit pattern" OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread" OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads" diff --git a/curs_main.c b/curs_main.c index a76aac998..92ac49efb 100644 --- a/curs_main.c +++ b/curs_main.c @@ -904,12 +904,14 @@ int mutt_index_menu (void) } break; + case OP_LIMIT_CURRENT_THREAD: case OP_MAIN_LIMIT: CHECK_IN_MAILBOX; menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : -1; - if (mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0) + if ((op == OP_LIMIT_CURRENT_THREAD && mutt_limit_current_thread(CURHDR)) + || (op == OP_MAIN_LIMIT && mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)) { if (menu->oldcurrent >= 0) { diff --git a/functions.h b/functions.h index 7a1c5a9f1..b70d4d888 100644 --- a/functions.h +++ b/functions.h @@ -114,6 +114,7 @@ const struct binding_t OpMain[] = { /* map: index */ { "next-undeleted", OP_MAIN_NEXT_UNDELETED, "j" }, { "previous-undeleted", OP_MAIN_PREV_UNDELETED, "k" }, { "limit", OP_MAIN_LIMIT, "l" }, + { "limit-current-thread", OP_LIMIT_CURRENT_THREAD, "\033L" }, { "link-threads", OP_MAIN_LINK_THREADS, "&" }, { "list-reply", OP_LIST_REPLY, "L" }, { "mail", OP_MAIL, "m" }, diff --git a/mutt_menu.h b/mutt_menu.h index 8192019e2..ee341f699 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -115,4 +115,6 @@ int mutt_menuLoop (MUTTMENU *); void index_make_entry (char *, size_t, struct menu_t *, int); int index_color (int); +int mutt_limit_current_thread (HEADER *h); + #endif /* _MUTT_MENU_H_ */ diff --git a/pattern.c b/pattern.c index d954cdc3b..c6abc1dca 100644 --- a/pattern.c +++ b/pattern.c @@ -1294,6 +1294,51 @@ void mutt_check_simple (char *s, size_t len, const char *simple) } } +static THREAD* top_of_thread(HEADER *h) +{ + THREAD *t = h->thread; + + while (t && t->parent) t = t->parent; + return t; +} + +int mutt_limit_current_thread (HEADER *h) +{ + int i; + THREAD *me; + + me = top_of_thread(h); + + if (!me) { + /* NOP */ + return 0; + } + + Context->vcount = 0; + Context->vsize = 0; + Context->collapsed = 0; + + for (i = 0; i < Context->msgcount; i++) + { + Context->hdrs[i]->virtual = -1; + Context->hdrs[i]->limited = 0; + Context->hdrs[i]->collapsed = 0; + Context->hdrs[i]->num_hidden = 0; + if (top_of_thread(Context->hdrs[i]) == me) + { + BODY *body = Context->hdrs[i]->content; + + Context->hdrs[i]->virtual = Context->vcount; + Context->hdrs[i]->limited = 1; + Context->v2r[Context->vcount] = i; + Context->vcount++; + Context->vsize += body->length + body->offset - + body->hdr_offset; + } + } + return 1; +} + int mutt_pattern_func (int op, char *prompt) { pattern_t *pat;