diff options
author | Jason Cox <me@jasoncarloscox.com> | 2024-02-17 12:34:23 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-02-26 09:30:35 +0100 |
commit | f3a61a341c81d70b51d91a71e1b0909acdcdb8f4 (patch) | |
tree | 58a3156dc63500fd4e0cd0034a59e86cdbb6a3cb /commands/account/cf.go | |
parent | d8d5fc8d31f358c6425dfa18a9f8d2767bc6df40 (diff) | |
download | aerc-f3a61a341c81d70b51d91a71e1b0909acdcdb8f4.tar.gz |
commands: add :query to create named notmuch dirs
The current :cf command can be used to create folders for arbitrary
notmuch queries. These folders use the query as their namee. In some
cases, though, it's useful to give a more human-readable name. Create a
new :query command to allow doing so.
The :query command accepts an optional -n flag to specify a name. The
remaining arguments are interpreted verbatim as a notmuch query. If no
name is specified, the query itself is used as the name.
For example, to create a new folder with the full thread of the current
message, named by its subject, run the following command:
:query -n "{{.SubjectBase}}" thread:"{mid:{{.MessageId}}}"
:query could have been implemented as an additional flag to :cf. Giving
a name to the created folder would make the smantics of :cf strange,
though. For example, to create a named query folder, one would use
:cf -n <name> <query>. This syntax feels odd; the name of the folder
seems like it ought to be the positional argument of the change folder
command. Alternatively, the usage could be :cf -q <query> <name>, but
this feels wrong as well: the query, which is provided as a positional
parameter when no name is specified, becomes a flag parameter when a
name is specified. What's more, both of these potential usages add a
notmuch-specific flag to an otherwise general command. Creating a new
command feels cleaner. Perhaps the current query functionality of the
:cf command could eventually be deprecated to remove the duplicate
functionality and keep :cf limited to changing to existing folders.
Changelog-added: Create notmuch named queries with the `:query`
command.
Signed-off-by: Jason Cox <me@jasoncarloscox.com>
Tested-by: Inwit <inwit@sindominio.net>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/account/cf.go')
-rw-r--r-- | commands/account/cf.go | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go index 2f32e8bc..0f818006 100644 --- a/commands/account/cf.go +++ b/commands/account/cf.go @@ -103,35 +103,39 @@ func (c ChangeFolder) Execute([]string) error { } finalize := func(msg types.WorkerMessage) { - // As we're waiting for the worker to report status we must run - // the rest of the actions in this callback. - switch msg := msg.(type) { - case *types.Error: - app.PushError(msg.Error.Error()) - case *types.Done: - curAccount := app.SelectedAccount() - previous := curAccount.Directories().Selected() - history[curAccount.Name()] = previous - // reset store filtering if we switched folders - store := acct.Store() - if store != nil { - store.ApplyClear() - acct.SetStatus(state.SearchFilterClear()) - } - // focus account tab - acct.Select() - } + handleDirOpenResponse(acct, msg) } if target == "-" { if dir, ok := history[acct.Name()]; ok { - acct.Directories().Open(dir, 0*time.Second, finalize) + acct.Directories().Open(dir, "", 0*time.Second, finalize) } else { return errors.New("No previous folder to return to") } } else { - acct.Directories().Open(target, 0*time.Second, finalize) + acct.Directories().Open(target, "", 0*time.Second, finalize) } return nil } + +func handleDirOpenResponse(acct *app.AccountView, msg types.WorkerMessage) { + // As we're waiting for the worker to report status we must run + // the rest of the actions in this callback. + switch msg := msg.(type) { + case *types.Error: + app.PushError(msg.Error.Error()) + case *types.Done: + curAccount := app.SelectedAccount() + previous := curAccount.Directories().Selected() + history[curAccount.Name()] = previous + // reset store filtering if we switched folders + store := acct.Store() + if store != nil { + store.ApplyClear() + acct.SetStatus(state.SearchFilterClear()) + } + // focus account tab + acct.Select() + } +} |