aboutsummaryrefslogtreecommitdiffstats
path: root/_config
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-12-08 14:17:30 +0800
committerAaron LI <aly@aaronly.me>2018-12-08 14:17:30 +0800
commit17e0a08fcafdb7b8e17a31257e296348d041f1ce (patch)
treea131ae07c4b354565a8fc59d128d4d1c9c01debb /_config
parent17d87589ac915d47fff85cca14a58042b5f48f20 (diff)
downloaddotfiles-17e0a08fcafdb7b8e17a31257e296348d041f1ce.tar.bz2
alot: Add new hooks
Diffstat (limited to '_config')
-rw-r--r--_config/alot/hooks.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/_config/alot/hooks.py b/_config/alot/hooks.py
index 9447689..806959e 100644
--- a/_config/alot/hooks.py
+++ b/_config/alot/hooks.py
@@ -7,13 +7,32 @@
import re
+import alot
+
# Check for missing attachment before sending
#
async def pre_envelope_send(ui, dbm, __):
- p = r'.*([Aa]ttach|附件|附图)'
+ p = r'.*([Aa]ttach|附件|附图|已附|所附)'
e = ui.current_buffer.envelope
if re.match(p, e.body, re.DOTALL) and not e.attachments:
msg = 'No attachments. Send anyway?'
if not (await ui.choice(msg, select='yes')) == 'yes':
raise Exception()
+
+
+# Save marked position in search buffer
+#
+def pre_buffer_open(ui, dbm, buf):
+ current = ui.current_buffer
+ if isinstance(current, alot.buffers.SearchBuffer):
+ current.focused_thread = current.get_selected_thread()
+
+def post_buffer_focus(ui, dbm, buf, success):
+ if success and hasattr(buf, "focused_thread"):
+ if buf.focused_thread:
+ tid = buf.focused_thread.get_thread_id()
+ for pos, tlw in enumerate(buf.threadlist.get_lines()):
+ if tlw.get_thread().get_thread_id() == tid:
+ buf.body.set_focus(pos)
+ break