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.

sidebar-dotpathsep.patch 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. From: Fabian Groffen <grobian@gentoo.org>
  2. Date: Tue, 4 Mar 2014 21:12:15 +0100
  3. Subject: sidebar-dotpathsep
  4. Make path separators for sidebar folders configurable.
  5. When using IMAP, a '.' is often used as path separator, hence make the
  6. path separators configurable through sidebar_delim_chars variable.
  7. It defaults to "/." to work for both mboxes as well as IMAP folders. It
  8. can be set to only "/" or "." or whichever character desired as needed.
  9. Gbp-Pq: Topic mutt-patched
  10. ---
  11. globals.h | 1 +
  12. init.h | 8 ++++++++
  13. sidebar.c | 31 ++++++++++++++++++++++++-------
  14. 3 files changed, 33 insertions(+), 7 deletions(-)
  15. diff --git a/globals.h b/globals.h
  16. index 3f83328..61765a4 100644
  17. --- a/globals.h
  18. +++ b/globals.h
  19. @@ -118,6 +118,7 @@ WHERE char *SendCharset;
  20. WHERE char *Sendmail;
  21. WHERE char *Shell;
  22. WHERE char *SidebarDelim;
  23. +WHERE char *SidebarDelimChars INITVAL (NULL);
  24. WHERE char *Signature;
  25. WHERE char *SimpleSearch;
  26. #if USE_SMTP
  27. diff --git a/init.h b/init.h
  28. index 502f570..b0784d8 100644
  29. --- a/init.h
  30. +++ b/init.h
  31. @@ -2001,6 +2001,14 @@ struct option_t MuttVars[] = {
  32. ** .pp
  33. ** The width of the sidebar.
  34. */
  35. + { "sidebar_delim_chars", DT_STR, R_NONE, UL &SidebarDelimChars, UL "/." },
  36. + /*
  37. + ** .pp
  38. + ** This contains the list of characters which you would like to treat
  39. + ** as folder separators for displaying paths in the sidebar. If
  40. + ** you're not using IMAP folders, you probably prefer setting this to "/"
  41. + ** alone.
  42. + */
  43. { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
  44. /*
  45. ** .pp
  46. diff --git a/sidebar.c b/sidebar.c
  47. index 6098c2a..4356ffc 100644
  48. --- a/sidebar.c
  49. +++ b/sidebar.c
  50. @@ -249,20 +249,37 @@ int draw_sidebar(int menu) {
  51. // calculate depth of current folder and generate its display name with indented spaces
  52. int sidebar_folder_depth = 0;
  53. char *sidebar_folder_name;
  54. - sidebar_folder_name = basename(tmp->path);
  55. + int i;
  56. + sidebar_folder_name = tmp->path;
  57. + /* disregard a trailing separator, so strlen() - 2
  58. + * https://bugs.gentoo.org/show_bug.cgi?id=373197#c16 */
  59. + for (i = strlen(sidebar_folder_name) - 2; i >= 0; i--) {
  60. + if (SidebarDelimChars &&
  61. + strchr(SidebarDelimChars, sidebar_folder_name[i]))
  62. + {
  63. + sidebar_folder_name += i + 1;
  64. + break;
  65. + }
  66. + }
  67. if ( maildir_is_prefix ) {
  68. char *tmp_folder_name;
  69. - int i;
  70. + int lastsep = 0;
  71. tmp_folder_name = tmp->path + strlen(Maildir);
  72. - for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
  73. - if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
  74. - }
  75. + for (i = 0; i < strlen(tmp_folder_name) - 1; i++) {
  76. + if (SidebarDelimChars &&
  77. + strchr(SidebarDelimChars, tmp_folder_name[i]))
  78. + {
  79. + sidebar_folder_depth++;
  80. + lastsep = i + 1;
  81. + }
  82. + }
  83. if (sidebar_folder_depth > 0) {
  84. - sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
  85. + tmp_folder_name += lastsep; /* basename */
  86. + sidebar_folder_name = malloc(strlen(tmp_folder_name) + sidebar_folder_depth + 1);
  87. for (i=0; i < sidebar_folder_depth; i++)
  88. sidebar_folder_name[i]=' ';
  89. sidebar_folder_name[i]=0;
  90. - strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
  91. + strncat(sidebar_folder_name, tmp_folder_name, strlen(tmp_folder_name) + sidebar_folder_depth);
  92. }
  93. }
  94. printw( "%.*s", SidebarWidth - delim_len + 1,