##// END OF EJS Templates
Merging upstream changes from trunk.
Brian Granger -
r1787:200ff92e merge
parent child Browse files
Show More
@@ -28,7 +28,8 b' def install_editor(run_template, wait = False):'
28 line = 0
28 line = 0
29 cmd = itplns(run_template, locals())
29 cmd = itplns(run_template, locals())
30 print ">",cmd
30 print ">",cmd
31 os.system(cmd)
31 if os.system(cmd) != 0:
32 raise IPython.ipapi.TryNext()
32 if wait:
33 if wait:
33 raw_input("Press Enter when done editing:")
34 raw_input("Press Enter when done editing:")
34
35
@@ -64,7 +65,10 b' def idle(exe = None):'
64 p = os.path.dirname(idlelib.__file__)
65 p = os.path.dirname(idlelib.__file__)
65 exe = p + '/idle.py'
66 exe = p + '/idle.py'
66 install_editor(exe + ' "$file"')
67 install_editor(exe + ' "$file"')
67
68
69 def mate(exe = 'mate'):
70 """ TextMate, the missing editor"""
71 install_editor(exe + ' -w -l $line "$file"')
68
72
69 # these are untested, report any problems
73 # these are untested, report any problems
70
74
@@ -8,7 +8,7 b' compatibility)'
8 """
8 """
9
9
10 from IPython import ipapi
10 from IPython import ipapi
11 import os,textwrap
11 import os,re,textwrap
12
12
13 # The import below effectively obsoletes your old-style ipythonrc[.ini],
13 # The import below effectively obsoletes your old-style ipythonrc[.ini],
14 # so consider yourself warned!
14 # so consider yourself warned!
@@ -129,7 +129,7 b' def main():'
129 # and the next best thing to real 'ls -F'
129 # and the next best thing to real 'ls -F'
130 ip.defalias('d','dir /w /og /on')
130 ip.defalias('d','dir /w /og /on')
131
131
132 ip.set_hook('input_prefilter', dotslash_prefilter_f)
132 ip.set_hook('input_prefilter', slash_prefilter_f)
133 extend_shell_behavior(ip)
133 extend_shell_behavior(ip)
134
134
135 class LastArgFinder:
135 class LastArgFinder:
@@ -151,13 +151,13 b' class LastArgFinder:'
151 return parts[-1]
151 return parts[-1]
152 return ""
152 return ""
153
153
154 def dotslash_prefilter_f(self,line):
154 def slash_prefilter_f(self,line):
155 """ ./foo now runs foo as system command
155 """ ./foo, ~/foo and /bin/foo now run foo as system command
156
156
157 Removes the need for doing !./foo
157 Removes the need for doing !./foo, !~/foo or !/bin/foo
158 """
158 """
159 import IPython.genutils
159 import IPython.genutils
160 if line.startswith("./"):
160 if re.match('(?:[.~]|/[a-zA-Z_0-9]+)/', line):
161 return "_ip.system(" + IPython.genutils.make_quoted_expr(line)+")"
161 return "_ip.system(" + IPython.genutils.make_quoted_expr(line)+")"
162 raise ipapi.TryNext
162 raise ipapi.TryNext
163
163
@@ -422,7 +422,11 b' python-profiler package from non-free.""")'
422 else:
422 else:
423 fndoc = 'No documentation'
423 fndoc = 'No documentation'
424 else:
424 else:
425 fndoc = fn.__doc__.rstrip()
425 if fn.__doc__:
426 fndoc = fn.__doc__.rstrip()
427 else:
428 fndoc = 'No documentation'
429
426
430
427 if mode == 'rest':
431 if mode == 'rest':
428 rest_docs.append('**%s%s**::\n\n\t%s\n\n' %(self.shell.ESC_MAGIC,
432 rest_docs.append('**%s%s**::\n\n\t%s\n\n' %(self.shell.ESC_MAGIC,
@@ -2328,7 +2332,11 b' Currently the magic system has the following functions:\\n"""'
2328 # do actual editing here
2332 # do actual editing here
2329 print 'Editing...',
2333 print 'Editing...',
2330 sys.stdout.flush()
2334 sys.stdout.flush()
2331 self.shell.hooks.editor(filename,lineno)
2335 try:
2336 self.shell.hooks.editor(filename,lineno)
2337 except IPython.ipapi.TryNext:
2338 warn('Could not open editor')
2339 return
2332
2340
2333 # XXX TODO: should this be generalized for all string vars?
2341 # XXX TODO: should this be generalized for all string vars?
2334 # For now, this is special-cased to blocks created by cpaste
2342 # For now, this is special-cased to blocks created by cpaste
@@ -385,7 +385,7 b' class MTInteractiveShell(InteractiveShell):'
385
385
386 Modified version of code.py's runsource(), to handle threading issues.
386 Modified version of code.py's runsource(), to handle threading issues.
387 See the original for full docstring details."""
387 See the original for full docstring details."""
388
388
389 global KBINT
389 global KBINT
390
390
391 # If Ctrl-C was typed, we reset the flag and return right away
391 # If Ctrl-C was typed, we reset the flag and return right away
@@ -415,7 +415,7 b' class MTInteractiveShell(InteractiveShell):'
415 if (self.worker_ident is None
415 if (self.worker_ident is None
416 or self.worker_ident == thread.get_ident() ):
416 or self.worker_ident == thread.get_ident() ):
417 InteractiveShell.runcode(self,code)
417 InteractiveShell.runcode(self,code)
418 return
418 return False
419
419
420 # Case 3
420 # Case 3
421 # Store code in queue, so the execution thread can handle it.
421 # Store code in queue, so the execution thread can handle it.
@@ -776,6 +776,17 b' class IPShellGTK(IPThread):'
776 debug=1,shell_class=MTInteractiveShell):
776 debug=1,shell_class=MTInteractiveShell):
777
777
778 import gtk
778 import gtk
779 # Check for set_interactive, coming up in new pygtk.
780 # Disable it so that this code works, but notify
781 # the user that he has a better option as well.
782 # XXX TODO better support when set_interactive is released
783 try:
784 gtk.set_interactive(False)
785 print "Your PyGtk has set_interactive(), so you can use the"
786 print "more stable single-threaded Gtk mode."
787 print "See https://bugs.launchpad.net/ipython/+bug/270856"
788 except AttributeError:
789 pass
779
790
780 self.gtk = gtk
791 self.gtk = gtk
781 self.gtk_mainloop = hijack_gtk()
792 self.gtk_mainloop = hijack_gtk()
@@ -180,7 +180,7 b' def re_mark(mark):'
180
180
181 class Demo(object):
181 class Demo(object):
182
182
183 re_stop = re_mark('-?\s?stop\s?-?')
183 re_stop = re_mark('-*\s?stop\s?-*')
184 re_silent = re_mark('silent')
184 re_silent = re_mark('silent')
185 re_auto = re_mark('auto')
185 re_auto = re_mark('auto')
186 re_auto_all = re_mark('auto_all')
186 re_auto_all = re_mark('auto_all')
@@ -25,7 +25,8 b' ip = IPython.ipapi.get()'
25 def calljed(self,filename, linenum):
25 def calljed(self,filename, linenum):
26 "My editor hook calls the jed editor directly."
26 "My editor hook calls the jed editor directly."
27 print "Calling my own editor, jed ..."
27 print "Calling my own editor, jed ..."
28 os.system('jed +%d %s' % (linenum,filename))
28 if os.system('jed +%d %s' % (linenum,filename)) != 0:
29 raise ipapi.TryNext()
29
30
30 ip.set_hook('editor', calljed)
31 ip.set_hook('editor', calljed)
31
32
@@ -84,7 +85,8 b' def editor(self,filename, linenum=None):'
84 editor = '"%s"' % editor
85 editor = '"%s"' % editor
85
86
86 # Call the actual editor
87 # Call the actual editor
87 os.system('%s %s %s' % (editor,linemark,filename))
88 if os.system('%s %s %s' % (editor,linemark,filename)) != 0:
89 raise ipapi.TryNext()
88
90
89 import tempfile
91 import tempfile
90 def fix_error_editor(self,filename,linenum,column,msg):
92 def fix_error_editor(self,filename,linenum,column,msg):
@@ -105,7 +107,8 b' def fix_error_editor(self,filename,linenum,column,msg):'
105 return
107 return
106 t = vim_quickfix_file()
108 t = vim_quickfix_file()
107 try:
109 try:
108 os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name)
110 if os.system('vim --cmd "set errorformat=%f:%l:%c:%m" -q ' + t.name):
111 raise ipapi.TryNext()
109 finally:
112 finally:
110 t.close()
113 t.close()
111
114
@@ -1419,8 +1419,12 b' want to merge them back into the new files.""" % locals()'
1419 except TypeError:
1419 except TypeError:
1420 return 0
1420 return 0
1421 # always pass integer line and offset values to editor hook
1421 # always pass integer line and offset values to editor hook
1422 self.hooks.fix_error_editor(e.filename,
1422 try:
1423 int0(e.lineno),int0(e.offset),e.msg)
1423 self.hooks.fix_error_editor(e.filename,
1424 int0(e.lineno),int0(e.offset),e.msg)
1425 except IPython.ipapi.TryNext:
1426 warn('Could not open editor')
1427 return False
1424 return True
1428 return True
1425
1429
1426 def edit_syntax_error(self):
1430 def edit_syntax_error(self):
@@ -1572,6 +1576,11 b' want to merge them back into the new files.""" % locals()'
1572 else:
1576 else:
1573 banner = self.BANNER+self.banner2
1577 banner = self.BANNER+self.banner2
1574
1578
1579 # if you run stuff with -c <cmd>, raw hist is not updated
1580 # ensure that it's in sync
1581 if len(self.input_hist) != len (self.input_hist_raw):
1582 self.input_hist_raw = InputList(self.input_hist)
1583
1575 while 1:
1584 while 1:
1576 try:
1585 try:
1577 self.interact(banner)
1586 self.interact(banner)
@@ -91,7 +91,7 b' def start_engine():'
91 try:
91 try:
92 engine_service.execute(shell_import_statement)
92 engine_service.execute(shell_import_statement)
93 except:
93 except:
94 log.msg("Error running import_statement: %s" % sis)
94 log.msg("Error running import_statement: %s" % shell_import_statement)
95
95
96 # Create the service hierarchy
96 # Create the service hierarchy
97 main_service = service.MultiService()
97 main_service = service.MultiService()
@@ -173,4 +173,4 b' def main():'
173
173
174
174
175 if __name__ == "__main__":
175 if __name__ == "__main__":
176 main() No newline at end of file
176 main()
@@ -2397,9 +2397,11 b' module, now part of the standard Python library.'
2397 Input caching system
2397 Input caching system
2398 --------------------
2398 --------------------
2399
2399
2400 IPython offers numbered prompts (In/Out) with input and output caching.
2400 IPython offers numbered prompts (In/Out) with input and output caching
2401 All input is saved and can be retrieved as variables (besides the usual
2401 (also referred to as 'input history'). All input is saved and can be
2402 arrow key recall).
2402 retrieved as variables (besides the usual arrow key recall), in
2403 addition to the %rep magic command that brings a history entry
2404 up for editing on the next command line.
2403
2405
2404 The following GLOBAL variables always exist (so don't overwrite them!):
2406 The following GLOBAL variables always exist (so don't overwrite them!):
2405 _i: stores previous input. _ii: next previous. _iii: next-next previous.
2407 _i: stores previous input. _ii: next previous. _iii: next-next previous.
@@ -2432,6 +2434,42 b' sec. 6.2 <#sec:magic> for more details on the macro system.'
2432 A history function %hist allows you to see any part of your input
2434 A history function %hist allows you to see any part of your input
2433 history by printing a range of the _i variables.
2435 history by printing a range of the _i variables.
2434
2436
2437 You can also search ('grep') through your history by typing
2438 '%hist -g somestring'. This also searches through the so called *shadow history*,
2439 which remembers all the commands (apart from multiline code blocks)
2440 you have ever entered. Handy for searching for svn/bzr URL's, IP adrresses
2441 etc. You can bring shadow history entries listed by '%hist -g' up for editing
2442 (or re-execution by just pressing ENTER) with %rep command. Shadow history
2443 entries are not available as _iNUMBER variables, and they are identified by
2444 the '0' prefix in %hist -g output. That is, history entry 12 is a normal
2445 history entry, but 0231 is a shadow history entry.
2446
2447 Shadow history was added because the readline history is inherently very
2448 unsafe - if you have multiple IPython sessions open, the last session
2449 to close will overwrite the history of previountly closed session. Likewise,
2450 if a crash occurs, history is never saved, whereas shadow history entries
2451 are added after entering every command (so a command executed
2452 in another IPython session is immediately available in other IPython
2453 sessions that are open).
2454
2455 To conserve space, a command can exist in shadow history only once - it doesn't
2456 make sense to store a common line like "cd .." a thousand times. The idea is
2457 mainly to provide a reliable place where valuable, hard-to-remember commands can
2458 always be retrieved, as opposed to providing an exact sequence of commands
2459 you have entered in actual order.
2460
2461 Because shadow history has all the commands you have ever executed,
2462 time taken by %hist -g will increase oven time. If it ever starts to take
2463 too long (or it ends up containing sensitive information like passwords),
2464 clear the shadow history by `%clear shadow_nuke`.
2465
2466 Time taken to add entries to shadow history should be negligible, but
2467 in any case, if you start noticing performance degradation after using
2468 IPython for a long time (or running a script that floods the shadow history!),
2469 you can 'compress' the shadow history by executing
2470 `%clear shadow_compress`. In practice, this should never be necessary
2471 in normal use.
2472
2435 .. _output_caching:
2473 .. _output_caching:
2436
2474
2437 Output caching system
2475 Output caching system
@@ -2475,7 +2513,7 b' Directory history'
2475
2513
2476 Your history of visited directories is kept in the global list _dh, and
2514 Your history of visited directories is kept in the global list _dh, and
2477 the magic %cd command can be used to go to any entry in that list. The
2515 the magic %cd command can be used to go to any entry in that list. The
2478 %dhist command allows you to view this history. do ``cd -<TAB`` to
2516 %dhist command allows you to view this history. Do ``cd -<TAB`` to
2479 conventiently view the directory history.
2517 conventiently view the directory history.
2480
2518
2481
2519
General Comments 0
You need to be logged in to leave comments. Login now