##// END OF EJS Templates
Honor 'readline 0' setting when readline is installed, closes \#178
vivainio -
Show More
@@ -7,13 +7,11 b' ip = IPython.ipapi.get()'
7
7
8 import os,sys
8 import os,sys
9
9
10 def restore_env(self):
10 def restore_env(self):
11 ip = self.getapi()
11 ip = self.getapi()
12 env = ip.db.get('stored_env', {'set' : {}, 'add' : [], 'pre' : []})
12 env = ip.db.get('stored_env', {'set' : {}, 'add' : [], 'pre' : []})
13 for k,v in env['set'].items():
13 for k,v in env['set'].items():
14 #print "restore alias",k,v # dbg
15 os.environ[k] = v
14 os.environ[k] = v
16 self.alias_table[k] = v
17 for k,v in env['add']:
15 for k,v in env['add']:
18 os.environ[k] = os.environ.get(k,"") + v
16 os.environ[k] = os.environ.get(k,"") + v
19 for k,v in env['pre']:
17 for k,v in env['pre']:
@@ -90,9 +90,11 b' def main():'
90 def mapper(s): return s.lower()
90 def mapper(s): return s.lower()
91
91
92 for cmd in syscmds:
92 for cmd in syscmds:
93 #print "al",cmd
93 # print "sys",cmd #dbg
94 noext, ext = os.path.splitext(cmd)
94 noext, ext = os.path.splitext(cmd)
95 ip.IP.alias_table[mapper(noext)] = (0,cmd)
95 key = mapper(noext)
96 if key not in ip.IP.alias_table:
97 ip.defalias(key, cmd)
96
98
97 if 'ls' in syscmds:
99 if 'ls' in syscmds:
98 # use the colors of cygwin ls (recommended)
100 # use the colors of cygwin ls (recommended)
@@ -184,6 +184,9 b' class IPApi:'
184 self.IP = ip
184 self.IP = ip
185
185
186 self.extensions = {}
186 self.extensions = {}
187
188 self.dbg = DebugTools(self)
189
187 global _recent
190 global _recent
188 _recent = self
191 _recent = self
189
192
@@ -222,6 +225,11 b' class IPApi:'
222
225
223 import new
226 import new
224 im = new.instancemethod(func,self.IP, self.IP.__class__)
227 im = new.instancemethod(func,self.IP, self.IP.__class__)
228 old = getattr(self.IP, "magic_" + magicname, None)
229 if old:
230 self.dbg.debug_stack("Magic redefinition '%s', old %s" % (magicname,
231 old))
232
225 setattr(self.IP, "magic_" + magicname, im)
233 setattr(self.IP, "magic_" + magicname, im)
226
234
227 def ex(self,cmd):
235 def ex(self,cmd):
@@ -355,7 +363,15 b' class IPApi:'
355
363
356 Creates a new alias named 'bb' in ipython user namespace
364 Creates a new alias named 'bb' in ipython user namespace
357 """
365 """
366
367 self.dbg.check_hotname(name)
358
368
369
370 if name in self.IP.alias_table:
371 self.dbg.debug_stack("Alias redefinition: '%s' => '%s' (old '%s')" %
372 (name, cmd, self.IP.alias_table[name]))
373
374
359 if callable(cmd):
375 if callable(cmd):
360 self.IP.alias_table[name] = cmd
376 self.IP.alias_table[name] = cmd
361 import IPython.shadowns
377 import IPython.shadowns
@@ -368,7 +384,11 b' class IPApi:'
368 raise Exception('The %s and %l specifiers are mutually exclusive '
384 raise Exception('The %s and %l specifiers are mutually exclusive '
369 'in alias definitions.')
385 'in alias definitions.')
370
386
371 self.IP.alias_table[name] = (nargs,cmd)
387 self.IP.alias_table[name] = (nargs,cmd)
388 return
389
390 # just put it in - it's probably (0,'foo')
391 self.IP.alias_table[name] = cmd
372
392
373 def defmacro(self, *args):
393 def defmacro(self, *args):
374 """ Define a new macro
394 """ Define a new macro
@@ -419,7 +439,35 b' class IPApi:'
419 m.init_ipython(self)
439 m.init_ipython(self)
420 self.extensions[mod] = m
440 self.extensions[mod] = m
421 return m
441 return m
442
443
444 class DebugTools:
445 """ Used for debugging mishaps in api usage
446
447 So far, tracing redefinitions is supported.
448 """
449
450 def __init__(self, ip):
451 self.ip = ip
452 self.debugmode = False
453 self.hotnames = set()
454
455
456 def hotname(self, name_to_catch):
457 self.hotnames.add(name_to_catch)
458
459 def debug_stack(self, msg = None):
460 if not self.debugmode:
461 return
422
462
463 import traceback
464 if msg is not None:
465 print '====== %s ========' % msg
466 traceback.print_stack()
467
468 def check_hotname(self,name):
469 if name in self.hotnames:
470 self.debug_stack( "HotName '%s' caught" % name)
423
471
424 def launch_new_instance(user_ns = None):
472 def launch_new_instance(user_ns = None):
425 """ Make and start a new ipython instance.
473 """ Make and start a new ipython instance.
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 2637 2007-08-17 16:18:05Z vivainio $
9 $Id: iplib.py 2646 2007-08-20 16:28:48Z vivainio $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -579,12 +579,13 b' class InteractiveShell(object,Magic):'
579 else:
579 else:
580 auto_alias = ()
580 auto_alias = ()
581 self.auto_alias = [s.split(None,1) for s in auto_alias]
581 self.auto_alias = [s.split(None,1) for s in auto_alias]
582 # Call the actual (public) initializer
583 self.init_auto_alias()
584
582
585 # Produce a public API instance
583 # Produce a public API instance
586 self.api = IPython.ipapi.IPApi(self)
584 self.api = IPython.ipapi.IPApi(self)
587
585
586 # Call the actual (public) initializer
587 self.init_auto_alias()
588
588 # track which builtins we add, so we can clean up later
589 # track which builtins we add, so we can clean up later
589 self.builtins_added = {}
590 self.builtins_added = {}
590 # This method will add the necessary builtins for operation, but
591 # This method will add the necessary builtins for operation, but
@@ -1017,7 +1018,8 b' class InteractiveShell(object,Magic):'
1017 These are ALL parameter-less aliases"""
1018 These are ALL parameter-less aliases"""
1018
1019
1019 for alias,cmd in self.auto_alias:
1020 for alias,cmd in self.auto_alias:
1020 self.alias_table[alias] = (0,cmd)
1021 self.getapi().defalias(alias,cmd)
1022
1021
1023
1022 def alias_table_validate(self,verbose=0):
1024 def alias_table_validate(self,verbose=0):
1023 """Update information about the alias table.
1025 """Update information about the alias table.
@@ -1268,7 +1270,9 b' want to merge them back into the new files.""" % locals()'
1268 def init_readline(self):
1270 def init_readline(self):
1269 """Command history completion/saving/reloading."""
1271 """Command history completion/saving/reloading."""
1270
1272
1273
1271 import IPython.rlineimpl as readline
1274 import IPython.rlineimpl as readline
1275
1272 if not readline.have_readline:
1276 if not readline.have_readline:
1273 self.has_readline = 0
1277 self.has_readline = 0
1274 self.readline = None
1278 self.readline = None
@@ -1618,7 +1622,7 b' want to merge them back into the new files.""" % locals()'
1618 # Mark activity in the builtins
1622 # Mark activity in the builtins
1619 __builtin__.__dict__['__IPYTHON__active'] += 1
1623 __builtin__.__dict__['__IPYTHON__active'] += 1
1620
1624
1621 if readline.have_readline:
1625 if self.has_readline:
1622 self.readline_startup_hook(self.pre_readline)
1626 self.readline_startup_hook(self.pre_readline)
1623 # exit_now is set by a call to %Exit or %Quit
1627 # exit_now is set by a call to %Exit or %Quit
1624
1628
General Comments 0
You need to be logged in to leave comments. Login now