Show More
@@ -2044,7 +2044,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2044 | self.magics_manager.register_function(func, |
|
2044 | self.magics_manager.register_function(func, | |
2045 | magic_kind=magic_kind, magic_name=magic_name) |
|
2045 | magic_kind=magic_kind, magic_name=magic_name) | |
2046 |
|
2046 | |||
2047 | def run_line_magic(self, magic_name, line): |
|
2047 | def run_line_magic(self, magic_name, line, back_compat=False): | |
2048 | """Execute the given line magic. |
|
2048 | """Execute the given line magic. | |
2049 |
|
2049 | |||
2050 | Parameters |
|
2050 | Parameters | |
@@ -2054,6 +2054,10 b' class InteractiveShell(SingletonConfigurable):' | |||||
2054 |
|
2054 | |||
2055 | line : str |
|
2055 | line : str | |
2056 | The rest of the input line as a single string. |
|
2056 | The rest of the input line as a single string. | |
|
2057 | ||||
|
2058 | back_compat : bool | |||
|
2059 | If run_line_magic() is called from magic() then it should be 'True'. | |||
|
2060 | This is added to ensure backward compatibility for use of 'get_ipython().magic()' | |||
2057 | """ |
|
2061 | """ | |
2058 | fn = self.find_line_magic(magic_name) |
|
2062 | fn = self.find_line_magic(magic_name) | |
2059 | if fn is None: |
|
2063 | if fn is None: | |
@@ -2066,7 +2070,13 b' class InteractiveShell(SingletonConfigurable):' | |||||
2066 | # Note: this is the distance in the stack to the user's frame. |
|
2070 | # Note: this is the distance in the stack to the user's frame. | |
2067 | # This will need to be updated if the internal calling logic gets |
|
2071 | # This will need to be updated if the internal calling logic gets | |
2068 | # refactored, or else we'll be expanding the wrong variables. |
|
2072 | # refactored, or else we'll be expanding the wrong variables. | |
2069 | stack_depth = 2 |
|
2073 | # Determine stack_depth depending on where run_line_magic() has been called | |
|
2074 | if back_compat: | |||
|
2075 | # run_line_magic() called directly using 'get_ipython().magic()' | |||
|
2076 | stack_depth = 2 | |||
|
2077 | else: | |||
|
2078 | # run_line_magic() called directly using 'get_ipython().run_line_magic()' | |||
|
2079 | stack_depth = 1 | |||
2070 | magic_arg_s = self.var_expand(line, stack_depth) |
|
2080 | magic_arg_s = self.var_expand(line, stack_depth) | |
2071 | # Put magic args in a list so we can call with f(*a) syntax |
|
2081 | # Put magic args in a list so we can call with f(*a) syntax | |
2072 | args = [magic_arg_s] |
|
2082 | args = [magic_arg_s] | |
@@ -2154,7 +2164,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2154 | # TODO: should we issue a loud deprecation warning here? |
|
2164 | # TODO: should we issue a loud deprecation warning here? | |
2155 | magic_name, _, magic_arg_s = arg_s.partition(' ') |
|
2165 | magic_name, _, magic_arg_s = arg_s.partition(' ') | |
2156 | magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) |
|
2166 | magic_name = magic_name.lstrip(prefilter.ESC_MAGIC) | |
2157 | return self.run_line_magic(magic_name, magic_arg_s) |
|
2167 | return self.run_line_magic(magic_name, magic_arg_s, back_compat=True) | |
2158 |
|
2168 | |||
2159 | #------------------------------------------------------------------------- |
|
2169 | #------------------------------------------------------------------------- | |
2160 | # Things related to macros |
|
2170 | # Things related to macros |
@@ -112,7 +112,7 b' syntax = \\' | |||||
112 | (u'%hist1?', "get_ipython().run_line_magic({u}'pinfo', {u}'%hist1')"), |
|
112 | (u'%hist1?', "get_ipython().run_line_magic({u}'pinfo', {u}'%hist1')"), | |
113 | (u'%hist2??', "get_ipython().run_line_magic({u}'pinfo2', {u}'%hist2')"), |
|
113 | (u'%hist2??', "get_ipython().run_line_magic({u}'pinfo2', {u}'%hist2')"), | |
114 | (u'%%hist3?', "get_ipython().run_line_magic({u}'pinfo', {u}'%%hist3')"), |
|
114 | (u'%%hist3?', "get_ipython().run_line_magic({u}'pinfo', {u}'%%hist3')"), | |
115 |
(u'%%hist4??', "get_ipython().run_line_magic({u}'pinfo2', {u}'%%hist |
|
115 | (u'%%hist4??', "get_ipython().run_line_magic({u}'pinfo2', {u}'%%hist4')"), | |
116 | (u'f*?', "get_ipython().run_line_magic({u}'psearch', {u}'f*')"), |
|
116 | (u'f*?', "get_ipython().run_line_magic({u}'psearch', {u}'f*')"), | |
117 | (u'ax.*aspe*?', "get_ipython().run_line_magic({u}'psearch', {u}'ax.*aspe*')"), |
|
117 | (u'ax.*aspe*?', "get_ipython().run_line_magic({u}'psearch', {u}'ax.*aspe*')"), | |
118 | (u'a = abc?', "get_ipython().set_next_input({u}'a = abc');" |
|
118 | (u'a = abc?', "get_ipython().set_next_input({u}'a = abc');" |
General Comments 0
You need to be logged in to leave comments.
Login now