]> granicus.if.org Git - neomutt/commitdiff
feature: dotpathsep
authorFabian Groffen <grobian@gentoo.org>
Thu, 26 Nov 2015 16:49:27 +0000 (16:49 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:37:42 +0000 (03:37 +0100)
Add new config: "sidebar_delim_chars"
Allow the user to configure how folder names are parsed into a
hierarchy.

globals.h
init.h
sidebar.c

index b5a126269bf1afbd6dba3600746b0ac2f2669304..28f95198839b735feee6a44e1d9f178bc23a55ab 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -119,6 +119,7 @@ WHERE char *SendCharset;
 WHERE char *Sendmail;
 WHERE char *Shell;
 WHERE char *SidebarDelim;
+WHERE char *SidebarDelimChars;
 WHERE char *SidebarFormat;
 WHERE char *SidebarIndentStr;
 WHERE char *Signature;
diff --git a/init.h b/init.h
index ef7f433753a9e3ac00a7ce3674a4a9d3cc4c92a8..d46cde2980b7c52bf072c7d04ae3beef47b3bdf5 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2672,6 +2672,14 @@ struct option_t MuttVars[] = {
   ** This specifies the delimiter between the sidebar (if visible) and 
   ** other screens.
   */
+  { "sidebar_delim_chars",             DT_STR, R_NONE, UL &SidebarDelimChars, UL "/." },
+  /*
+  ** .pp
+  ** This contains the list of characters which you would like to treat
+  ** as folder separators for displaying paths in the sidebar.  If
+  ** you're not using IMAP folders, you probably prefer setting this to "/"
+  ** alone.
+  */
   { "sidebar_folderindent", DT_BOOL, R_BOTH, OPTSIDEBARFOLDERINDENT, 0 },
   /*
   ** .pp
index f099370cf1caac9c4b9fa62ebe390da522461325..a56dded65a2ae80f4c006326c94d8eff44ea91df 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -356,33 +356,53 @@ int draw_sidebar(int menu) {
                        tmp->msgcount = Context->msgcount;
                        tmp->msg_flagged = Context->flagged;
                }
+
+               /* compute length of Maildir without trailing separator */
+               size_t maildirlen = strlen (Maildir);
+               if (SidebarDelimChars && strchr (SidebarDelimChars, Maildir[maildirlen - 1])) {
+                       maildirlen--;
+               }
+
                /* check whether Maildir is a prefix of the current folder's path */
                short maildir_is_prefix = 0;
-               if ( (strlen(tmp->path) > strlen(Maildir)) &&
-                       (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
+               if ( (strlen(tmp->path) > maildirlen) &&
+                       (strncmp(Maildir, tmp->path, maildirlen) == 0) )
                        maildir_is_prefix = 1;
                /* calculate depth of current folder and generate its display name with indented spaces */
                int sidebar_folder_depth = 0;
                char *sidebar_folder_name;
-               sidebar_folder_name = option(OPTSIDEBARSHORTPATH) ? (char*) mutt_basename(tmp->path) : tmp->path + maildir_is_prefix*(strlen(Maildir) + 1);
-               if ( maildir_is_prefix && option(OPTSIDEBARFOLDERINDENT) ) {
+               int i;
+               if (option (OPTSIDEBARSHORTPATH)) {
+                       /* disregard a trailing separator, so strlen() - 2 */
+                       sidebar_folder_name = tmp->path;
+                       for (i = strlen (sidebar_folder_name) - 2; i >= 0; i--) {
+                               if (SidebarDelimChars &&
+                                               strchr (SidebarDelimChars, sidebar_folder_name[i]))
+                               {
+                                       sidebar_folder_name += i + 1;
+                                       break;
+                               }
+                       }
+               } else {
+                       sidebar_folder_name = tmp->path + maildir_is_prefix * (maildirlen + 1);
+               }
+               if (maildir_is_prefix && option (OPTSIDEBARFOLDERINDENT)) {
                        const char *tmp_folder_name;
-                       int i;
-                       tmp_folder_name = tmp->path + strlen(Maildir) + 1;
-                       for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
-                               if (tmp_folder_name[i] == '/'  || tmp_folder_name[i] == '.') sidebar_folder_depth++;
-                       }   
+                       int lastsep = 0;
+                       tmp_folder_name = tmp->path + maildirlen + 1;
+                       for (i = 0; i < strlen(tmp_folder_name) - 1; i++) {
+                               if (SidebarDelimChars &&
+                                               strchr (SidebarDelimChars, tmp_folder_name[i]))
+                               {
+                                       sidebar_folder_depth++;
+                                       lastsep = i + 1;
+                               }
+                       }
                        if (sidebar_folder_depth > 0) {
                                if (option(OPTSIDEBARSHORTPATH)) {
-                                       tmp_folder_name = strrchr(tmp->path, '.');
-                                       if (tmp_folder_name == NULL)
-                                               tmp_folder_name = mutt_basename(tmp->path);
-                                       else
-                                               tmp_folder_name++;
+                                       tmp_folder_name += lastsep;  /* basename */
                                }
-                               else
-                                       tmp_folder_name = tmp->path + strlen(Maildir) + 1;
-                               sidebar_folder_name = malloc(strlen(tmp_folder_name) + sidebar_folder_depth*strlen(NONULL(SidebarIndentStr)) + 1);
+                               sidebar_folder_name = malloc(strlen(tmp_folder_name) + sidebar_folder_depth*strlen (NONULL (SidebarIndentStr)) + 1);
                                sidebar_folder_name[0]=0;
                                for (i=0; i < sidebar_folder_depth; i++)
                                        strncat(sidebar_folder_name, NONULL(SidebarIndentStr), strlen(NONULL(SidebarIndentStr)));