From fca0648232bc0ed55a0fe6e5695feef2170f3592 2008-12-05 20:03:23 From: Jorgen Stenarson Date: 2008-12-05 20:03:23 Subject: [PATCH] merged from trunk --- diff --git a/IPython/Extensions/ipy_editors.py b/IPython/Extensions/ipy_editors.py index c94027c..88e064a 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:") @@ -64,7 +65,10 @@ def idle(exe = None): p = os.path.dirname(idlelib.__file__) exe = p + '/idle.py' install_editor(exe + ' "$file"') - + +def mate(exe = 'mate'): + """ TextMate, the missing editor""" + install_editor(exe + ' -w -l $line "$file"') # these are untested, report any problems diff --git a/IPython/Extensions/ipy_profile_sh.py b/IPython/Extensions/ipy_profile_sh.py index 59776cb..f320a3d 100644 --- a/IPython/Extensions/ipy_profile_sh.py +++ b/IPython/Extensions/ipy_profile_sh.py @@ -8,7 +8,7 @@ compatibility) """ from IPython import ipapi -import os,textwrap +import os,re,textwrap # The import below effectively obsoletes your old-style ipythonrc[.ini], # so consider yourself warned! @@ -129,7 +129,7 @@ def main(): # and the next best thing to real 'ls -F' ip.defalias('d','dir /w /og /on') - ip.set_hook('input_prefilter', dotslash_prefilter_f) + ip.set_hook('input_prefilter', slash_prefilter_f) extend_shell_behavior(ip) class LastArgFinder: @@ -151,13 +151,13 @@ class LastArgFinder: return parts[-1] return "" -def dotslash_prefilter_f(self,line): - """ ./foo now runs foo as system command +def slash_prefilter_f(self,line): + """ ./foo, ~/foo and /bin/foo now run foo as system command - Removes the need for doing !./foo + Removes the need for doing !./foo, !~/foo or !/bin/foo """ import IPython.genutils - if line.startswith("./"): + if re.match('(?:[.~]|/[a-zA-Z_0-9]+)/', line): return "_ip.system(" + IPython.genutils.make_quoted_expr(line)+")" raise ipapi.TryNext diff --git a/IPython/Magic.py b/IPython/Magic.py index b0fdcb9..e45adf9 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -422,7 +422,11 @@ python-profiler package from non-free.""") else: fndoc = 'No documentation' else: - fndoc = fn.__doc__.rstrip() + if fn.__doc__: + fndoc = fn.__doc__.rstrip() + else: + fndoc = 'No documentation' + if mode == 'rest': rest_docs.append('**%s%s**::\n\n\t%s\n\n' %(self.shell.ESC_MAGIC, @@ -2328,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/Shell.py b/IPython/Shell.py index 9023fe6..8f31694 100644 --- a/IPython/Shell.py +++ b/IPython/Shell.py @@ -385,7 +385,7 @@ class MTInteractiveShell(InteractiveShell): Modified version of code.py's runsource(), to handle threading issues. See the original for full docstring details.""" - + global KBINT # If Ctrl-C was typed, we reset the flag and return right away @@ -415,7 +415,7 @@ class MTInteractiveShell(InteractiveShell): if (self.worker_ident is None or self.worker_ident == thread.get_ident() ): InteractiveShell.runcode(self,code) - return + return False # Case 3 # Store code in queue, so the execution thread can handle it. @@ -776,6 +776,17 @@ class IPShellGTK(IPThread): debug=1,shell_class=MTInteractiveShell): import gtk + # Check for set_interactive, coming up in new pygtk. + # Disable it so that this code works, but notify + # the user that he has a better option as well. + # XXX TODO better support when set_interactive is released + try: + gtk.set_interactive(False) + print "Your PyGtk has set_interactive(), so you can use the" + print "more stable single-threaded Gtk mode." + print "See https://bugs.launchpad.net/ipython/+bug/270856" + except AttributeError: + pass self.gtk = gtk self.gtk_mainloop = hijack_gtk() diff --git a/IPython/demo.py b/IPython/demo.py index 0734868..03c7e5d 100644 --- a/IPython/demo.py +++ b/IPython/demo.py @@ -180,7 +180,7 @@ def re_mark(mark): class Demo(object): - re_stop = re_mark('-?\s?stop\s?-?') + re_stop = re_mark('-*\s?stop\s?-*') re_silent = re_mark('silent') re_auto = re_mark('auto') re_auto_all = re_mark('auto_all') 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 34195b6..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): @@ -1572,6 +1576,11 @@ want to merge them back into the new files.""" % locals() else: banner = self.BANNER+self.banner2 + # if you run stuff with -c , raw hist is not updated + # ensure that it's in sync + if len(self.input_hist) != len (self.input_hist_raw): + self.input_hist_raw = InputList(self.input_hist) + while 1: try: self.interact(banner) diff --git a/IPython/kernel/scripts/ipengine.py b/IPython/kernel/scripts/ipengine.py index 97fd2ca..8d9d1b2 100644 --- a/IPython/kernel/scripts/ipengine.py +++ b/IPython/kernel/scripts/ipengine.py @@ -91,7 +91,7 @@ def start_engine(): try: engine_service.execute(shell_import_statement) except: - log.msg("Error running import_statement: %s" % sis) + log.msg("Error running import_statement: %s" % shell_import_statement) # Create the service hierarchy main_service = service.MultiService() @@ -169,4 +169,4 @@ def main(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/docs/source/interactive/reference.txt b/docs/source/interactive/reference.txt index b3a873b..ef60af4 100644 --- a/docs/source/interactive/reference.txt +++ b/docs/source/interactive/reference.txt @@ -2397,9 +2397,11 @@ module, now part of the standard Python library. Input caching system -------------------- -IPython offers numbered prompts (In/Out) with input and output caching. -All input is saved and can be retrieved as variables (besides the usual -arrow key recall). +IPython offers numbered prompts (In/Out) with input and output caching +(also referred to as 'input history'). All input is saved and can be +retrieved as variables (besides the usual arrow key recall), in +addition to the %rep magic command that brings a history entry +up for editing on the next command line. The following GLOBAL variables always exist (so don't overwrite them!): _i: stores previous input. _ii: next previous. _iii: next-next previous. @@ -2432,6 +2434,42 @@ sec. 6.2 <#sec:magic> for more details on the macro system. A history function %hist allows you to see any part of your input history by printing a range of the _i variables. +You can also search ('grep') through your history by typing +'%hist -g somestring'. This also searches through the so called *shadow history*, +which remembers all the commands (apart from multiline code blocks) +you have ever entered. Handy for searching for svn/bzr URL's, IP adrresses +etc. You can bring shadow history entries listed by '%hist -g' up for editing +(or re-execution by just pressing ENTER) with %rep command. Shadow history +entries are not available as _iNUMBER variables, and they are identified by +the '0' prefix in %hist -g output. That is, history entry 12 is a normal +history entry, but 0231 is a shadow history entry. + +Shadow history was added because the readline history is inherently very +unsafe - if you have multiple IPython sessions open, the last session +to close will overwrite the history of previountly closed session. Likewise, +if a crash occurs, history is never saved, whereas shadow history entries +are added after entering every command (so a command executed +in another IPython session is immediately available in other IPython +sessions that are open). + +To conserve space, a command can exist in shadow history only once - it doesn't +make sense to store a common line like "cd .." a thousand times. The idea is +mainly to provide a reliable place where valuable, hard-to-remember commands can +always be retrieved, as opposed to providing an exact sequence of commands +you have entered in actual order. + +Because shadow history has all the commands you have ever executed, +time taken by %hist -g will increase oven time. If it ever starts to take +too long (or it ends up containing sensitive information like passwords), +clear the shadow history by `%clear shadow_nuke`. + +Time taken to add entries to shadow history should be negligible, but +in any case, if you start noticing performance degradation after using +IPython for a long time (or running a script that floods the shadow history!), +you can 'compress' the shadow history by executing +`%clear shadow_compress`. In practice, this should never be necessary +in normal use. + .. _output_caching: Output caching system @@ -2475,7 +2513,7 @@ Directory history Your history of visited directories is kept in the global list _dh, and the magic %cd command can be used to go to any entry in that list. The -%dhist command allows you to view this history. do ``cd -