From c0ca7f05ee98b7ec144e5098cbe07cc925f3209d Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Fri, 17 Jul 2020 23:17:15 +0200 Subject: [PATCH 1/4] Enable concatenation of search queries (split by " / ") --- alot/buffers/search.py | 34 ++++++++++++++++++++-------------- alot/walker.py | 8 ++++++++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/alot/buffers/search.py b/alot/buffers/search.py index c3487fd24..278a19bc6 100644 --- a/alot/buffers/search.py +++ b/alot/buffers/search.py @@ -61,20 +61,26 @@ def rebuild(self, reverse=False): if exclude_tags: exclude_tags = [t for t in exclude_tags.split(';') if t] - try: - self.result_count = self.dbman.count_messages(self.querystring) - threads = self.dbman.get_threads( - self.querystring, order, exclude_tags) - except NotmuchError: - self.ui.notify('malformed query string: %s' % self.querystring, - 'error') - self.listbox = urwid.ListBox([]) - self.body = self.listbox - return - - self.threadlist = IterableWalker(threads, ThreadlineWidget, - dbman=self.dbman, - reverse=reverse) + querylist = self.querystring.split(' / ') + for query in querylist: + try: + self.result_count = self.dbman.count_messages(query) + threads = self.dbman.get_threads( + query, order, exclude_tags) + except NotmuchError: + self.ui.notify('malformed query string: %s' % query, + 'error') + self.listbox = urwid.ListBox([]) + self.body = self.listbox + return + + iterablewalker = IterableWalker(threads, ThreadlineWidget, + dbman=self.dbman, + reverse=reverse) + if self.threadlist: + self.threadlist.append(iterablewalker) + else: + self.threadlist = iterablewalker self.listbox = urwid.ListBox(self.threadlist) self.body = self.listbox diff --git a/alot/walker.py b/alot/walker.py index cfefc9e61..c0dac7850 100644 --- a/alot/walker.py +++ b/alot/walker.py @@ -6,6 +6,11 @@ import urwid +def chain(*iterables): + for iterable in iterables: + yield from iterable + + class IterableWalker(urwid.ListWalker): """An urwid walker for iterables. @@ -92,3 +97,6 @@ def _get_next_item(self): def get_lines(self): return self.lines + + def append(self, iterableWalker): + self.iterable = chain(self.iterable, iterableWalker.iterable) From b95e3ce3c69adbd2187401a065c15c6e9a7d59f7 Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Mon, 20 Jul 2020 21:10:45 +0200 Subject: [PATCH 2/4] Use itertools.chain instead of reimplementing it --- alot/walker.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/alot/walker.py b/alot/walker.py index c0dac7850..bdb42797d 100644 --- a/alot/walker.py +++ b/alot/walker.py @@ -2,15 +2,11 @@ # Copyright © 2018 Dylan Baker # This file is released under the GNU GPL, version 3 or a later revision. # For further details see the COPYING file +import itertools import logging import urwid -def chain(*iterables): - for iterable in iterables: - yield from iterable - - class IterableWalker(urwid.ListWalker): """An urwid walker for iterables. @@ -99,4 +95,4 @@ def get_lines(self): return self.lines def append(self, iterableWalker): - self.iterable = chain(self.iterable, iterableWalker.iterable) + self.iterable = itertools.chain(self.iterable, iterableWalker.iterable) From 5840b675cadf910c54edcd9a971a64979a4926d7 Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Mon, 20 Jul 2020 21:13:01 +0200 Subject: [PATCH 3/4] Fix: Show cumulative count for concatenated searches --- alot/buffers/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alot/buffers/search.py b/alot/buffers/search.py index 278a19bc6..89f57fdb4 100644 --- a/alot/buffers/search.py +++ b/alot/buffers/search.py @@ -64,7 +64,7 @@ def rebuild(self, reverse=False): querylist = self.querystring.split(' / ') for query in querylist: try: - self.result_count = self.dbman.count_messages(query) + self.result_count += self.dbman.count_messages(query) threads = self.dbman.get_threads( query, order, exclude_tags) except NotmuchError: From 5cf9bdf00493c29e3af9d879308e924630a20a98 Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Mon, 20 Jul 2020 22:39:14 +0200 Subject: [PATCH 4/4] Fix: Reset result_count and threadlist when rebuilding the search buffer --- alot/buffers/search.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/alot/buffers/search.py b/alot/buffers/search.py index 89f57fdb4..04031a42b 100644 --- a/alot/buffers/search.py +++ b/alot/buffers/search.py @@ -61,6 +61,8 @@ def rebuild(self, reverse=False): if exclude_tags: exclude_tags = [t for t in exclude_tags.split(';') if t] + self.result_count = 0 + self.threadlist = None querylist = self.querystring.split(' / ') for query in querylist: try: