@@ -37,7 +37,7 @@ function empty_or_escaped(x: string) {
37
37
* x['a = !ls'] = !ls
38
38
* is perfectly valid IPython, but regular expressions cannot help here.
39
39
*/
40
- export const LINE_MAGIC_PREFIX = '^(\\s*|\\s*\\S+\\s*=\\s*)'
40
+ export const LINE_MAGIC_PREFIX = '^(\\s*|\\s*\\S+\\s*=\\s*)' ;
41
41
42
42
export let overrides : IScopedCodeOverride [ ] = [
43
43
/**
@@ -55,6 +55,45 @@ export let overrides: IScopedCodeOverride[] = [
55
55
scope : 'line'
56
56
}
57
57
} ,
58
+ {
59
+ // note: assignments of pinfo/pinfo2 are not supported by IPython
60
+ pattern : '^(\\s*)' + '(\\?{1,2})(\\S+)(\n)?' ,
61
+ replacement : ( match , prefix , marks , name , line_break ) => {
62
+ const cmd = marks == '?' ? 'pinfo' : 'pinfo2' ;
63
+ line_break = line_break || '' ;
64
+ // trick: use single quotes to distinguish
65
+ return `${ prefix } get_ipython().run_line_magic(\'${ cmd } \', \'${ name } \')${ line_break } ` ;
66
+ } ,
67
+ scope : 'line' ,
68
+ reverse : {
69
+ pattern :
70
+ "get_ipython\\(\\).run_line_magic\\('(pinfo2?)', '(.*?)'\\)(\n)?" ,
71
+ replacement : ( match , cmd , name ) => {
72
+ const marks = cmd == 'pinfo' ? '?' : '??' ;
73
+ return `${ marks } ${ name } ` ;
74
+ } ,
75
+ scope : 'line'
76
+ }
77
+ } ,
78
+ {
79
+ pattern : '^(\\s*)' + '([^\\?\\s]+)(\\?{1,2})(\n)?' ,
80
+ replacement : ( match , prefix , name , marks , line_break ) => {
81
+ const cmd = marks == '?' ? 'pinfo' : 'pinfo2' ;
82
+ line_break = line_break || '' ;
83
+ // trick: use two spaces to distinguish pinfo using suffix (int?) from the one using prefix (?int)
84
+ return `${ prefix } get_ipython().run_line_magic(\'${ cmd } \', \'${ name } \')${ line_break } ` ;
85
+ } ,
86
+ scope : 'line' ,
87
+ reverse : {
88
+ pattern :
89
+ "get_ipython\\(\\).run_line_magic\\('(pinfo2?)', '(.*?)'\\)(\n)?" ,
90
+ replacement : ( match , cmd , name ) => {
91
+ const marks = cmd == 'pinfo' ? '?' : '??' ;
92
+ return `${ name } ${ marks } ` ;
93
+ } ,
94
+ scope : 'line'
95
+ }
96
+ } ,
58
97
{
59
98
pattern : LINE_MAGIC_PREFIX + '%(\\S+)(.*)(\n)?' ,
60
99
replacement : ( match , prefix , name , args , line_break ) => {
0 commit comments