summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-10-19 15:35:16 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-10-19 15:35:16 +0100
commite4aeb78803525e49663ca1fa20e5381a679a0e30 (patch)
tree5ba457abca7be867eb793d68c29ce702fad0d037
parentd648b0f083500debe628d01ef52decc21943946b (diff)
smarter discovery of editor command
This will respect EDITOR env var or use /usr/bin/editor if editor_cmd is unset (default)
-rw-r--r--alot/commands/globals.py17
-rw-r--r--alot/defaults/alot.rc5
2 files changed, 19 insertions, 3 deletions
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index cda492a0..17b37ab2 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -8,6 +8,7 @@ from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import urwid
from twisted.internet import defer
+import logging
from alot.commands import Command, registerCommand
from alot import buffers
@@ -177,11 +178,23 @@ class EditCommand(ExternalCommand):
self.thread = thread
else:
self.thread = settings.config.getboolean('general', 'editor_in_thread')
- editor_cmd = settings.config.get('general', 'editor_cmd')
- ExternalCommand.__init__(self, editor_cmd, path=self.path,
+ self.editor_cmd = None
+ if os.path.isfile('/usr/bin/editor'):
+ self.editor_cmd = '/usr/bin/editor'
+ self.editor_cmd = os.environ.get('EDITOR', self.editor_cmd)
+ self.editor_cmd = settings.config.get('general', 'editor_cmd',
+ fallback=self.editor_cmd)
+ logging.debug('using editor_cmd: %s' %self.editor_cmd)
+
+ ExternalCommand.__init__(self, self.editor_cmd, path=self.path,
spawn=self.spawn, thread=self.thread,
**kwargs)
+ def apply(self, ui):
+ if self.editor_cmd == None:
+ ui.notify('no editor set', priority='error')
+ else:
+ return ExternalCommand.apply(self, ui)
@registerCommand(MODE, 'pyshell',
diff --git a/alot/defaults/alot.rc b/alot/defaults/alot.rc
index 4243e5f0..4255bb86 100644
--- a/alot/defaults/alot.rc
+++ b/alot/defaults/alot.rc
@@ -28,7 +28,10 @@ terminal_cmd = x-terminal-emulator -e
# EDITOR settings #
####################
# editor command
-editor_cmd = /usr/bin/vim -f -c 'set filetype=mail' +
+# if unset, alot will first the EDITOR env variable, then /usr/bin/editor
+#editor_cmd = /usr/bin/vim -f -c 'set filetype=mail' +
+
+# file encoding used by your editor
editor_writes_encoding = UTF-8
# use terminal_command to spawn a new terminal for the editor?