summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2018-07-01 16:12:49 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2018-07-24 22:05:57 +0100
commit6ab2f27b2c15aab4f340b7770598235b155a06b7 (patch)
tree0db3590cf9a6decc8a982a8abe0f4a632f976c47 /alot
parent7f9215bbe1f089d0d9077bf2bd09d16699b492e5 (diff)
add completion for named queries
This adds a Completer which looks up and completes the alias strings of named queries. Also in this commit the QueryCompleter (which helps building valid query strings in prompts) is extended to make use of the new Completer.
Diffstat (limited to 'alot')
-rw-r--r--alot/completion.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/alot/completion.py b/alot/completion.py
index a14c2ae0..8eb46448 100644
--- a/alot/completion.py
+++ b/alot/completion.py
@@ -123,6 +123,19 @@ class MultipleSelectionCompleter(Completer):
return res
+class NamedQueryCompleter(StringlistCompleter):
+ """complete the name of a named query string"""
+
+ def __init__(self, dbman):
+ """
+ :param dbman: used to look up named query strings in the DB
+ :type dbman: :class:`~alot.db.DBManager`
+ """
+ # mapping of alias to query string (dict str -> str)
+ nqueries = dbman.get_named_queries()
+ StringlistCompleter.__init__(self, list(nqueries))
+
+
class QueryCompleter(Completer):
"""completion for a notmuch query string"""
def __init__(self, dbman):
@@ -134,19 +147,23 @@ class QueryCompleter(Completer):
abooks = settings.get_addressbooks()
self._abookscompleter = AbooksCompleter(abooks, addressesonly=True)
self._tagcompleter = TagCompleter(dbman)
+ self._nquerycompleter = NamedQueryCompleter(dbman)
self.keywords = ['tag', 'from', 'to', 'subject', 'attachment',
- 'is', 'id', 'thread', 'folder']
+ 'is', 'id', 'thread', 'folder', 'query']
def complete(self, original, pos):
mypart, start, end, mypos = self.relevant_part(original, pos)
myprefix = mypart[:mypos]
- m = re.search(r'(tag|is|to|from):(\w*)', myprefix)
+ m = re.search(r'(tag|is|to|from|query):(\w*)', myprefix)
if m:
cmd, _ = m.groups()
- cmdlen = len(cmd) + 1 # length of the keyword part incld colon
+ cmdlen = len(cmd) + 1 # length of the keyword part including colon
if cmd in ['to', 'from']:
localres = self._abookscompleter.complete(mypart[cmdlen:],
mypos - cmdlen)
+ elif cmd in ['query']:
+ localres = self._nquerycompleter.complete(mypart[cmdlen:],
+ mypos - cmdlen)
else:
localres = self._tagcompleter.complete(mypart[cmdlen:],
mypos - cmdlen)