| Line 37... |
Line 37... |
| 37 |
if (preventReentrance && insideR>0) {
|
37 |
if (preventReentrance && insideR>0) {
|
| 38 |
SLog(@"CodeCompletion.complete: returning nil completion to prevent R re-entrance [***]");
|
38 |
SLog(@"CodeCompletion.complete: returning nil completion to prevent R re-entrance [***]");
|
| 39 |
return nil;
|
39 |
return nil;
|
| 40 |
}
|
40 |
}
|
| 41 |
REngine *re = [REngine mainEngine];
|
41 |
REngine *re = [REngine mainEngine];
|
| - |
|
42 |
if (![re beginProtected]) {
|
| - |
|
43 |
SLog(@"CodeCompletion.complete: returning nil completion because protected REngine entry failed [***]");
|
| - |
|
44 |
return nil;
|
| - |
|
45 |
}
|
| 42 |
// first get the length of the search path so we can go environment by environment
|
46 |
// first get the length of the search path so we can go environment by environment
|
| 43 |
RSEXP *x = [re evaluateString:@"length(search())"];
|
47 |
RSEXP *x = [re evaluateString:@"length(search())"];
|
| 44 |
int pos=1, maxpos;
|
48 |
int pos=1, maxpos;
|
| 45 |
if (x==nil) return nil;
|
- |
|
| 46 |
if ((maxpos = [x integer])==0) return nil;
|
49 |
if (x==nil || ((maxpos = [x integer])==0)) { [re endProtected]; return nil; }
|
| 47 |
|
50 |
|
| 48 |
// ok, we got the search path length; search in each environment and if something matches, get it, otherwise go to the next one
|
51 |
// ok, we got the search path length; search in each environment and if something matches, get it, otherwise go to the next one
|
| 49 |
while (pos<=maxpos) {
|
52 |
while (pos<=maxpos) {
|
| 50 |
// use ls to get the names of the objects in the specific environment
|
53 |
// use ls to get the names of the objects in the specific environment
|
| 51 |
NSString *ls=[NSString stringWithFormat:@"ls(pos=%d, all.names=TRUE, pattern=\"^%@.*\")", pos, part];
|
54 |
NSString *ls=[NSString stringWithFormat:@"ls(pos=%d, all.names=TRUE, pattern=\"^%@.*\")", pos, part];
|
| 52 |
RSEXP *x = [re evaluateString:ls];
|
55 |
RSEXP *x = [re evaluateString:ls];
|
| 53 |
//NSLog(@"attepmting to find %@ via %@", part, ls);
|
56 |
//NSLog(@"attepmting to find %@ via %@", part, ls);
|
| 54 |
if (x==nil)
|
57 |
if (x==nil) {
|
| - |
|
58 |
[re endProtected];
|
| 55 |
return nil;
|
59 |
return nil;
|
| - |
|
60 |
}
|
| 56 |
NSArray *a = [x array];
|
61 |
NSArray *a = [x array];
|
| 57 |
if (a == nil) {
|
62 |
if (a == nil) {
|
| 58 |
[x release];
|
63 |
[x release];
|
| - |
|
64 |
[re endProtected];
|
| 59 |
return nil;
|
65 |
return nil;
|
| 60 |
}
|
66 |
}
|
| 61 |
|
67 |
|
| 62 |
{ // the following code works also if pattern is not specified; with pattern present we could make it even easier, but currently we use it just to narrow the search (e.g. "." could still be matched by something else ...)
|
68 |
{ // the following code works also if pattern is not specified; with pattern present we could make it even easier, but currently we use it just to narrow the search (e.g. "." could still be matched by something else ...)
|
| 63 |
int i=0, firstMatch=-1, matches=0;
|
69 |
int i=0, firstMatch=-1, matches=0;
|
| Line 77... |
Line 83... |
| 77 |
}
|
83 |
}
|
| 78 |
i++;
|
84 |
i++;
|
| 79 |
}
|
85 |
}
|
| 80 |
if (common!=nil) { // attempt to get class of the object - it will fail if that's just a partial object, but who cares..
|
86 |
if (common!=nil) { // attempt to get class of the object - it will fail if that's just a partial object, but who cares..
|
| 81 |
x = [re evaluateString:[NSString stringWithFormat:@"try(class(%@),silent=TRUE)",common]];
|
87 |
x = [re evaluateString:[NSString stringWithFormat:@"try(class(%@),silent=TRUE)",common]];
|
| - |
|
88 |
[re endProtected];
|
| 82 |
if (x!=nil && [x string]!=nil && [[x string] isEqualToString:@"function"])
|
89 |
if (x!=nil && [x string]!=nil && [[x string] isEqualToString:@"function"])
|
| 83 |
return [[common autorelease] stringByAppendingString:@"("];
|
90 |
return [[common autorelease] stringByAppendingString:@"("];
|
| 84 |
else
|
91 |
else
|
| 85 |
return [common autorelease];
|
92 |
return [common autorelease];
|
| 86 |
}
|
93 |
}
|
| 87 |
}
|
94 |
}
|
| 88 |
pos++;
|
95 |
pos++;
|
| 89 |
}
|
96 |
}
|
| - |
|
97 |
[re endProtected];
|
| 90 |
return nil;
|
98 |
return nil;
|
| 91 |
}
|
99 |
}
|
| 92 |
|
100 |
|
| 93 |
+ (NSArray*) completeAll: (NSString*) part cutPrefix: (int) prefix {
|
101 |
+ (NSArray*) completeAll: (NSString*) part cutPrefix: (int) prefix {
|
| 94 |
if (preventReentrance && insideR>0) {
|
102 |
if (preventReentrance && insideR>0) {
|
| 95 |
SLog(@"CodeCompletion.completeAll: returning nil completion to prevent R re-entrance [***]");
|
103 |
SLog(@"CodeCompletion.completeAll: returning nil completion to prevent R re-entrance [***]");
|
| 96 |
return nil;
|
104 |
return nil;
|
| 97 |
}
|
105 |
}
|
| - |
|
106 |
|
| 98 |
REngine *re = [REngine mainEngine];
|
107 |
REngine *re = [REngine mainEngine];
|
| - |
|
108 |
if (![re beginProtected]) {
|
| - |
|
109 |
SLog(@"CodeCompletion.completeAll: returning nil completion because protected REngine entry failed [***]");
|
| - |
|
110 |
return nil;
|
| - |
|
111 |
}
|
| - |
|
112 |
|
| 99 |
// first get the length of the search path so we can go environment by environment
|
113 |
// first get the length of the search path so we can go environment by environment
|
| 100 |
RSEXP *x = [re evaluateString:@"length(search())"];
|
114 |
RSEXP *x = [re evaluateString:@"length(search())"];
|
| 101 |
int pos=1, maxpos, matches=0;
|
115 |
int pos=1, maxpos, matches=0;
|
| 102 |
NSMutableArray *ca = nil;
|
116 |
NSMutableArray *ca = nil;
|
| 103 |
NSString *common=nil;
|
117 |
NSString *common=nil;
|
| 104 |
|
118 |
|
| 105 |
if (x==nil) return nil;
|
- |
|
| 106 |
if ((maxpos = [x integer])==0) return nil;
|
119 |
if (x==nil || ((maxpos = [x integer])==0)) { [re endProtected]; return nil; }
|
| 107 |
|
120 |
|
| 108 |
ca = [[NSMutableArray alloc] initWithCapacity: 8];
|
121 |
ca = [[NSMutableArray alloc] initWithCapacity: 8];
|
| 109 |
|
122 |
|
| 110 |
// ok, we got the search path length; search in each environment and if something matches, get it, otherwise go to the next one
|
123 |
// ok, we got the search path length; search in each environment and if something matches, get it, otherwise go to the next one
|
| 111 |
while (pos<=maxpos) {
|
124 |
while (pos<=maxpos) {
|
| 112 |
// use ls to get the names of the objects in the specific environment
|
125 |
// use ls to get the names of the objects in the specific environment
|
| 113 |
NSString *ls=[NSString stringWithFormat:@"ls(pos=%d, all.names=TRUE, pattern=\"^%@.*\")", pos, part];
|
126 |
NSString *ls=[NSString stringWithFormat:@"ls(pos=%d, all.names=TRUE, pattern=\"^%@.*\")", pos, part];
|
| 114 |
RSEXP *x = [re evaluateString:ls];
|
127 |
RSEXP *x = [re evaluateString:ls];
|
| 115 |
//NSLog(@"attepmting to find %@ via %@", part, ls);
|
128 |
//NSLog(@"attepmting to find %@ via %@", part, ls);
|
| 116 |
if (x==nil)
|
129 |
if (x==nil) {
|
| - |
|
130 |
[re endProtected];
|
| 117 |
return nil;
|
131 |
return nil;
|
| - |
|
132 |
}
|
| - |
|
133 |
|
| 118 |
NSArray *a = [x array];
|
134 |
NSArray *a = [x array];
|
| 119 |
|
135 |
|
| 120 |
if (a == nil) {
|
136 |
if (a == nil) {
|
| 121 |
[x release];
|
137 |
[x release];
|
| - |
|
138 |
[re endProtected];
|
| 122 |
return nil;
|
139 |
return nil;
|
| 123 |
}
|
140 |
}
|
| 124 |
|
141 |
|
| 125 |
{ // the following code works also if pattern is not specified; with pattern present we could make it even easier, but currently we use it just to narrow the search (e.g. "." could still be matched by something else ...)
|
142 |
{ // the following code works also if pattern is not specified; with pattern present we could make it even easier, but currently we use it just to narrow the search (e.g. "." could still be matched by something else ...)
|
| 126 |
int i=0, firstMatch=-1;
|
143 |
int i=0, firstMatch=-1;
|
| Line 149... |
Line 166... |
| 149 |
if (matches==1) {
|
166 |
if (matches==1) {
|
| 150 |
// attempt to get class of the object - it will fail if that's just a partial object, but who cares..
|
167 |
// attempt to get class of the object - it will fail if that's just a partial object, but who cares..
|
| 151 |
x = [re evaluateString:[NSString stringWithFormat:@"try(class(%@),silent=TRUE)",common]];
|
168 |
x = [re evaluateString:[NSString stringWithFormat:@"try(class(%@),silent=TRUE)",common]];
|
| 152 |
[ca release];
|
169 |
[ca release];
|
| 153 |
if (x!=nil && [x string]!=nil && [[x string] isEqualToString:@"function"]) {
|
170 |
if (x!=nil && [x string]!=nil && [[x string] isEqualToString:@"function"]) {
|
| - |
|
171 |
[re endProtected];
|
| 154 |
return [NSArray arrayWithObject: [[[common autorelease] stringByAppendingString:@"("] substringFromIndex:prefix]];
|
172 |
return [NSArray arrayWithObject: [[[common autorelease] stringByAppendingString:@"("] substringFromIndex:prefix]];
|
| 155 |
} else {
|
173 |
} else {
|
| - |
|
174 |
[re endProtected];
|
| 156 |
return [NSArray arrayWithObject: [[common autorelease] substringFromIndex:prefix]];
|
175 |
return [NSArray arrayWithObject: [[common autorelease] substringFromIndex:prefix]];
|
| 157 |
}
|
176 |
}
|
| 158 |
} else {
|
177 |
} else {
|
| 159 |
[common release];
|
178 |
[common release];
|
| - |
|
179 |
[re endProtected];
|
| 160 |
return ca;
|
180 |
return ca;
|
| 161 |
}
|
181 |
}
|
| 162 |
}
|
182 |
}
|
| - |
|
183 |
[re endProtected];
|
| 163 |
[ca release];
|
184 |
[ca release];
|
| 164 |
return nil;
|
185 |
return nil;
|
| 165 |
}
|
186 |
}
|
| 166 |
|
187 |
|
| 167 |
@end
|
188 |
@end
|