From 1ed6a9682667f084f4611c39281a1d15fb5bc7b3 2006-01-18 19:24:48 From: fperez Date: 2006-01-18 19:24:48 Subject: [PATCH] - Manual updates - Small %edit fix. --- diff --git a/IPython/Magic.py b/IPython/Magic.py index f159c49..2849af4 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Magic functions for InteractiveShell. -$Id: Magic.py 1029 2006-01-18 07:33:38Z fperez $""" +$Id: Magic.py 1030 2006-01-18 19:24:48Z fperez $""" #***************************************************************************** # Copyright (C) 2001 Janko Hauser and @@ -1935,18 +1935,16 @@ Currently the magic system has the following functions:\n""" print else: print 'done. Executing edited code...' + self.shell.safe_execfile(filename,self.shell.user_ns) + if use_temp: try: - self.shell.safe_execfile(filename,self.shell.user_ns) + return open(filename).read() except IOError,msg: if msg.filename == filename: warn('File not found. Did you forget to save?') return else: self.shell.showtraceback() - except: - self.shell.showtraceback() - if use_temp: - return open(filename).read() def magic_xmode(self,parameter_s = ''): """Switch modes for the exception handlers. diff --git a/doc/ChangeLog b/doc/ChangeLog index b30bfcd..f92917a 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2006-01-18 Fernando Perez + + * IPython/Magic.py (magic_edit): fix check for when users don't + save their output files, the try/except was in the wrong section. + 2006-01-17 Fernando Perez * IPython/Magic.py (magic_run): fix __file__ global missing from diff --git a/doc/manual_base.lyx b/doc/manual_base.lyx index e39d2c8..42d6f19 100644 --- a/doc/manual_base.lyx +++ b/doc/manual_base.lyx @@ -2474,6 +2474,121 @@ all %save \family default allows you to select which lines of input you need to save. +\layout Subsubsection* + +Lightweight 'version control' +\layout Standard + +When you call +\family typewriter +%edit +\family default + with no arguments, IPython opens an empty editor with a temporary file, + and it returns the contents of your editing session as a string variable. + Thanks to IPython's output caching mechanism, this is automatically stored: +\layout LyX-Code + +In [1]: %edit +\layout LyX-Code + +IPython will make a temporary file named: /tmp/ipython_edit_yR-HCN.py +\layout LyX-Code + +Editing... + done. + Executing edited code... +\layout LyX-Code + +hello - this is a temporary file +\layout LyX-Code + +Out[1]: "print 'hello - this is a temporary file' +\backslash +n" +\layout Standard + +Now, if you call +\family typewriter +`%edit -p' +\family default +, IPython tries to open an editor with the same data as the last time you + used +\family typewriter +%edit +\family default +. + So if you haven't used +\family typewriter +%edit +\family default + in the meantime, this same contents will reopen; however, it will be done + in a +\emph on +new file +\emph default +. + This means that if you make changes and you later want to find an old version, + you can always retrieve it by using its output number, via +\family typewriter +`%edit _NN' +\family default +, where +\family typewriter +NN +\family default + is the number of the output prompt. +\layout Standard + +Continuing with the example above, this should illustrate this idea: +\layout LyX-Code + +In [2]: edit -p +\layout LyX-Code + +IPython will make a temporary file named: /tmp/ipython_edit_nA09Qk.py +\layout LyX-Code + +Editing... + done. + Executing edited code... +\layout LyX-Code + +hello - now I made some changes +\layout LyX-Code + +Out[2]: "print 'hello - now I made some changes' +\backslash +n" +\layout LyX-Code + +In [3]: edit _1 +\layout LyX-Code + +IPython will make a temporary file named: /tmp/ipython_edit_gy6-zD.py +\layout LyX-Code + +Editing... + done. + Executing edited code... +\layout LyX-Code + +hello - this is a temporary file +\layout LyX-Code + +IPython version control at work :) +\layout LyX-Code + +Out[3]: "print 'hello - this is a temporary file' +\backslash +nprint 'IPython version control at work :)' +\backslash +n" +\layout Standard + +This section was written after a contribution by Alexander Belchenko on + the IPython user list. +\layout LyX-Code + \layout Subsection Effective logging