From e4aeb78803525e49663ca1fa20e5381a679a0e30 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Wed, 19 Oct 2011 15:35:16 +0100 Subject: smarter discovery of editor command This will respect EDITOR env var or use /usr/bin/editor if editor_cmd is unset (default) --- alot/commands/globals.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'alot/commands/globals.py') 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', -- cgit v1.2.3