diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2018-06-25 16:17:35 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2018-07-24 22:05:57 +0100 |
commit | 65dad4acfdc45abfc03b56b9a1860c53a0e85912 (patch) | |
tree | 5b8a36cb81282b72a4b51349031518169fc31610 /alot/commands/globals.py | |
parent | 297121e1d6c56424612faa510216b90b1827fad5 (diff) |
new command "savequery"
...that stores a query string as named search.
in Search buffers, this will fall back on the current search string
unless a full query string is provided as (second) argument.
Diffstat (limited to 'alot/commands/globals.py')
-rw-r--r-- | alot/commands/globals.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py index af98694d..92918269 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -994,3 +994,55 @@ class ReloadCommand(Command): except ConfigError as e: ui.notify('Error when reloading config files:\n {}'.format(e), priority='error') + + +@registerCommand( + MODE, 'savequery', + arguments=[ + (['--no-flush'], {'action': 'store_false', 'dest': 'flush', + 'default': 'True', + 'help': 'postpone a writeout to the index'}), + (['alias'], {'help': 'alias to use for query string'}), + (['query'], {'help': 'query string to store', + 'nargs': argparse.REMAINDER}) + ], + help='store query string as a "named query" in the database') +class SaveQueryCommand(Command): + + """save alias for query string""" + repeatable = False + + def __init__(self, alias, query=None, flush=True, **kwargs): + """ + :param alias: name to use for query string + :type alias: str + :param query: query string to save + :type query: str or None + :param flush: immediately write out to the index + :type flush: bool + """ + self.alias = alias + if query is None: + self.query = '' + else: + self.query = ' '.join(query) + self.flush = flush + Command.__init__(self, **kwargs) + + def apply(self, ui): + searchbuffer = ui.current_buffer + query = searchbuffer.querystring + msg = 'saved alias "%s" for query string "%s"' % (self.alias, + self.query) + + try: + ui.dbman.save_named_query(self.alias, self.query) + logging.debug(msg) + ui.notify(msg) + except DatabaseROError: + ui.notify('index in read-only mode', priority='error') + return + + # flush index + if self.flush: + ui.apply_command(commands.globals.FlushCommand()) |