##// END OF EJS Templates
%cpaste: assign to pasted_blck before exec (to have it survive exceptions, %cpaste rep re-executes previously pasted block
Ville M. Vainio -
Show More
@@ -3210,6 +3210,8 b' Defaulting color scheme to \'NoColor\'"""'
3210 This assigns the pasted block to variable 'foo' as string, without
3210 This assigns the pasted block to variable 'foo' as string, without
3211 dedenting or executing it (preceding >>> and + is still stripped)
3211 dedenting or executing it (preceding >>> and + is still stripped)
3212
3212
3213 '%cpaste rep' re-executes the block previously entered by cpaste.
3214
3213 Do not be alarmed by garbled output on Windows (it's a readline bug).
3215 Do not be alarmed by garbled output on Windows (it's a readline bug).
3214 Just press enter and type -- (and press enter again) and the block
3216 Just press enter and type -- (and press enter again) and the block
3215 will be what was just pasted.
3217 will be what was just pasted.
@@ -3218,6 +3220,15 b' Defaulting color scheme to \'NoColor\'"""'
3218 """
3220 """
3219 opts,args = self.parse_options(parameter_s,'s:',mode='string')
3221 opts,args = self.parse_options(parameter_s,'s:',mode='string')
3220 par = args.strip()
3222 par = args.strip()
3223 if par == 'rep':
3224 b = self.user_ns.get('pasted_block', None)
3225 if b is None:
3226 raise UsageError('No previous pasted block available')
3227 print "Re-executing '%s...' (%d chars)"% (b.split('\n',1)[0], len(b))
3228 exec b in self.user_ns
3229
3230 return
3231
3221 sentinel = opts.get('s','--')
3232 sentinel = opts.get('s','--')
3222
3233
3223 # Regular expressions that declare text we strip from the input:
3234 # Regular expressions that declare text we strip from the input:
@@ -3245,8 +3256,8 b' Defaulting color scheme to \'NoColor\'"""'
3245 #print "block:\n",block
3256 #print "block:\n",block
3246 if not par:
3257 if not par:
3247 b = textwrap.dedent(block)
3258 b = textwrap.dedent(block)
3248 exec b in self.user_ns
3249 self.user_ns['pasted_block'] = b
3259 self.user_ns['pasted_block'] = b
3260 exec b in self.user_ns
3250 else:
3261 else:
3251 self.user_ns[par] = SList(block.splitlines())
3262 self.user_ns[par] = SList(block.splitlines())
3252 print "Block assigned to '%s'" % par
3263 print "Block assigned to '%s'" % par
General Comments 0
You need to be logged in to leave comments. Login now