~sircmpwn/aerc

Add a 'folders-exclude' option v1 PROPOSED

ARaspiK: 1
 Add a 'folders-exclude' option

 3 files changed, 46 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/11366/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Add a 'folders-exclude' option Export this patch

Added a 'folders-exclude' option that allows removing selected folders
from the directory list sidebar. My motivating example was that removing
a single folder from the list using Golang regexes seemed pretty hard,
so this is a better way to do it. The excluded folders list is included
in the man page.
---
 config/config.go      |  5 +++++
 doc/aerc-config.5.scd |  7 +++++++
 widgets/dirlist.go    | 43 ++++++++++++++++++++++++++++++++++---------
 3 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/config/config.go b/config/config.go
index 8ebd69d..ce59944 100644
--- a/config/config.go
+++ b/config/config.go
@@ -76,6 +76,7 @@ type AccountConfig struct {
	Source          string
	SourceCredCmd   string
	Folders         []string
	FoldersExclude	[]string
	Params          map[string]string
	Outgoing        string
	OutgoingCredCmd string
@@ -186,6 +187,10 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
				folders := strings.Split(val, ",")
				sort.Strings(folders)
				account.Folders = folders
			} else if key == "folders-exclude" {
				folders := strings.Split(val, ",")
				sort.Strings(folders)
				account.FoldersExclude = folders
			} else if key == "source-cred-cmd" {
				account.SourceCredCmd = val
			} else if key == "outgoing" {
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 2bd3076..af64ad6 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -376,6 +376,13 @@ Note that many of these configuration options are written for you, such as

	Default: all folders

*folders-exclude*
	Specifies the comma separated list of folders to exclude from the sidebar.
	Names prefixed with ~ are interpreted as regular expressions.
	Note that this overrides anything from *folders*.

	Default: no folders

*folders-sort*
	Specifies a comma separated list of folders to be shown at the top of the
	list in the provided order. Remaining folders will be sorted alphabetically.
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index f12631b..83edfd7 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -393,21 +393,46 @@ func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
// dirstore, based on the AccountConfig.Folders option
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
	dirlist.dirs = dirlist.store.List()
	// config option defaults to show all if unset
	configFolders := dirlist.acctConf.Folders
	configFoldersExclude := dirlist.acctConf.FoldersExclude
	// 'folders' unset and 'folders-exclude' unset: show all
	// 'folders' set and 'folders-exclude' unset: show 'folders'
	// 'folders' unset and 'folders-exclude' set: show all except for 'folders-exclude'
	// 'folders' set and 'folders-exclude' set: show 'folders' except for 'folders-exclude'

	// intermediate list of dirs
	var filtered []string

	// 'folders': if unset, select all, otherwise select only 'folders'
	if len(configFolders) == 0 {
		return
		filtered = dirlist.dirs
	} else {
		for _, folder := range dirlist.dirs {
			for _, cfgfolder := range configFolders {
				if folderMatches(folder, cfgfolder) {
					filtered = append(filtered, folder)
					break
				}
			}
		}
	}
	var filtered []string
	for _, folder := range dirlist.dirs {
		for _, cfgfolder := range configFolders {
			if folderMatches(folder, cfgfolder) {
				filtered = append(filtered, folder)
				break

	// another intermediate list of dirs
	var excluded []string

	// 'folders-exclude': if unset, select 'filtered', otherwise remove 'folders-exclude'
	if len(configFoldersExclude) != 0 {
		for _, folder := range filtered {
			for _, cfgnotfolder := range configFoldersExclude {
				if !folderMatches(folder, cfgnotfolder) {
					excluded = append(excluded, folder)
					break
				}
			}
		}
	}
	dirlist.dirs = filtered

	dirlist.dirs = excluded
}

func (dirlist *DirectoryList) SelectedMsgStore() (*lib.MessageStore, bool) {
-- 
2.27.0
Time appropriate greetings,

On Sun, Jun 28, 2020 at 04:04:59PM +0000, ARaspiK wrote: