From: Justin Vasel Date: Thu, 30 Nov 2017 04:29:58 +0000 (-0500) Subject: Configure number of directory components displayed in sidebar X-Git-Tag: neomutt-20171215~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=671ff50e1b23a03ac1435970eb3c681e96a6d1d9;p=neomutt Configure number of directory components displayed in sidebar 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 --- diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 973375ae9..f9338956c 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -748,11 +748,12 @@ mailboxes =water/ocean/atlantic =water/ocean/pacific =water/ocean/arctic Shorten the names: -set sidebar_short_path # Shorten mailbox names -set sidebar_delim_chars="/" # Delete everything up to the last / character +set sidebar_short_path # Shorten mailbox names (truncate all subdirs) +set sidebar_component_depth=1 # Shorten mailbox names (truncate 1 subdirs) +set sidebar_delim_chars="/" # Delete everything up to the last or Nth / character The screenshot below shows what the Sidebar would look like - before and after shortening. + before and after shortening using sidebar_short_path. |fruit/apple |apple |fruit/banana |banana @@ -763,6 +764,19 @@ set sidebar_delim_chars="/" # Delete everyt |water/ocean/atlantic |atlantic |water/ocean/pacific |pacific |water/ocean/arctic |arctic + + The screenshot below shows what the Sidebar would look like + before and after shortening using sidebar_component_depth=1. + +|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 @@ -13817,6 +13831,15 @@ set sort_browser="reverse-size" no + + + sidebar_component_depth + + number + + 0 + + sidebar_sort_method @@ -14119,9 +14142,10 @@ set sidebar_visible = no set sidebar_width = 20 # Should the mailbox paths be abbreviated? set sidebar_short_path = no +# Number of top-level mailbox path subdirectories to truncate for display +set sidebar_component_depth = 0 # 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. set sidebar_delim_chars = '/.' # If the mailbox path is abbreviated, should it be indented? diff --git a/globals.h b/globals.h index 351472b92..5432663e1 100644 --- 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 117598fc6..89eac81fb 100644 --- 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 diff --git a/sidebar.c b/sidebar.c index ad16cae2f..b31227ae3 100644 --- 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);