You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sensible_browser_position.patch 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. From: Antonio Radici <antonio@debian.org>
  2. Date: Thu, 27 Feb 2014 14:42:36 +0100
  3. Subject: sensible_browser_position
  4. This is the sensible browser position patch by Haakon Riiser.
  5. * Found in: <20050309162127.GA5656@s>
  6. http://lists.df7cb.de/mutt/message/20050309.162127.a244a894.en.html
  7. Gbp-Pq: Topic features
  8. ---
  9. browser.c | 24 +++++++++++++++++++++---
  10. menu.c | 11 +++++++++++
  11. mutt_menu.h | 1 +
  12. 3 files changed, 33 insertions(+), 3 deletions(-)
  13. diff --git a/browser.c b/browser.c
  14. index cda4900..dbb31c8 100644
  15. --- a/browser.c
  16. +++ b/browser.c
  17. @@ -56,6 +56,7 @@ typedef struct folder_t
  18. int num;
  19. } FOLDER;
  20. +static char OldLastDir[_POSIX_PATH_MAX] = "";
  21. static char LastDir[_POSIX_PATH_MAX] = "";
  22. static char LastDirBackup[_POSIX_PATH_MAX] = "";
  23. @@ -536,15 +537,33 @@ static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
  24. menu->tagged = 0;
  25. if (buffy)
  26. + {
  27. + menu->is_mailbox_list = 1;
  28. snprintf (title, titlelen, _("Mailboxes [%d]"), mutt_buffy_check (0));
  29. + }
  30. else
  31. {
  32. + menu->is_mailbox_list = 0;
  33. strfcpy (path, LastDir, sizeof (path));
  34. mutt_pretty_mailbox (path, sizeof (path));
  35. #ifdef USE_IMAP
  36. if (state->imap_browse && option (OPTIMAPLSUB))
  37. - snprintf (title, titlelen, _("Subscribed [%s], File mask: %s"),
  38. - path, NONULL (Mask.pattern));
  39. + {
  40. + char *p = strrchr (OldLastDir, '/');
  41. + if (p && p - OldLastDir == mutt_strlen (LastDir) &&
  42. + mutt_strncmp (LastDir, OldLastDir, p - OldLastDir) == 0)
  43. + {
  44. + /* If we get here, it means that LastDir is the parent directory of
  45. + * OldLastDir. I.e., we're returning from a subdirectory, and we want
  46. + * to position the cursor on the directory we're returning from. */
  47. + int i;
  48. + for (i = 0; i < state->entrymax; i++)
  49. + if (mutt_strcmp (state->entry[i].name, p + 1) == 0)
  50. + menu->current = i;
  51. + }
  52. + snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
  53. + path, NONULL(Mask.pattern));
  54. + }
  55. else
  56. #endif
  57. snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
  58. @@ -731,7 +750,6 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
  59. #endif
  60. )
  61. {
  62. - char OldLastDir[_POSIX_PATH_MAX];
  63. /* save the old directory */
  64. strfcpy (OldLastDir, LastDir, sizeof (OldLastDir));
  65. diff --git a/menu.c b/menu.c
  66. index e03dd33..27b5f8e 100644
  67. --- a/menu.c
  68. +++ b/menu.c
  69. @@ -849,8 +849,17 @@ int menu_redraw (MUTTMENU *menu)
  70. int mutt_menuLoop (MUTTMENU *menu)
  71. {
  72. + static int last_position = -1;
  73. int i = OP_NULL;
  74. + if ( menu->max && menu->is_mailbox_list ) {
  75. + if ( last_position > (menu->max-1) ) {
  76. + last_position = -1;
  77. + } else if (last_position >= 0) {
  78. + menu->current = last_position;
  79. + }
  80. + }
  81. +
  82. FOREVER
  83. {
  84. if (option (OPTMENUCALLER))
  85. @@ -1078,6 +1087,8 @@ int mutt_menuLoop (MUTTMENU *menu)
  86. break;
  87. default:
  88. + if (menu->is_mailbox_list)
  89. + last_position = menu->current;
  90. return (i);
  91. }
  92. }
  93. diff --git a/mutt_menu.h b/mutt_menu.h
  94. index 82abecd..404b6dd 100644
  95. --- a/mutt_menu.h
  96. +++ b/mutt_menu.h
  97. @@ -49,6 +49,7 @@ typedef struct menu_t
  98. int offset; /* which screen row to start the index */
  99. int pagelen; /* number of entries per screen */
  100. int tagprefix;
  101. + int is_mailbox_list;
  102. /* Setting dialog != NULL overrides normal menu behavior.
  103. * In dialog mode menubar is hidden and prompt keys are checked before