Skip to content

Commit

Permalink
Merge pull request #1657 from tkf/editor-wait-opt
Browse files Browse the repository at this point in the history
Add `wait` optional argument to `hooks.editor`.  As indicated the discussion for #1655 (superseded by this PR), this allows users to define custom magics that can call editors without waiting for a return value.
  • Loading branch information
fperez committed May 10, 2012
2 parents ea9c293 + ceaa52c commit e881f31
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions IPython/core/hooks.py
Expand Up @@ -42,6 +42,7 @@ def calljed(self,filename, linenum):
#*****************************************************************************

import os, bisect
import subprocess
import sys

from IPython.core.error import TryNext
Expand All @@ -54,7 +55,7 @@ def calljed(self,filename, linenum):
'show_in_pager','pre_prompt_hook',
'pre_run_code_hook', 'clipboard_get']

def editor(self,filename, linenum=None):
def editor(self, filename, linenum=None, wait=True):
"""Open the default editor at the given filename and linenumber.
This is IPython's default editor hook, you can use it as an example to
Expand All @@ -76,7 +77,9 @@ def editor(self,filename, linenum=None):
editor = '"%s"' % editor

# Call the actual editor
if os.system('%s %s %s' % (editor,linemark,filename)) != 0:
proc = subprocess.Popen('%s %s %s' % (editor, linemark, filename),
shell=True)
if wait and proc.wait() != 0:
raise TryNext()

import tempfile
Expand Down

0 comments on commit e881f31

Please sign in to comment.