Commit 0b0095eeadaf7645b731f277c06e3f19e63ea981

Parents: 44a55d41ad6b5c61c75456414e13aec94b367b02

From: Robin Jarry <robin@jarry.cc>
Date: Sat Aug 12 00:51:41 2023 +0700

complete: allow disabling automatic completion
Allow setting complete-min-chars = manual to disable automatic
completion.

Changelog-added: Setting `complete-min-chars=manual` in `aerc.conf` now
 disables automatic completion, leaving only manually triggered
 completion.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Tim Culverhouse <tim@timculverhouse.com>

Stats

config/aerc.conf +4/-0
config/ui.go +11/-1
doc/aerc-config.5.scd +4/-0
lib/ui/textinput.go +4/-0

Changeset

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
diff --git a/config/aerc.conf b/config/aerc.conf
index d8142197cc9f984a31268027c3eb44bbc12ccca2..0dfab7fc811939a0d7f069a3ed96d57e069de530 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -241,6 +241,10 @@
 # The minimum required characters to allow auto-completion to be triggered after
 # completion-delay.
 #
+# Setting this to "manual" disables automatic completion, leaving only the
+# manually triggered completion with the $complete key (see aerc-binds(5) for
+# more details).
+#
 # Default: 1
 #completion-min-chars=1
 
diff --git a/config/ui.go b/config/ui.go
index 3b637278c2104e5e5ceda99fb70e5a15433859af..17f2339f208b6ab19d2300c172ff9cec6eaf7fb9 100644
--- a/config/ui.go
+++ b/config/ui.go
@@ -3,6 +3,7 @@
 import (
 	"bytes"
 	"fmt"
+	"math"
 	"path"
 	"regexp"
 	"strconv"
@@ -66,7 +67,7 @@ 	DirListCollapse               int           `ini:"dirlist-collapse"`
 	Sort                          []string      `ini:"sort" delim:" "`
 	NextMessageOnDelete           bool          `ini:"next-message-on-delete" default:"true"`
 	CompletionDelay               time.Duration `ini:"completion-delay" default:"250ms"`
-	CompletionMinChars            int           `ini:"completion-min-chars" default:"1"`
+	CompletionMinChars            int           `ini:"completion-min-chars" default:"1" parse:"ParseCompletionMinChars"`
 	CompletionPopovers            bool          `ini:"completion-popovers" default:"true"`
 	StyleSetDirs                  []string      `ini:"stylesets-dirs" delim:":"`
 	StyleSetName                  string        `ini:"styleset-name" default:"default"`
@@ -315,6 +316,15 @@ 		_, _ = section.NewKey("column-subject",
 			`{{.ThreadPrefix}}{{if .ThreadFolded}}{{printf "{%d}" .ThreadCount}}{{end}}{{.Subject}}`)
 	}
 	return ParseColumnDefs(key, section)
+}
+
+const MANUAL_COMPLETE = math.MaxInt
+
+func (*UIConfig) ParseCompletionMinChars(section *ini.Section, key *ini.Key) (int, error) {
+	if key.String() == "manual" {
+		return MANUAL_COMPLETE, nil
+	}
+	return key.Int()
 }
 
 var indexFmtRegexp = regexp.MustCompile(`%(-?\d+)?(\.\d+)?([ACDFRTZadfgilnrstuv])`)
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 34bfb88258362dd2eb96bac48e8b34f4d546f947..ef35fd1247dbdd7d954ce35f87c5a8f23602bc79 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -283,6 +283,10 @@ *completion-min-chars* = _<int>_
 	The minimum required characters to allow auto-completion to be triggered
 	after *completion-delay*.
 
+	Setting this to _manual_ disables automatic completion, leaving only the
+	manually triggered completion with the *$complete* key (see
+	*aerc-binds*(5) for more details).
+
 	Default: _1_
 
 *border-char-vertical* = _"<char>"_++
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index 4b051d884b322ca36855404bcd894cea91afa73c..d1d46045db4a532d819cc4e0ea1036feff67e423 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -308,6 +308,10 @@ 	if ti.tabcomplete == nil {
 		// no completer
 		return
 	}
+	if ti.completeMinChars == config.MANUAL_COMPLETE {
+		// only manually triggered completion
+		return
+	}
 	if ti.completeDebouncer == nil {
 		ti.completeDebouncer = time.AfterFunc(ti.completeDelay, func() {
 			defer log.PanicHandler()