Commit 2256f55a authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

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.
parent 53d57438
......@@ -124,6 +124,7 @@ OP_MAIN_PREV_NEW_THEN_UNREAD "jump to the previous new or unread message"
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"
......
......@@ -474,7 +474,7 @@ static void resort_index (MUTTMENU *menu)
}
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 @@ int mutt_index_menu (void)
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;
}
......
......@@ -160,6 +160,7 @@ const struct binding_t OpMain[] = { /* map: index */
{ "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 @@ const struct binding_t OpPager[] = { /* map: pager */
{ "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 },
......
......@@ -298,7 +298,7 @@ int mutt_fetch_recips (ENVELOPE *out, ENVELOPE *in, int flags);
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)
......
......@@ -1074,9 +1074,10 @@ int _mutt_aside_thread (HEADER *hdr, short dir, short subthreads)
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 @@ int mutt_parent_message (CONTEXT *ctx, HEADER *hdr)
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment