From 24daef89e0fc6056c3ff7b94880ed12b4ec3eaa6 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 14 Mar 2019 23:41:25 -0400 Subject: Implement :{next,prev}-message --- commands/next-folder.go | 6 +++--- commands/next-message.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 commands/next-message.go (limited to 'commands') diff --git a/commands/next-folder.go b/commands/next-folder.go index ed11615..dce8907 100644 --- a/commands/next-folder.go +++ b/commands/next-folder.go @@ -13,13 +13,13 @@ func init() { Register("prev-folder", NextPrevFolder) } -func usage(cmd string) error { +func nextPrevFolderUsage(cmd string) error { return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) } func NextPrevFolder(aerc *widgets.Aerc, args []string) error { if len(args) > 2 { - return usage(args[0]) + return nextPrevFolderUsage(args[0]) } var ( n int = 1 @@ -28,7 +28,7 @@ func NextPrevFolder(aerc *widgets.Aerc, args []string) error { if len(args) > 1 { n, err = strconv.Atoi(args[1]) if err != nil { - return usage(args[0]) + return nextPrevFolderUsage(args[0]) } } acct := aerc.SelectedAccount() diff --git a/commands/next-message.go b/commands/next-message.go new file mode 100644 index 0000000..86cd678 --- /dev/null +++ b/commands/next-message.go @@ -0,0 +1,43 @@ +package commands + +import ( + "errors" + "fmt" + "strconv" + + "git.sr.ht/~sircmpwn/aerc2/widgets" +) + +func init() { + Register("next-message", NextPrevMessage) + Register("prev-message", NextPrevMessage) +} + +func nextPrevMessageUsage(cmd string) error { + return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) +} + +func NextPrevMessage(aerc *widgets.Aerc, args []string) error { + if len(args) > 2 { + return nextPrevMessageUsage(args[0]) + } + var ( + n int = 1 + err error + ) + if len(args) > 1 { + n, err = strconv.Atoi(args[1]) + if err != nil { + return nextPrevMessageUsage(args[0]) + } + } + acct := aerc.SelectedAccount() + for ; n > 0; n-- { + if args[0] == "prev-message" { + acct.Messages().Prev() + } else { + acct.Messages().Next() + } + } + return nil +} -- cgit v1.2.3