Skip to content

Commit

Permalink
taglist: allow to restrict tags to displayed messages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mjg committed Oct 23, 2020
1 parent 95c4a35 commit 49065ac
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Expand Down

0 comments on commit 49065ac

Please sign in to comment.