summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpazz <patricktotzke@gmail.com>2011-07-30 17:23:07 +0100
committerpazz <patricktotzke@gmail.com>2011-07-30 17:23:07 +0100
commite432307a1ebfe53910145d7d082a37a6307e2da7 (patch)
treeb3a51db08adf66b5ac46748c1648091f29076fbf
parentd1877b113870f32d1cfcfe8b89a27513d33b9b24 (diff)
cleared settings: mappings can be defined via cfg.
issue #19
-rw-r--r--alot/message.py7
-rw-r--r--alot/settings.py123
-rw-r--r--alot/ui.py3
-rw-r--r--data/example.rc3
4 files changed, 64 insertions, 72 deletions
diff --git a/alot/message.py b/alot/message.py
index 2930dbde..b1ea7484 100644
--- a/alot/message.py
+++ b/alot/message.py
@@ -201,6 +201,7 @@ def decode_to_unicode(part):
raw_payload = unicode(raw_payload, errors='replace')
return raw_payload
+
def decode_header(header):
valuelist = email.header.decode_header(header)
value = u''
@@ -209,10 +210,11 @@ def decode_header(header):
value = value + v.decode(enc)
else:
value = value + v
- value = value.replace('\r','')
- value = value.replace('\n',' ')
+ value = value.replace('\r', '')
+ value = value.replace('\n', ' ')
return value
+
def encode_header(key, value):
if key.lower() in ['from', 'to', 'cc', 'bcc']:
rawentries = value.split(',')
@@ -233,6 +235,7 @@ def encode_header(key, value):
value = Header(value.encode('ascii', errors='replace'))
return value
+
class Attachment:
"""represents a single mail attachment"""
diff --git a/alot/settings.py b/alot/settings.py
index d23b4bfa..bd52d2e8 100644
--- a/alot/settings.py
+++ b/alot/settings.py
@@ -19,7 +19,6 @@ Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com>
import imp
import os
import mailcap
-import logging
from ConfigParser import SafeConfigParser
from account import Account
@@ -191,6 +190,48 @@ DEFAULTS = {
'threadline_tags_focus_bg': 'g58',
'threadline_tags_focus_fg': '#ff8',
},
+ 'global-maps': {
+ '@': 'refresh',
+ 'I': 'search tag:inbox AND NOT tag:killed',
+ 'U': 'search tag:unread',
+ 'x': 'close',
+ 'tab': 'bnext',
+ 'shift tab': 'bprevious',
+ '\\': 'prompt search ',
+ 'q': 'exit',
+ ';': 'bufferlist',
+ ':': 'prompt',
+ 'L': 'taglist',
+ 's': 'shell',
+ '$': 'flush',
+ '@': 'refresh',
+ 'm': 'compose',
+ },
+ 'search-maps': {
+ '|': 'refineprompt',
+ 'enter': 'openthread',
+ 'l': 'retagprompt',
+ 'a': 'toggletag inbox',
+ '&': 'toggletag killed',
+ },
+ 'thread-maps': {
+ 'a': 'toggletag inbox',
+ 'r': 'reply',
+ 'g': 'groupreply',
+ },
+ 'taglist-maps': {
+ 'enter': 'select',
+ },
+ 'envelope-maps': {
+ 'y': 'send',
+ 'enter': 'reedit',
+ 't': 'prompt to',
+ 's': 'prompt subject',
+ },
+ 'bufferlist-maps': {
+ 'd': 'closefocussed',
+ 'enter': 'openfocussed',
+ }
}
@@ -199,14 +240,18 @@ class CustomConfigParser(SafeConfigParser):
self.defaults = defaults
self.hooks = None
SafeConfigParser.__init__(self)
+ self.optionxform = str
for sec in defaults.keys():
self.add_section(sec)
def get(self, section, option, *args, **kwargs):
if self.has_option(section, option):
return SafeConfigParser.get(self, section, option, *args, **kwargs)
+ elif section in self.defaults:
+ if option in self.defaults[section]:
+ return self.defaults[section][option]
else:
- return self.defaults[section][option]
+ return None
def getstringlist(self, section, option, **kwargs):
value = self.get(section, option, **kwargs)
@@ -235,6 +280,12 @@ class CustomConfigParser(SafeConfigParser):
))
return p
+ def get_mapping(self, mode, key):
+ cmdline = self.get(mode + '-maps', key)
+ if not cmdline:
+ cmdline = self.get('global-maps', key)
+ return cmdline
+
class HookManager:
def setup(self, hooksfile):
@@ -254,7 +305,6 @@ class HookManager:
def f(*args, **kwargs):
msg = 'called undefined hook: %s with arguments'
- logging.debug(msg % key)
return f
def call(self, hookname, *args, **kwargs):
@@ -262,8 +312,8 @@ class HookManager:
try:
hook(*args, **kwargs)
except:
- msg = 'exception occured while calling hook: %s with arguments %s, %s'
- logging.exception(msg % hookname, args, kwargs)
+ msg = 'exception occured while calling hook:' \
+ '%s with arguments %s, %s'
config = CustomConfigParser(DEFAULTS)
@@ -285,66 +335,3 @@ def get_mime_handler(mime_type, key, interactive=True):
return mc_tuple[1][key]
else:
return None
-
-# maps mode to keybingins: for each one,
-# a key is mapped to a pair cmdline, helpstring.
-MAPPING = {
- 'global': {
- '@': ('refresh', ''),
- 'I': ('search tag:inbox AND NOT tag:killed', 'open Inbox'),
- 'U': ('search tag:unread', 'open unread'),
- 'x': ('close', 'close buffer'),
- 'tab': ('bnext', 'next buffer'),
- 'shift tab': ('bprevious', 'previous buffer'),
- '\\': ('prompt search ', ''),
- 'q': ('exit', ''),
- ';': ('bufferlist', ''),
- ':': ('prompt', ''),
- 'L': ('taglist', ''),
- 's': ('shell', ''),
- '$': ('flush', ''),
- '@': ('refresh', 'refresh current buffer'),
- 'm': ('compose', ''),
- },
- 'search': {
- '|': ('refineprompt', ''),
- 'enter': ('openthread', ''),
- 'l': ('retagprompt', ''),
- 'a': ('toggletag inbox', ''),
- '&': ('toggletag killed', ''),
- },
- 'thread': {
- 'a': ('toggletag inbox', ''),
- 'r': ('reply', ''),
- 'g': ('groupreply', ''),
- },
- 'taglist': {
- 'enter': ('select', ''),
- },
- 'envelope': {
- 'y': ('send', ''),
- 'enter': ('reedit', ''),
- 't': ('prompt to', ''),
- 's': ('prompt subject', ''),
- },
- 'bufferlist': {
- 'd': ('closefocussed', ''),
- 'enter': ('openfocussed', ''),
- }
-}
-
-
-def get_mappings_by_mode(mode):
- if not mode in MAPPING:
- return None # invalid mode string
- maps = MAPPING['global'].copy()
- maps.update(MAPPING[mode])
- return maps
-
-
-def get_mapping(key, mode):
- maps = get_mappings_by_mode(mode)
- if key in maps:
- return maps[key]
- else:
- return None, None
diff --git a/alot/ui.py b/alot/ui.py
index 64336318..1f28e701 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -21,7 +21,6 @@ import os
from urwid.command_map import command_map
from settings import config
-from settings import get_mapping
from buffer import BufferlistBuffer
from command import commandfactory
from command import interpret_commandline
@@ -222,7 +221,7 @@ class UI:
return urwid.AttrMap(columns, 'footer')
def keypress(self, key):
- cmdline, helpstring = get_mapping(key, self.mode)
+ cmdline = config.get_mapping(self.mode, key)
if cmdline:
self.logger.debug("handle %s in %s mode" % (key, self.mode))
if cmdline.startswith('prompt'):
diff --git a/data/example.rc b/data/example.rc
index 6d5996fa..3580597d 100644
--- a/data/example.rc
+++ b/data/example.rc
@@ -173,3 +173,6 @@ threadline_tags_bg = default
threadline_tags_fg = #a86
threadline_tags_focus_bg = g11
threadline_tags_focus_fg = #ff8
+
+[search-maps]
+t = toggletag todo