diff options
author | Bence Ferdinandy <bence@ferdinandy.com> | 2024-04-13 21:51:57 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-04-14 11:51:03 +0200 |
commit | c70c63cbaac8bb78f7d541a2927789c3567ee0e0 (patch) | |
tree | 02117580a4e49ec688c939dd0a71b635fff3dd93 /commands/account | |
parent | 4d95c5371ecc4d667652bb0f5df43c68823ed08b (diff) | |
download | aerc-c70c63cbaac8bb78f7d541a2927789c3567ee0e0.tar.gz |
notmuch: add completions for :cf, :filter and :search
Add completion of notmuch search-terms for :cf, :filter and :search.
Implements: https://todo.sr.ht/~rjarry/aerc/244
Changelog-added: Notmuch completions for `:cf`, `:filter` and
`:search`.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Tested-by: Julio B <julio.bacel@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/account')
-rw-r--r-- | commands/account/cf.go | 19 | ||||
-rw-r--r-- | commands/account/search.go | 16 |
2 files changed, 31 insertions, 4 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go index e96ab2d6..c6993a23 100644 --- a/commands/account/cf.go +++ b/commands/account/cf.go @@ -3,6 +3,7 @@ package account import ( "errors" "reflect" + "strings" "time" "git.sr.ht/~rjarry/aerc/app" @@ -18,7 +19,7 @@ var history map[string]string type ChangeFolder struct { Account bool `opt:"-a"` - Folder string `opt:"..." complete:"CompleteFolder"` + Folder string `opt:"..." complete:"CompleteFolderAndNotmuch"` } func init() { @@ -34,7 +35,7 @@ func (ChangeFolder) Aliases() []string { return []string{"cf"} } -func (c *ChangeFolder) CompleteFolder(arg string) []string { +func (c *ChangeFolder) CompleteFolderAndNotmuch(arg string) []string { var acct *app.AccountView args := opt.LexArgs(c.Folder) @@ -51,7 +52,7 @@ func (c *ChangeFolder) CompleteFolder(arg string) []string { if acct == nil { return nil } - return commands.FilterList( + retval := commands.FilterList( acct.Directories().List(), arg, func(s string) string { dir := acct.Directories().Directory(s) @@ -61,6 +62,18 @@ func (c *ChangeFolder) CompleteFolder(arg string) []string { return s }, ) + notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker)) + if reflect.TypeOf(notmuch) == reflect.TypeOf(acct.Worker().Backend) { + notmuchcomps := handleNotmuchComplete(arg) + for _, prefix := range notmuch_search_terms { + if strings.HasPrefix(arg, prefix) { + return notmuchcomps + } + } + retval = append(retval, notmuchcomps...) + + } + return retval } func (c ChangeFolder) Execute([]string) error { diff --git a/commands/account/search.go b/commands/account/search.go index e64e8154..f37e094d 100644 --- a/commands/account/search.go +++ b/commands/account/search.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "net/textproto" + "reflect" "strings" "time" @@ -14,6 +15,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib/state" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/models" + "git.sr.ht/~rjarry/aerc/worker/handlers" "git.sr.ht/~rjarry/aerc/worker/types" ) @@ -30,7 +32,7 @@ type SearchFilter struct { Cc []string `opt:"-c" action:"ParseCc" complete:"CompleteAddress"` StartDate time.Time `opt:"-d" action:"ParseDate" complete:"CompleteDate"` EndDate time.Time - Terms string `opt:"..." required:"false"` + Terms string `opt:"..." required:"false" complete:"CompleteNotmuch"` } func init() { @@ -57,6 +59,18 @@ func (*SearchFilter) CompleteDate(arg string) []string { return commands.FilterList(commands.GetDateList(), arg, commands.QuoteSpace) } +func (*SearchFilter) CompleteNotmuch(arg string) []string { + acct := app.SelectedAccount() + if acct == nil { + return nil + } + notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker)) + if reflect.TypeOf(notmuch) != reflect.TypeOf(acct.Worker().Backend) { + return nil + } + return handleNotmuchComplete(arg) +} + func (s *SearchFilter) ParseRead(arg string) error { s.WithFlags |= models.SeenFlag s.WithoutFlags &^= models.SeenFlag |