aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-12-12 15:03:30 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-14 11:22:58 +0100
commitc05c2ffe0424b048b10e7dd1aca59ae9cf631f12 (patch)
tree13a3a84eb74fdea77996161f01bec5596f67f39f /commands/msg
parent9d0297e9d913a92b2d7ae02692e83f0f4093a766 (diff)
downloadaerc-c05c2ffe0424b048b10e7dd1aca59ae9cf631f12.tar.gz
config: make various sections accessible via global vars
There is only one instance of AercConfig which is associated to the Aerc widget. Everywhere we need to access configuration options, we need somehow to get a reference either to the Aerc widget or to a pointer to the AercConfig instance. This makes the code cluttered. Remove the AercConfig structure and every place where it is referenced. Instead, declare global variables for every configuration section and access them directly from the `config` module. Since bindings and ui sections can be "contextual" (i.e. per account, per folder or per subject), leave most local references intact. Replacing them with config.{Ui,Binds}.For{Account,Folder,Subject} would make this patch even more unreadable. This is something that may be addressed in the future. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'commands/msg')
-rw-r--r--commands/msg/delete.go5
-rw-r--r--commands/msg/forward.go5
-rw-r--r--commands/msg/invite.go5
-rw-r--r--commands/msg/move.go5
-rw-r--r--commands/msg/recall.go2
-rw-r--r--commands/msg/reply.go13
-rw-r--r--commands/msg/unsubscribe.go1
7 files changed, 20 insertions, 16 deletions
diff --git a/commands/msg/delete.go b/commands/msg/delete.go
index 066476d8..6c786257 100644
--- a/commands/msg/delete.go
+++ b/commands/msg/delete.go
@@ -4,6 +4,7 @@ import (
"errors"
"time"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models"
@@ -54,7 +55,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushStatus("Messages deleted.", 10*time.Second)
mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
if isMsgView {
- if !aerc.Config().Ui.NextMessageOnDelete {
+ if !config.Ui.NextMessageOnDelete {
aerc.RemoveTab(h.msgProvider)
} else {
// no more messages in the list
@@ -71,7 +72,7 @@ func (Delete) Execute(aerc *widgets.Aerc, args []string) error {
aerc.PushError(err.Error())
return
}
- nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
+ nextMv := widgets.NewMessageViewer(acct, view)
aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
})
}
diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index c0215aee..9a4f3d41 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -12,6 +12,7 @@ import (
"strings"
"sync"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/format"
"git.sr.ht/~rjarry/aerc/lib/ui"
@@ -99,7 +100,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
}
addTab := func() (*widgets.Composer, error) {
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), template, h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
@@ -158,7 +159,7 @@ func (forward) Execute(aerc *widgets.Aerc, args []string) error {
})
} else {
if template == "" {
- template = aerc.Config().Templates.Forwards
+ template = config.Templates.Forwards
}
part := lib.FindPlaintext(msg.BodyStructure, nil)
diff --git a/commands/msg/invite.go b/commands/msg/invite.go
index 32251643..2dca259b 100644
--- a/commands/msg/invite.go
+++ b/commands/msg/invite.go
@@ -5,6 +5,7 @@ import (
"fmt"
"io"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/calendar"
"git.sr.ht/~rjarry/aerc/lib/format"
@@ -99,7 +100,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error {
to = msg.Envelope.From
}
- if !aerc.Config().Compose.ReplyToSelf {
+ if !config.Compose.ReplyToSelf {
for i, v := range to {
if v.Address == from.Address {
to = append(to[:i], to[i+1:]...)
@@ -147,7 +148,7 @@ func (invite) Execute(aerc *widgets.Aerc, args []string) error {
}
addTab := func(cr *calendar.Reply) error {
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), "", h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
diff --git a/commands/msg/move.go b/commands/msg/move.go
index 15494364..6e77a88c 100644
--- a/commands/msg/move.go
+++ b/commands/msg/move.go
@@ -6,6 +6,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models"
@@ -91,7 +92,7 @@ func handleDone(
aerc.PushStatus(message, 10*time.Second)
mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
switch {
- case isMsgView && !aerc.Config().Ui.NextMessageOnDelete:
+ case isMsgView && !config.Ui.NextMessageOnDelete:
aerc.RemoveTab(h.msgProvider)
case isMsgView:
if next == nil {
@@ -107,7 +108,7 @@ func handleDone(
aerc.PushError(err.Error())
return
}
- nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
+ nextMv := widgets.NewMessageViewer(acct, view)
aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
})
default:
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index d39f4daf..f106e8bd 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -72,7 +72,7 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
}
log.Debugf("Recalling message <%s>", msgInfo.Envelope.MessageId)
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), "", msgInfo.RFC822Headers,
models.OriginalMail{})
if err != nil {
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 12eba928..5aad4fc9 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -11,6 +11,7 @@ import (
"git.sr.ht/~sircmpwn/getopt"
"git.sr.ht/~rjarry/aerc/commands/account"
+ "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/lib/crypto"
"git.sr.ht/~rjarry/aerc/lib/format"
@@ -118,7 +119,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
to = msg.Envelope.From
}
- if !aerc.Config().Compose.ReplyToSelf {
+ if !config.Compose.ReplyToSelf {
for i, v := range to {
if v.Address == from.Address {
to = append(to[:i], to[i+1:]...)
@@ -179,13 +180,13 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
mv, _ := aerc.SelectedTabContent().(*widgets.MessageViewer)
addTab := func() error {
- composer, err := widgets.NewComposer(aerc, acct, aerc.Config(),
+ composer, err := widgets.NewComposer(aerc, acct,
acct.AccountConfig(), acct.Worker(), template, h, original)
if err != nil {
aerc.PushError("Error: " + err.Error())
return err
}
- if (mv != nil) && aerc.Config().Viewer.CloseOnReply {
+ if (mv != nil) && config.Viewer.CloseOnReply {
mv.Close()
aerc.RemoveTab(mv)
}
@@ -208,7 +209,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
switch {
case c.Sent():
store.Answered([]uint32{msg.Uid}, true, nil)
- case mv != nil && aerc.Config().Viewer.CloseOnReply:
+ case mv != nil && config.Viewer.CloseOnReply:
//nolint:errcheck // who cares?
account.ViewMessage{}.Execute(aerc, []string{"-p"})
}
@@ -219,7 +220,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
if quote {
if template == "" {
- template = aerc.Config().Templates.QuotedReply
+ template = config.Templates.QuotedReply
}
if crypto.IsEncrypted(msg.BodyStructure) {
@@ -275,7 +276,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
return nil
} else {
if template == "" {
- template = aerc.Config().Templates.NewMessage
+ template = config.Templates.NewMessage
}
return addTab()
}
diff --git a/commands/msg/unsubscribe.go b/commands/msg/unsubscribe.go
index 0538b2f2..a334e827 100644
--- a/commands/msg/unsubscribe.go
+++ b/commands/msg/unsubscribe.go
@@ -151,7 +151,6 @@ func unsubscribeMailto(aerc *widgets.Aerc, u *url.URL) error {
composer, err := widgets.NewComposer(
aerc,
acct,
- aerc.Config(),
acct.AccountConfig(),
acct.Worker(),
"",