2 This is the sensible browser position patch by Haakon Riiser.
4 * Found in: <20050309162127.GA5656@s>
5 http://lists.df7cb.de/mutt/message/20050309.162127.a244a894.en.html
6 * myon 2009-01-15: refreshed for mutt-1.5.19
11 @@ -859,8 +859,12 @@ int menu_redraw (MUTTMENU *menu)
13 int mutt_menuLoop (MUTTMENU *menu)
15 + static int last_position = -1;
18 + if (menu->is_mailbox_list && last_position >= 0)
19 + menu->current = last_position;
23 if (option (OPTMENUCALLER))
24 @@ -1088,6 +1092,8 @@ int mutt_menuLoop (MUTTMENU *menu)
28 + if (menu->is_mailbox_list)
29 + last_position = menu->current;
35 @@ -56,6 +56,7 @@ typedef struct folder_t
39 +static char OldLastDir[_POSIX_PATH_MAX] = "";
40 static char LastDir[_POSIX_PATH_MAX] = "";
41 static char LastDirBackup[_POSIX_PATH_MAX] = "";
43 @@ -511,9 +512,13 @@ static void init_menu (struct browser_st
48 + menu->is_mailbox_list = 1;
49 snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0));
53 + menu->is_mailbox_list = 0;
54 strfcpy (path, LastDir, sizeof (path));
55 mutt_pretty_mailbox (path, sizeof (path));
57 @@ -522,8 +527,23 @@ static void init_menu (struct browser_st
58 path, NONULL (Mask.pattern));
61 - snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
62 - path, NONULL(Mask.pattern));
64 + char *p = strrchr (OldLastDir, '/');
65 + if (p && p - OldLastDir == mutt_strlen (LastDir) &&
66 + mutt_strncmp (LastDir, OldLastDir, p - OldLastDir) == 0)
68 + /* If we get here, it means that LastDir is the parent directory of
69 + * OldLastDir. I.e., we're returning from a subdirectory, and we want
70 + * to position the cursor on the directory we're returning from. */
72 + for (i = 0; i < state->entrymax; i++)
73 + if (mutt_strcmp (state->entry[i].name, p + 1) == 0)
76 + snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
77 + path, NONULL(Mask.pattern));
81 menu->redraw = REDRAW_FULL;
83 @@ -706,7 +726,6 @@ void _mutt_select_file (char *f, size_t
87 - char OldLastDir[_POSIX_PATH_MAX];
89 /* save the old directory */
90 strfcpy (OldLastDir, LastDir, sizeof (OldLastDir));
93 @@ -49,6 +49,7 @@ typedef struct menu_t
94 int offset; /* which screen row to start the index */
95 int pagelen; /* number of entries per screen */
97 + int is_mailbox_list;
99 /* Setting dialog != NULL overrides normal menu behaviour.
100 * In dialog mode menubar is hidden and prompt keys are checked before