From e0b5f2e08cd766258bdfd5eb392690768d2f5964 Mon Sep 17 00:00:00 2001 From: inwit Date: Mon, 31 Jan 2022 17:32:19 +0100 Subject: [PATCH] completions: add folder flexible search as an option Provide an option to change the completion style when selecting a folder from completing with folders starting with the input string to completing with folders in which the input string is a substring present at any point in the folder name. References: https://lists.sr.ht/~sircmpwn/aerc/%3C20201129181020.186984-1-inwit%40sindominio.net%3E References: https://lists.sr.ht/~sircmpwn/aerc/%3C20210223202536.199355-1-clayton%40craftyguy.net%3E Signed-off-by: inwit --- commands/commands.go | 15 ++++++++++++++- config/aerc.conf.in | 4 ++++ config/config.go | 2 ++ doc/aerc-config.5.scd | 6 ++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/commands/commands.go b/commands/commands.go index 3777835..cb5b63b 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -121,7 +121,7 @@ func GetFolders(aerc *widgets.Aerc, args []string) []string { return aerc.SelectedAccount().Directories().List() } for _, dir := range aerc.SelectedAccount().Directories().List() { - if hasCaseSmartPrefix(dir, args[0]) { + if foundInString(dir, args[0], aerc.SelectedAccount().UiConfig().FuzzyFolderComplete) { out = append(out, dir) } } @@ -177,6 +177,14 @@ func GetLabels(aerc *widgets.Aerc, args []string) []string { return out } +func foundInString(s, substring string, fuzzy bool) bool { + if fuzzy { + return caseInsensitiveContains(s, substring) + } else { + return hasCaseSmartPrefix(s, substring) + } +} + // hasCaseSmartPrefix checks whether s starts with prefix, using a case // sensitive match if and only if prefix contains upper case letters. func hasCaseSmartPrefix(s, prefix string) bool { @@ -186,6 +194,11 @@ func hasCaseSmartPrefix(s, prefix string) bool { return strings.HasPrefix(strings.ToLower(s), strings.ToLower(prefix)) } +func caseInsensitiveContains(s, substr string) bool { + s, substr = strings.ToUpper(s), strings.ToUpper(substr) + return strings.Contains(s, substr) +} + func hasUpper(s string) bool { for _, r := range s { if unicode.IsUpper(r) { diff --git a/config/aerc.conf.in b/config/aerc.conf.in index 87f7e56..98cd679 100644 --- a/config/aerc.conf.in +++ b/config/aerc.conf.in @@ -112,6 +112,10 @@ stylesets-dirs=@SHAREDIR@/stylesets/ # Default: default styleset-name=default +# Activates fuzzy search for IMAP folders: the typed string is search in the +# folder tree in any position, not necessarily at the beginning. +#fuzzy-folder-complete=false + #[ui:account=foo] # # Enable threading in the ui. Only works with notmuch:// and imap:// accounts diff --git a/config/config.go b/config/config.go index 8d818c2..185a14c 100644 --- a/config/config.go +++ b/config/config.go @@ -43,6 +43,7 @@ type UIConfig struct { EmptyDirlist string `ini:"empty-dirlist"` MouseEnabled bool `ini:"mouse-enabled"` ThreadingEnabled bool `ini:"threading-enabled"` + FuzzyFolderComplete bool `ini:"fuzzy-folder-complete"` NewMessageBell bool `ini:"new-message-bell"` Spinner string `ini:"spinner"` SpinnerDelimiter string `ini:"spinner-delimiter"` @@ -563,6 +564,7 @@ func LoadConfigFromFile(root *string, sharedir string, logger *log.Logger) (*Aer EmptyDirlist: "(no folders)", MouseEnabled: false, NewMessageBell: true, + FuzzyFolderComplete: false, Spinner: "[..] , [..] , [..] , [..] , [..], [..] , [..] , [..] ", SpinnerDelimiter: ",", DirListFormat: "%n %>r", diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index a5af0d2..ce53f9b 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -222,6 +222,12 @@ These options are configured in the *[ui]* section of aerc.conf. Have a look at *aerc-stylesets*(7) as to how a styleset looks like. +*fuzzy-folder-complete* + When finding a folder with cf or move, for example, the popover will + how not only the folders /starting/ with the string input by the user, + but it will show coincidences of folders /containing/ the string in any + position of their name. This is case-independent. + *threading-enabled* Enable a threaded viewing of messages, works with IMAP (when there's server support) and NotMuch backends.