From 49065ac133614302c84cb826f6e26ec8482a60ab Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Sat, 17 Oct 2020 17:16:36 +0200 Subject: [PATCH] taglist: allow to restrict tags to displayed messages Currently, the taglist command runs on the global list of tags. Introduce a flag `msgs` which allows to restrict the taglist to those appearing in the displayed messages of a search or thread buffer. This is basically the same list which `notmuch search --output=tags` would return for the query underlying the search buffer resp. the query for the thread displayed in a thread buffer. --- alot/commands/globals.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/alot/commands/globals.py b/alot/commands/globals.py index f6fe52c9d..7058fd53e 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -555,13 +555,14 @@ def apply(self, ui): @registerCommand(MODE, 'taglist', arguments=[ + (['--msgs'], {'action': 'store_true', 'help': 'list tags from displayed messages'}), (['--tags'], {'nargs': '+', 'help': 'tags to display'}), (['match'], {'nargs': '?', 'help': 'regular expression to match'}), ]) class TagListCommand(Command): """opens taglist buffer""" - def __init__(self, filtfun=lambda x: True, tags=None, match=None, **kwargs): + def __init__(self, filtfun=lambda x: True, tags=None, match=None, msgs=False, **kwargs): """ :param filtfun: filter to apply to displayed list :type filtfun: callable (str->bool) @@ -573,11 +574,20 @@ def __init__(self, filtfun=lambda x: True, tags=None, match=None, **kwargs): self.filtfun = lambda x: pattern.search(x) is not None else: self.filtfun = filtfun + self.msgs = msgs self.tags = tags Command.__init__(self, **kwargs) def apply(self, ui): - tags = self.tags or ui.dbman.get_all_tags() + if self.tags: + tags = self.tags + elif self.msgs and isinstance(ui.current_buffer, buffers.SearchBuffer): + tags = list(ui.dbman.query(ui.current_buffer.querystring). + search_messages().collect_tags()) + elif self.msgs and isinstance(ui.current_buffer, buffers.ThreadBuffer): + tags = list(ui.current_buffer.thread.get_tags()) + else: + tags = ui.dbman.get_all_tags() blists = ui.get_buffers_of_type(buffers.TagListBuffer) if blists: buf = blists[0]