title: Save a function definition in ipython
body: <p>When using ipython I often want to save specific functions I have defined during my session, e.g.:</p>
  
  <pre><code>In [1]: def func1():
  ...:        pass
  ...: 
  
  In [2]: %save func1.py func1
  func1 is neither a string nor a macro.
  </code></pre>
  
  <p>Instead I have to pick out the function definition line number from <code>enumerate(_ih)</code>, or manually copy and paste from vim if I have <code>%edit</code>'d the function.</p>
  
  <p>Is there a way to achieve <code>%save func1.py func1</code>? I feel like it should be possible as ipython has access to the definition when using %edit.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Line based saving doesn't work if I have at some point edited the function with <code>%ed</code>. I'm looking for a way to save the <em>new</em> function definition in this case.</p>