From 0c766661bcf20e8e28ce3d6f9fdb766e4b659d0d 2008-09-20 09:34:38 From: Ville M. Vainio Date: 2008-09-20 09:34:38 Subject: [PATCH] TryNext editor if editor hook fails. Patch by Lukasz Pankowski --- diff --git a/IPython/Extensions/ipy_editors.py b/IPython/Extensions/ipy_editors.py index c94027c..711197d 100644 --- a/IPython/Extensions/ipy_editors.py +++ b/IPython/Extensions/ipy_editors.py @@ -28,7 +28,8 @@ def install_editor(run_template, wait = False): line = 0 cmd = itplns(run_template, locals()) print ">",cmd - os.system(cmd) + if os.system(cmd) != 0: + raise IPython.ipapi.TryNext() if wait: raw_input("Press Enter when done editing:") diff --git a/IPython/Magic.py b/IPython/Magic.py index 93ec51c..e45adf9 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -2332,7 +2332,11 @@ Currently the magic system has the following functions:\n""" # do actual editing here print 'Editing...', sys.stdout.flush() - self.shell.hooks.editor(filename,lineno) + try: + self.shell.hooks.editor(filename,lineno) + except IPython.ipapi.TryNext: + warn('Could not open editor') + return # XXX TODO: should this be generalized for all string vars? # For now, this is special-cased to blocks created by cpaste diff --git a/IPython/hooks.py b/IPython/hooks.py index 6a67264..fdbea8e 100644 --- a/IPython/hooks.py +++ b/IPython/hooks.py @@ -25,7 +25,8 @@ ip = IPython.ipapi.get() def calljed(self,filename, linenum): "My editor hook calls the jed editor directly." print "Calling my own editor, jed ..." - os.system('jed +%d %s' % (linenum,filename)) + if os.system('jed +%d %s' % (linenum,filename)) != 0: + raise ipapi.TryNext() ip.set_hook('editor', calljed) @@ -84,7 +85,8 @@ def editor(self,filename, linenum=None): editor = '"%s"' % editor # Call the actual editor - os.system('%s %s %s' % (editor,linemark,filename)) + if os.system('%s %s %s' % (editor,linemark,filename)) != 0: + raise ipapi.TryNext() import tempfile def fix_error_editor(self,filename,linenum,column,msg): @@ -105,7 +107,8 @@ def fix_error_editor(self,filename,linenum,column,msg): return t = vim_quickfix_file() try: - os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name) + if os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name): + raise ipapi.TryNext() finally: t.close() diff --git a/IPython/iplib.py b/IPython/iplib.py index e5b524f..4084f66 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -1419,8 +1419,12 @@ want to merge them back into the new files.""" % locals() except TypeError: return 0 # always pass integer line and offset values to editor hook - self.hooks.fix_error_editor(e.filename, - int0(e.lineno),int0(e.offset),e.msg) + try: + self.hooks.fix_error_editor(e.filename, + int0(e.lineno),int0(e.offset),e.msg) + except IPython.ipapi.TryNext: + warn('Could not open editor') + return False return True def edit_syntax_error(self):