Skip to content

Commit

Permalink
Reinstate newlines in %save and %macro, first part of issue 245.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Feb 5, 2011
1 parent 2ccc90d commit cf5ffcf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion IPython/core/macro.py
Expand Up @@ -21,7 +21,7 @@ class Macro(IPyAutocall):

def __init__(self,data):
"""store the macro value, as a single string which can be executed"""
self.value = ''.join(data).rstrip()+'\n'
self.value = '\n'.join(data).rstrip()+'\n'

def __str__(self):
return self.value
Expand Down
9 changes: 4 additions & 5 deletions IPython/core/magic.py
Expand Up @@ -200,7 +200,7 @@ def extract_input_slices(self,slices,raw=False):
else:
ini = int(chunk)
fin = ini+1
cmds.append(''.join(hist[ini:fin]))
cmds.append('\n'.join(hist[ini:fin]))
return cmds

def arg_err(self,func):
Expand Down Expand Up @@ -2013,10 +2013,9 @@ def magic_save(self,parameter_s = ''):
if ans.lower() not in ['y','yes']:
print 'Operation cancelled.'
return
cmds = ''.join(self.extract_input_slices(ranges,opts.has_key('r')))
f = file(fname,'w')
f.write(cmds)
f.close()
cmds = '\n'.join(self.extract_input_slices(ranges,opts.has_key('r')))
with open(fname,'w') as f:
f.write(cmds)
print 'The following commands were written to file `%s`:' % fname
print cmds

Expand Down

0 comments on commit cf5ffcf

Please sign in to comment.