changeset: 6825:77de473642cb
user:      Kevin McCarthy <[email protected]>
date:      Wed Oct 19 13:21:16 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/77de473642cb

Add root-message function to jump to root message in thread.

This seems like a useful feature that was brought up for discussion on
mutt-users.  Proposed solutions involved collapsing/uncollapsing
threads, but it's not hard to modify the mutt_parent_message()
function to return the root instead.

diffs (130 lines):

diff -r 1acabd35d9a3 -r 77de473642cb OPS
--- a/OPS       Mon Oct 17 11:23:30 2016 -0700
+++ b/OPS       Wed Oct 19 13:21:16 2016 -0700
@@ -124,6 +124,7 @@
 OP_MAIN_PREV_UNREAD "jump to the previous unread message"
 OP_MAIN_READ_THREAD "mark the current thread as read"
 OP_MAIN_READ_SUBTHREAD "mark the current subthread as read"
+OP_MAIN_ROOT_MESSAGE "jump to root message in thread"
 OP_MAIN_SET_FLAG "set a status flag on a message"
 OP_MAIN_SYNC_FOLDER "save changes to mailbox"
 OP_MAIN_TAG_PATTERN "tag messages matching a pattern"
diff -r 1acabd35d9a3 -r 77de473642cb curs_main.c
--- a/curs_main.c       Mon Oct 17 11:23:30 2016 -0700
+++ b/curs_main.c       Wed Oct 19 13:21:16 2016 -0700
@@ -474,7 +474,7 @@
   }
 
   if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
-    menu->current = mutt_parent_message (Context, current);
+    menu->current = mutt_parent_message (Context, current, 0);
 
   if (menu->current < 0)
     menu->current = ci_first_message ();
@@ -1791,12 +1791,14 @@
          menu->redraw = REDRAW_MOTION;
        break;
 
+      case OP_MAIN_ROOT_MESSAGE:
       case OP_MAIN_PARENT_MESSAGE:
 
        CHECK_MSGCOUNT;
         CHECK_VISIBLE;
 
-       if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0)
+       if ((menu->current = mutt_parent_message (Context, CURHDR,
+                                                  op == OP_MAIN_ROOT_MESSAGE)) 
< 0)
        {
          menu->current = menu->oldcurrent;
        }
diff -r 1acabd35d9a3 -r 77de473642cb functions.h
--- a/functions.h       Mon Oct 17 11:23:30 2016 -0700
+++ b/functions.h       Wed Oct 19 13:21:16 2016 -0700
@@ -160,6 +160,7 @@
   { "next-unread",             OP_MAIN_NEXT_UNREAD,            NULL },
   { "previous-unread",         OP_MAIN_PREV_UNREAD,            NULL },
   { "parent-message",          OP_MAIN_PARENT_MESSAGE,         "P" },
+  { "root-message",            OP_MAIN_ROOT_MESSAGE,           NULL },
 
 
   { "extract-keys",            OP_EXTRACT_KEYS,                "\013" },
@@ -271,6 +272,7 @@
   { "previous-line",   OP_PREV_LINE,                   NULL },
   { "bottom",          OP_PAGER_BOTTOM,                NULL },
   { "parent-message",  OP_MAIN_PARENT_MESSAGE,         "P" },
+  { "root-message",    OP_MAIN_ROOT_MESSAGE,           NULL },
 
 
 
diff -r 1acabd35d9a3 -r 77de473642cb protos.h
--- a/protos.h  Mon Oct 17 11:23:30 2016 -0700
+++ b/protos.h  Wed Oct 19 13:21:16 2016 -0700
@@ -298,7 +298,7 @@
 int mutt_chscmp (const char *s, const char *chs);
 #define mutt_is_utf8(a) mutt_chscmp (a, "utf-8")
 #define mutt_is_us_ascii(a) mutt_chscmp (a, "us-ascii")
-int mutt_parent_message (CONTEXT *, HEADER *);
+int mutt_parent_message (CONTEXT *, HEADER *, int);
 int mutt_prepare_template(FILE*, CONTEXT *, HEADER *, HEADER *, short);
 int mutt_resend_message (FILE *, CONTEXT *, HEADER *);
 #define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL)
diff -r 1acabd35d9a3 -r 77de473642cb thread.c
--- a/thread.c  Mon Oct 17 11:23:30 2016 -0700
+++ b/thread.c  Wed Oct 19 13:21:16 2016 -0700
@@ -1074,9 +1074,10 @@
   return (tmp->virtual);
 }
 
-int mutt_parent_message (CONTEXT *ctx, HEADER *hdr)
+int mutt_parent_message (CONTEXT *ctx, HEADER *hdr, int find_root)
 {
   THREAD *thread;
+  HEADER *parent = NULL;
 
   if ((Sort & SORT_MASK) != SORT_THREADS)
   {
@@ -1084,22 +1085,34 @@
     return (hdr->virtual);
   }
 
+  /* Root may be the current message */
+  if (find_root)
+    parent = hdr;
+
   for (thread = hdr->thread->parent; thread; thread = thread->parent)
   {
     if ((hdr = thread->message) != NULL)
     {
-      if (VISIBLE (hdr, ctx))
-       return (hdr->virtual);
-      else
-      {
-       mutt_error _("Parent message is not visible in this limited view.");
-       return (-1);
-      }
+      parent = hdr;
+      if (!find_root)
+        break;
     }
   }
-  
-  mutt_error _("Parent message is not available.");
-  return (-1);
+
+  if (!parent)
+  {
+    mutt_error _("Parent message is not available.");
+    return (-1);
+  }
+  if (!VISIBLE (parent, ctx))
+  {
+    if (find_root)
+      mutt_error _("Root message is not visible in this limited view.");
+    else
+      mutt_error _("Parent message is not visible in this limited view.");
+    return (-1);
+  }
+  return (parent->virtual);
 }
 
 void mutt_set_virtual (CONTEXT *ctx)

Reply via email to