Skip to content

Commit

Permalink
taglist: refine search from buffer
Browse files Browse the repository at this point in the history
When a taglist buffer lists tags from a search or thead buffer (without
`--global`) then selecting a tag lists all messages in the db with that
tag. This feels counter-intuitive.

Instead, remember the original query and refine the query by filtering
on the tag in addition to the original query when the tag is `select`ed.

In addition, introduce a new command `globalselect` which does a global
search with the selected tag. The default key binding is `meta enter`,
complementing the default binding `enter` for `select`.
  • Loading branch information
mjg committed Dec 29, 2020
1 parent b6e965e commit 1a14fd8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion alot/buffers/taglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class TagListBuffer(Buffer):

modename = 'taglist'

def __init__(self, ui, alltags=None, filtfun=lambda x: True):
def __init__(self, ui, alltags=None, filtfun=lambda x: True, querystring=None):
self.filtfun = filtfun
self.ui = ui
self.tags = alltags or []
self.querystring = querystring
self.isinitialized = False
self.rebuild()
Buffer.__init__(self, ui, self.body)
Expand Down
5 changes: 4 additions & 1 deletion alot/commands/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,15 +583,18 @@ def __init__(self, filtfun=lambda x: True, tags=None, match=None, globally=False
Command.__init__(self, **kwargs)

def apply(self, ui):
querystring = None
if self.tags:
tags = self.tags
elif (not self.globally) and isinstance(ui.current_buffer, buffers.SearchBuffer):
tags = ui.dbman.collect_tags(ui.current_buffer.querystring)
querystring = ui.current_buffer.querystring
elif (not self.globally) and isinstance(ui.current_buffer, buffers.ThreadBuffer):
tags = list(ui.current_buffer.thread.get_tags())
querystring = 'thread:%s' % ui.current_buffer.thread.get_thread_id()
else: # self.globally or otherBuffer
tags = ui.dbman.get_all_tags()
ui.buffer_open(buffers.TagListBuffer(ui, tags, self.filtfun))
ui.buffer_open(buffers.TagListBuffer(ui, tags, self.filtfun, querystring))


@registerCommand(MODE, 'namedqueries')
Expand Down
19 changes: 17 additions & 2 deletions alot/commands/taglist.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@
@registerCommand(MODE, 'select')
class TaglistSelectCommand(Command):

"""search for messages with selected tag within original buffer"""
async def apply(self, ui):
tagstring = 'tag:"%s"' % ui.current_buffer.get_selected_tag()
querystring = ui.current_buffer.querystring
if querystring:
fullquerystring = '(%s) AND %s' % (querystring, tagstring)
else:
fullquerystring = tagstring
cmd = SearchCommand(query=[fullquerystring])
await ui.apply_command(cmd)


@registerCommand(MODE, 'globalselect')
class TaglistGlobalSelectCommand(Command):

"""search for messages with selected tag"""
async def apply(self, ui):
tagstring = ui.current_buffer.get_selected_tag()
cmd = SearchCommand(query=['tag:"%s"' % tagstring])
tagstring = 'tag:"%s"' % ui.current_buffer.get_selected_tag()
cmd = SearchCommand(query=[tagstring])
await ui.apply_command(cmd)
1 change: 1 addition & 0 deletions alot/defaults/default.bindings
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ q = exit

[taglist]
enter = select
meta enter = globalselect

[namedqueries]
enter = select
Expand Down
9 changes: 8 additions & 1 deletion docs/source/usage/modes/taglist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ Commands in 'taglist' mode
--------------------------
The following commands are available in taglist mode:

.. _cmd.taglist.globalselect:

.. describe:: globalselect

search for messages with selected tag


.. _cmd.taglist.select:

.. describe:: select

search for messages with selected tag
search for messages with selected tag within original buffer


0 comments on commit 1a14fd8

Please sign in to comment.