]> granicus.if.org Git - neomutt/commitdiff
Configure number of directory components displayed in sidebar
authorJustin Vasel <justin.vasel@gmail.com>
Thu, 30 Nov 2017 04:29:58 +0000 (23:29 -0500)
committerRichard Russon <rich@flatcap.org>
Tue, 12 Dec 2017 13:28:51 +0000 (13:28 +0000)
In cases of a complex maildir directory structures, one may want to hide the
highest `N` directories from display in the sidebar to keep things looking
clean and legible.

This commit introduces a new config parameter, `sidebar_component_depth`, which
takes a positive integer as its value.

For example, suppose I have the following directory structure:
```
Inbox
dir1/dir2
dir1/dir2/dir3/sushi
dir1/dir2/dir3/neomutt/developer
```

By setting `sidebar_component_depth=2` in one's rc file, the sidebar will
display these maildirs in the following way:
```
Inbox
dir2
dir3/sushi
dir3/neomutt/developer
```

As seen in this example, the two highest directories have been truncated from
each path except in the case when there are `<= N` subdirectories, in which
case the bottom-most directory is displayed.

This parameter has a default value of 0, which disables the feature.

A previously-existing option, `sidebar_short_path`, provides similar behavior,
but truncates all except the bottom-most directories. When that option is
enabled, `sidebar_component_depth` is ignored.

Issue #813

doc/manual.xml.head
globals.h
init.h
sidebar.c

index 973375ae9e6858b694a0809665fd064385353064..f9338956c4c38abe90d32f8c0ab7ab5cdf30091c 100644 (file)
@@ -748,11 +748,12 @@ mailboxes =water/ocean/atlantic =water/ocean/pacific   =water/ocean/arctic
 </screen>
               <para>Shorten the names:</para>
               <screen>
-set sidebar_short_path                  <emphasis role="comment"># Shorten mailbox names</emphasis>
-set sidebar_delim_chars="/"             <emphasis role="comment"># Delete everything up to the last / character</emphasis>
+set sidebar_short_path                  <emphasis role="comment"># Shorten mailbox names (truncate all subdirs)</emphasis>
+set sidebar_component_depth=1           <emphasis role="comment"># Shorten mailbox names (truncate 1 subdirs)</emphasis>
+set sidebar_delim_chars="/"             <emphasis role="comment"># Delete everything up to the last or Nth / character</emphasis>
 </screen>
               <para>The screenshot below shows what the Sidebar would look like
-              before and after shortening.</para>
+              before and after shortening using <literal>sidebar_short_path</literal>.</para>
               <screen>
 |fruit/apple                            |apple
 |fruit/banana                           |banana
@@ -763,6 +764,19 @@ set sidebar_delim_chars="/"             <emphasis role="comment"># Delete everyt
 |water/ocean/atlantic                   |atlantic
 |water/ocean/pacific                    |pacific
 |water/ocean/arctic                     |arctic
+</screen>
+              <para>The screenshot below shows what the Sidebar would look like
+              before and after shortening using <literal>sidebar_component_depth=1</literal>.</para>
+              <screen>
+|fruit/apple                            |apple
+|fruit/banana                           |banana
+|fruit/cherry                           |cherry
+|water/sea/sicily                       |sea/sicily
+|water/sea/archipelago                  |sea/archipelago
+|water/sea/sibuyan                      |sea/sibuyan
+|water/ocean/atlantic                   |ocean/atlantic
+|water/ocean/pacific                    |ocean/pacific
+|water/ocean/arctic                     |ocean/arctic
 </screen>
             </sect5>
 
@@ -13817,6 +13831,15 @@ set sort_browser="reverse-size"
                   <literal>no</literal>
                 </entry>
               </row>
+              <row>
+                <entry>
+                  <literal>sidebar_component_depth</literal>
+                </entry>
+                <entry>number</entry>
+                <entry>
+                  <literal>0</literal>
+                </entry>
+              </row>
               <row>
                 <entry>
                   <literal>sidebar_sort_method</literal>
@@ -14119,9 +14142,10 @@ set sidebar_visible = no
 set sidebar_width = 20
 <emphasis role="comment"># Should the mailbox paths be abbreviated?</emphasis>
 set sidebar_short_path = no
+<emphasis role="comment"># Number of top-level mailbox path subdirectories to truncate for display</emphasis>
+set sidebar_component_depth = 0
 <emphasis role="comment"># When abbreviating mailbox path names, use any of these characters as path
 # separators.  Only the part after the last separators will be shown.
-
 # For file folders '/' is good.  For IMAP folders, often '.' is useful.</emphasis>
 set sidebar_delim_chars = '/.'
 <emphasis role="comment"># If the mailbox path is abbreviated, should it be indented?</emphasis>
index 351472b9232fbb47fb385937c77903a88c70fe91..5432663e1275b1c2e819a154e4d6e4ee07a43c21 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -244,6 +244,7 @@ WHERE short ScoreThresholdRead;
 WHERE short ScoreThresholdFlag;
 
 #ifdef USE_SIDEBAR
+WHERE short SidebarComponentDepth;
 WHERE short SidebarWidth;
 WHERE struct ListHead SidebarWhitelist INITVAL(STAILQ_HEAD_INITIALIZER(SidebarWhitelist));
 #endif
diff --git a/init.h b/init.h
index 117598fc64010cbbd767dc913f355b63d5327eb5..89eac81fbea47e2e1c67ce45cbbef44ad71a4a8b 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3340,7 +3340,8 @@ struct Option MuttVars[] = {
   ** .dt \fCfruit.cherry\fP .dd \fCcherry\fP        .dd \fC..cherry\fP
   ** .de
   ** .pp
-  ** \fBSee also:\fP $$sidebar_delim_chars, $$sidebar_folder_indent, $$sidebar_indent_string.
+  ** \fBSee also:\fP $$sidebar_delim_chars, $$sidebar_folder_indent,
+  ** $$sidebar_indent_string, $$sidebar_component_depth.
   */
   { "sidebar_sort_method", DT_SORT|DT_SORT_SIDEBAR, R_SIDEBAR, UL &SidebarSortMethod, SORT_ORDER },
   /*
@@ -3361,6 +3362,18 @@ struct Option MuttVars[] = {
   ** You may optionally use the ``reverse-'' prefix to specify reverse sorting
   ** order (example: ``\fCset sort_browser=reverse-date\fP'').
   */
+  { "sidebar_component_depth", DT_NUMBER, R_SIDEBAR, UL &SidebarComponentDepth, UL 0 },
+  /*
+  ** .pp
+  ** By default the sidebar will show the mailbox's path, relative to the
+  ** $$folder variable. This specifies the number of parent directories to hide
+  ** from display in the sidebar. For example: If a maildir is normally
+  ** displayed in the sidebar as dir1/dir2/dir3/maildir, setting
+  ** \fCsidebar_component_depth=2\fP will display it as dir3/maildir, having
+  ** truncated the 2 highest directories.
+  ** .pp
+  ** \fBSee also:\fP $$sidebar_short_path
+  */
   { "sidebar_visible", DT_BOOL, R_REFLOW, OPT_SIDEBAR_VISIBLE, 0 },
   /*
   ** .pp
index ad16cae2f5b80be0d9fdcd1b5aaaa51bf13a198c..b31227ae35445ceb38938bc1ea78dd9116de42d2 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -900,6 +900,18 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width)
         }
       }
     }
+    else if ((SidebarComponentDepth > 0) && SidebarDelimChars)
+    {
+      sidebar_folder_name = b->path + maildir_is_prefix * (maildirlen + 1);
+      for (int i = 0; i < SidebarComponentDepth; i++)
+      {
+        char *chars_after_delim = strpbrk(sidebar_folder_name, SidebarDelimChars);
+        if (!chars_after_delim)
+          break;
+        else
+          sidebar_folder_name = chars_after_delim + 1;
+      }
+    }
     else
       sidebar_folder_name = b->path + maildir_is_prefix * (maildirlen + 1);