Commit fb8e60c041d7b4a61e5862d6bce6fd3bd8fca000

Parents: 4bd93fccbf18a855016bd26a3ec8cd9ca7cf5600

From: Vitaly Ovchinnikov <v@ovch.ru>
Date: Mon Oct 30 15:35:59 2023 +0700

binds: folder-specific bindings for composer
Add folder-specific bindings for composer, so custom binginds might be
specified for a composer opened in a given folder.

Changlelog-Added: `[compose::editor:folder=$name]` binding context.
Signed-off-by: Vitaly Ovchinnikov <v@ovch.ru>
Acked-by: Robin Jarry <robin@jarry.cc>

Stats

app/aerc.go +5/-3
app/compose.go +7/-0
doc/aerc-binds.5.scd +8/-2

Changeset

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
diff --git a/app/aerc.go b/app/aerc.go
index f51aa24223d13ed1cf76bf25c9ca53cdec6e4239..046c78711d46a8a2420ef368ae408d6f113060d2 100644
--- a/app/aerc.go
+++ b/app/aerc.go
@@ -243,17 +243,19 @@ 		return binds.ForFolder(view.SelectedDirectory())
 	case *AccountWizard:
 		return config.Binds.AccountWizard
 	case *Composer:
+		var binds *config.KeyBindings
 		switch view.Bindings() {
 		case "compose::editor":
-			return config.Binds.ComposeEditor.ForAccount(
+			binds = config.Binds.ComposeEditor.ForAccount(
 				selectedAccountName)
 		case "compose::review":
-			return config.Binds.ComposeReview.ForAccount(
+			binds = config.Binds.ComposeReview.ForAccount(
 				selectedAccountName)
 		default:
-			return config.Binds.Compose.ForAccount(
+			binds = config.Binds.Compose.ForAccount(
 				selectedAccountName)
 		}
+		return binds.ForFolder(view.SelectedDirectory())
 	case *MessageViewer:
 		switch view.Bindings() {
 		case "view::passthrough":
diff --git a/app/compose.go b/app/compose.go
index 101a5765d362e190ba2c4e8a54c980980594413c..9ab8206b9e40e6784bda767a45fc5464fb4c7ccb 100644
--- a/app/compose.go
+++ b/app/compose.go
@@ -42,6 +42,7 @@ 	parent  *models.OriginalMail // parent of current message, only set if reply
 
 	acctConfig *config.AccountConfig
 	acct       *AccountView
+	seldir     string
 
 	attachments []lib.Attachment
 	editor      *Terminal
@@ -92,6 +93,7 @@
 	c := &Composer{
 		acct:       acct,
 		acctConfig: acctConfig,
+		seldir:     acct.Directories().Selected(),
 		header:     h,
 		parent:     orig,
 		email:      email,
@@ -125,6 +127,10 @@ 		return nil, err
 	}
 
 	return c, nil
+}
+
+func (c *Composer) SelectedDirectory() string {
+	return c.seldir
 }
 
 func (c *Composer) SwitchAccount(newAcct *AccountView) error {
@@ -1682,6 +1688,7 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage {
 	bindings := config.Binds.ComposeReview.ForAccount(
 		composer.acctConfig.Name,
 	)
+	bindings = bindings.ForFolder(composer.SelectedDirectory())
 
 	reviewCommands := [][]string{
 		{":send<enter>", "Send", ""},
diff --git a/doc/aerc-binds.5.scd b/doc/aerc-binds.5.scd
index f3e44574da0f4f94ea1260be48672c047be5c67e..228c6cd1ca038e3aef2f3340f6413abbeaaec752 100644
--- a/doc/aerc-binds.5.scd
+++ b/doc/aerc-binds.5.scd
@@ -61,9 +61,12 @@ *[context:account=*_AccountName_*]*
 	keybindings for this context and account, where _AccountName_ is a
 	regular expression that matches the account name you provided in _accounts.conf_.
 
-Folder-specific bindings can be configured for message lists:
+Folder and context-specific bindings can be configured for message lists:
 
-*[messages:folder=*_FolderName_*]*
+*[messages:folder=*_FolderName_*]*++
+*[compose:folder=*_FolderName_*]*++
+*[compose::editor:folder=*_FolderName_*]*++
+*[compose::review:folder=*_FolderName_*]*
 	keybindings under this section will be specific to the folder that
 	matches the regular expression _FolderName_.
 	Keybindings from a folder specifier will take precedence over account specifiers
@@ -75,6 +78,9 @@ [messages:account=Mailbox]
 c = :cf path:mailbox/** and<space>
 
 [compose::editor:account=Mailbox2]
+
+[compose::editor:folder=aerc]
+y = :send -t aerc
 
 [messages:folder=Drafts]
 <Enter> = :recall<Enter>