diff options
author | Lucas Hoffmann <l-m-h@web.de> | 2017-07-05 09:46:10 +0200 |
---|---|---|
committer | Lucas Hoffmann <l-m-h@web.de> | 2017-07-11 19:52:10 +0200 |
commit | 203be95b9d9506b17f42879ad62f83307d13e6ab (patch) | |
tree | 6b1668aeacf415c310a60db6c7de036d304ba79a /alot | |
parent | bd2ffd809e911299a387fbc84feede3e556c2a15 (diff) |
Add :tag commands in envelope buffers
Diffstat (limited to 'alot')
-rw-r--r-- | alot/commands/envelope.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 82b87888..5537a31f 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -570,3 +570,58 @@ class EncryptCommand(Command): envelope.encrypt_keys = {} # reload buffer ui.current_buffer.rebuild() + + +@registerCommand( + MODE, 'tag', forced={'action': 'add'}, + arguments=[(['tags'], {'help': 'comma separated list of tags'})], + help='add tags to message', +) +@registerCommand( + MODE, 'retag', forced={'action': 'set'}, + arguments=[(['tags'], {'help': 'comma separated list of tags'})], + help='set message tags.', +) +@registerCommand( + MODE, 'untag', forced={'action': 'remove'}, + arguments=[(['tags'], {'help': 'comma separated list of tags'})], + help='remove tags from message', +) +@registerCommand( + MODE, 'toggletags', forced={'action': 'toggle'}, + arguments=[(['tags'], {'help': 'comma separated list of tags'})], + help='flip presence of tags on message', +) +class TagCommand(Command): + + """manipulate message tags""" + repeatable = True + + def __init__(self, tags=u'', action='add', **kwargs): + """ + :param tags: comma separated list of tagstrings to set + :type tags: unicode + :param action: adds tags if 'add', removes them if 'remove', adds tags + and removes all other if 'set' or toggle individually if + 'toggle' + :type action: str + """ + assert isinstance(tags, unicode), 'tags should be a unicode string' + self.tagsstring = tags + self.action = action + Command.__init__(self, **kwargs) + + def apply(self, ui): + ebuffer = ui.current_buffer + envelope = ebuffer.envelope + tags = {t for t in self.tagsstring.split(',') if t} + old = set(envelope.tags) + if self.action == 'add': + new = old.union(tags) + elif self.action == 'remove': + new = old.difference(tags) + elif self.action == 'set': + new = tags + elif self.action == 'toggle': + new = old.symmetric_difference(tags) + envelope.tags = sorted(new) |