diff options
author | Robin Jarry <robin@jarry.cc> | 2023-08-12 00:51:41 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-11-02 16:30:47 +0100 |
commit | 44a55d41ad6b5c61c75456414e13aec94b367b02 (patch) | |
tree | 8c82e4a02cda4210d39af99d63865e260f01992d /config | |
parent | c4e6de9d59cc534171fd0ef9fa51995e70a8b32e (diff) | |
download | aerc-44a55d41ad6b5c61c75456414e13aec94b367b02.tar.gz |
complete: allow setting the completion key binding
Until now, if less than complete-min-chars were entered or if
completion-delay had not expired yet, the only way to force trigger
completion was to press <tab>.
In some cases, <tab> is already bound to another action (for example
:next-field in the compose::editor context). This makes forcing the
completion impossible.
Allow defining a key to trigger manual completion via the new $complete
special entry in binds.conf.
Leave the default binding to <tab>. Set it to <C-o> in the
[compose::editor] to avoid conflicting with the existing <tab> binding.
Changelog-added: Customize key to trigger completion with `$complete` in
`binds.conf`.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'config')
-rw-r--r-- | config/binds.conf | 1 | ||||
-rw-r--r-- | config/binds.go | 32 |
2 files changed, 23 insertions, 10 deletions
diff --git a/config/binds.conf b/config/binds.conf index a38795d5..58d81508 100644 --- a/config/binds.conf +++ b/config/binds.conf @@ -115,6 +115,7 @@ $ex = <C-x> # view $noinherit = true $ex = <C-x> +$complete = <C-o> <C-k> = :prev-field<Enter> <C-Up> = :prev-field<Enter> <C-j> = :next-field<Enter> diff --git a/config/binds.go b/config/binds.go index 4552030d..1ea36a2d 100644 --- a/config/binds.go +++ b/config/binds.go @@ -57,6 +57,8 @@ type KeyBindings struct { Globals bool // Which key opens the ex line (default is :) ExKey KeyStroke + // Which key triggers completion (default is <tab>) + CompleteKey KeyStroke // private contextualBinds []*BindingConfigContext @@ -154,7 +156,8 @@ func parseBinds(root string) error { func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) { bindings := NewKeyBindings() for key, value := range sec.KeysHash() { - if key == "$ex" { + switch key { + case "$ex": strokes, err := ParseKeyStrokes(value) if err != nil { return nil, err @@ -163,9 +166,7 @@ func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) { return nil, errors.New("Invalid binding") } bindings.ExKey = strokes[0] - continue - } - if key == "$noinherit" { + case "$noinherit": if value == "false" { continue } @@ -173,13 +174,22 @@ func LoadBindingSection(sec *ini.Section) (*KeyBindings, error) { return nil, errors.New("Invalid binding") } bindings.Globals = false - continue - } - binding, err := ParseBinding(key, value) - if err != nil { - return nil, err + case "$complete": + strokes, err := ParseKeyStrokes(value) + if err != nil { + return nil, err + } + if len(strokes) != 1 { + return nil, errors.New("Invalid binding") + } + bindings.CompleteKey = strokes[0] + default: + binding, err := ParseBinding(key, value) + if err != nil { + return nil, err + } + bindings.Add(binding) } - bindings.Add(binding) } return bindings, nil } @@ -266,6 +276,7 @@ func LoadBinds(binds *ini.File, baseName string, baseGroup **KeyBindings) error func NewKeyBindings() *KeyBindings { return &KeyBindings{ ExKey: KeyStroke{tcell.ModNone, tcell.KeyRune, ':'}, + CompleteKey: KeyStroke{tcell.ModNone, tcell.KeyTab, 0}, Globals: true, contextualCache: make(map[bindsContextKey]*KeyBindings), contextualCounts: make(map[bindsContextType]int), @@ -329,6 +340,7 @@ func MergeBindings(bindings ...*KeyBindings) *KeyBindings { } merged.Bindings = filterAndCleanBindings(merged.Bindings) merged.ExKey = bindings[0].ExKey + merged.CompleteKey = bindings[0].CompleteKey merged.Globals = bindings[0].Globals return merged } |