]> granicus.if.org Git - neomutt/commitdiff
main: add command to limit to only current thread
authorDavid Sterba <dsterba@suse.cz>
Thu, 24 May 2012 13:34:53 +0000 (15:34 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:33:32 +0000 (03:33 +0100)
Add command to limit view on the thread from any of its message.
Predefined on command <ESC>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 <dsterba@suse.cz>
OPS
curs_main.c
functions.h
mutt_menu.h
pattern.c

diff --git a/OPS b/OPS
index 8414a8b337671ddee819f83f06b26da76559ee92..659c50f2ff4252bfbac1051e826d25b26eb3d66e 100644 (file)
--- 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"
index a76aac998e0fc94f303fa3e4730f197b56eb71f9..92ac49efbc4421a58c376cd03e9b7e9672625d06 100644 (file)
@@ -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)
          {
index 7a1c5a9f126b7da177fbbee023acacab45af07e3..b70d4d888c19afe0553ba11c6a7bfabfb7a3e353 100644 (file)
@@ -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" },
index 8192019e2cc8254c03f9f9227e7452c7a2ec4182..ee341f699fc3fab20ef77539cae1ee21a073e243 100644 (file)
@@ -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_ */
index d954cdc3bbd7a23b41360ed7f74ae55d0bf73e87..c6abc1dca60e1937b450820351cba828f19ee38b 100644 (file)
--- 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;