From 175d0efeb22eb61ce40a1b25969886a66fcdf83e Mon Sep 17 00:00:00 2001 From: Jonathan Bartlett Date: Fri, 10 Dec 2021 21:27:29 +0000 Subject: binds: add account specific bindings When using aerc for multiple accounts often bindings might differ slightly between accounts. For example: * Account A archives to one directory (:archive) * Account B archives to monthly directories (:archive month) Add account specific bindings to allow the user to add a "context" to a binding group using a context specifier and a regular expression. Currently the only context specifier is 'account'. The regular expression is validated against the accounts loaded from accounts.conf and the configuration fails to load if there are no matches. Contextual bindings are merged with global bindings, with contextual bindings taking precedence, when that context is active. Bindings are be configured using a generic pattern of 'view:context=regexp'. E.g.: # Globally Applicable Archiving [messages] A = :read:archive # Monthly Archiving for 'Mailbox' Account [messages:account=Mailbox$] A = :read:archive month In the above example all accounts matching the regular expression will archive in the monthly format - all others will use the global binding. Signed-off-by: Jonathan Bartlett --- config/bindings.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'config/bindings.go') diff --git a/config/bindings.go b/config/bindings.go index eff48a61..62956d7b 100644 --- a/config/bindings.go +++ b/config/bindings.go @@ -55,6 +55,28 @@ func MergeBindings(bindings ...*KeyBindings) *KeyBindings { return merged } +func (config AercConfig) MergeContextualBinds(baseBinds *KeyBindings, + contextType ContextType, reg string, bindCtx string) *KeyBindings { + + bindings := baseBinds + for _, contextualBind := range config.ContextualBinds { + if contextualBind.ContextType != contextType { + continue + } + + if !contextualBind.Regex.Match([]byte(reg)) { + continue + } + + if contextualBind.BindContext != bindCtx { + continue + } + + bindings = MergeBindings(contextualBind.Bindings, bindings) + } + return bindings +} + func (bindings *KeyBindings) Add(binding *Binding) { // TODO: Search for conflicts? bindings.bindings = append(bindings.bindings, binding) -- cgit