~sircmpwn/aerc

add close-tab command v1 PROPOSED

We already have :close and :abort, could we simply make the existing

Perhaps somewhat selfishly, I don't really want to remember that :close
works for the message viewer and the terminal, abort for the composer,
and if I want to close one by name I should use :close-tab.

I think it would be possible to just have a single :close command which
uses a type switch to do the additional cleanup required by the term and
the composer, and it could also be extended to take an optional tab
name, acting on the focused tab if none is provided.

Thoughts?
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/%3C20190808051238.13836-1-adityasri%40ocf.berkeley.edu%3E/mbox | git am -3
Learn more about email & git

[PATCH] add close-tab command Export this patch

This adds the close-tab command per https://todo.sr.ht/~sircmpwn/aerc2/242

---
 commands/closetab.go | 47 ++++++++++++++++++++++++++++++++++++++++++++
 doc/aerc.1.scd       |  3 +++
 widgets/aerc.go      |  4 ++++
 3 files changed, 54 insertions(+)
 create mode 100644 commands/closetab.go

diff --git a/commands/closetab.go b/commands/closetab.go
new file mode 100644
index 0000000..89b6262
--- /dev/null
+++ b/commands/closetab.go
@@ -0,0 +1,47 @@
+package commands
+
+import (
+	"errors"
+	"fmt"
+
+	"git.sr.ht/~sircmpwn/aerc/widgets"
+)
+
+type CloseTab struct{}
+
+func init() {
+	register(CloseTab{})
+}
+
+func (_ CloseTab) Aliases() []string {
+	return []string{"close-tab"}
+}
+
+func (_ CloseTab) Complete(aerc *widgets.Aerc, args []string) []string {
+	return nil
+}
+
+func (_ CloseTab) Execute(aerc *widgets.Aerc, args []string) error {
+	if len(args) != 2 {
+		return errors.New("Usage: close-tab <tab name>")
+	} else {
+		tabname := args[1]
+		for _, tab := range aerc.TabNames() {
+			if tab == tabname {
+				curTabIndex := aerc.SelectedTabIndex()
+				aerc.SelectTab(tabname)
+				switch tab := aerc.SelectedTab().(type) {
+				default:
+					aerc.RemoveTab(tab)
+					return nil
+				case *widgets.AccountView:
+					aerc.SelectTabIndex(curTabIndex)
+					return errors.New("Cannot close account tab")
+				}
+			}
+		}
+		return errors.New(fmt.Sprintf("Tab %s not found", tabname))
+	}
+	return nil
+}
+
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 10e6485..3b04010 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -41,6 +41,9 @@ These commands work in any context.
 	it's treated as an index. If + or - is specified, the number is interpreted
 	as a delta from the selected tab.
 
+*close-tab* <tab name>
+    Closes tab with the given name. Cannot close account tabs.
+
 *exec* <command...>
 	Executes an arbitrary command in the background.
 
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 5a7914a..ab96e19 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -244,6 +244,10 @@ func (aerc *Aerc) SelectedTab() ui.Drawable {
 	return aerc.tabs.Tabs[aerc.tabs.Selected].Content
 }
 
+func (aerc *Aerc) SelectedTabIndex() int {
+	return aerc.tabs.Selected
+}
+
 func (aerc *Aerc) NewTab(drawable ui.Drawable, name string) *ui.Tab {
 	tab := aerc.tabs.Add(drawable, name)
 	aerc.tabs.Select(len(aerc.tabs.Tabs) - 1)
-- 
2.22.0
We already have :close and :abort, could we simply make the existing

Perhaps somewhat selfishly, I don't really want to remember that :close
works for the message viewer and the terminal, abort for the composer,
and if I want to close one by name I should use :close-tab.

I think it would be possible to just have a single :close command which
uses a type switch to do the additional cleanup required by the term and
the composer, and it could also be extended to take an optional tab
name, acting on the focused tab if none is provided.

Thoughts?
View this thread in the archives