From 1bceeca953cda102923bb67dfbc8488bae5d35cc Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 24 May 2020 14:23:34 +0200 Subject: Allow designating certain tags as "property" tags. Those are tags like attachment, signed, sent, etc., which are set automatically based on message properties and are typically not changed manually. Such designated tags are not affected by the retag operation. --- alot/commands/common.py | 18 ++++++++++-------- alot/db/manager.py | 5 ++++- alot/defaults/alot.rc.spec | 7 +++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/alot/commands/common.py b/alot/commands/common.py index 8280a5c0..4914933c 100644 --- a/alot/commands/common.py +++ b/alot/commands/common.py @@ -7,6 +7,7 @@ from . import Command from .globals import PromptCommand +from ..settings.const import settings class RetagPromptCommand(Command): @@ -18,13 +19,14 @@ class RetagPromptCommand(Command): item = get_selected_item() if not item: return - tags = [] - for tag in item.get_tags(): - if ' ' in tag: - tags.append('"%s"' % tag) - # skip empty tags - elif tag: - tags.append(tag) - initial_tagstring = ','.join(sorted(tags)) + ',' + + exclude_tags = frozenset(settings.get('property_tags')) + tags = map(lambda x: ("%s" % x) if ' ' in x else x, + item.get_tags() - exclude_tags) + + initial_tagstring = ','.join(sorted(tags)) + if initial_tagstring: + initial_tagstring += ',' + r = await ui.apply_command(PromptCommand('retag ' + initial_tagstring)) return r diff --git a/alot/db/manager.py b/alot/db/manager.py index 6424f32f..cf452c42 100644 --- a/alot/db/manager.py +++ b/alot/db/manager.py @@ -84,6 +84,7 @@ class DBManager: """constants representing sort orders""" _exclude_tags = None + _property_tags = None def __init__(self, path=None, ro=False): """ @@ -98,6 +99,7 @@ class DBManager: self.processes = [] self._exclude_tags = frozenset(settings.get('exclude_tags')) + self._property_tags = frozenset(settings.get('property_tags')) def _db_ro(self): return Database(path = self.path, mode = Database.MODE.READ_ONLY) @@ -159,8 +161,9 @@ class DBManager: if cmd == 'tag': msg_tags |= op_tags if cmd == 'set': + property_tags = msg_tags & self._property_tags msg_tags.clear() - msg_tags |= op_tags + msg_tags |= op_tags | property_tags elif cmd == 'untag': msg_tags -= op_tags diff --git a/alot/defaults/alot.rc.spec b/alot/defaults/alot.rc.spec index 943bfe16..46572758 100644 --- a/alot/defaults/alot.rc.spec +++ b/alot/defaults/alot.rc.spec @@ -14,6 +14,13 @@ input_timeout = float(default=1.0) # .. note:: this config setting is equivalent to, but independent of, the 'search.exclude_tags' in the notmuch config. exclude_tags = force_list(default=list()) +# A list of tags that are considered message "properties", and will not be +# normally touched. Specifically, these tags will not be removed by the retag +# operation, and will excluded from completion. +# Using a property-tag in an explicit add or remove operation will still work +# normally. +property_tags = force_list(default=list(attachment,encrypted,signed,sent,replied)) + # confirm exit bug_on_exit = boolean(default=False) -- cgit v1.2.3