The R Project SVN R-packages

Rev

Rev 6245 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6245 Rev 7927
Line 35... Line 35...
35
#import "NSTextView_RAdditions.h"
35
#import "NSTextView_RAdditions.h"
36
#import "RTextView.h"
36
#import "RTextView.h"
37
#import "RegexKitLite.h"
37
#import "RegexKitLite.h"
38
#import "RGUI.h"
38
#import "RGUI.h"
39
 
39
 
40
static inline int RPARSERCONTEXTFORPOSITION (RTextView* self, NSUInteger index) 
-
 
41
{
-
 
42
	typedef int (*RPARSERCONTEXTFORPOSITIONMethodPtr)(RTextView*, SEL, NSUInteger);
-
 
43
	static RPARSERCONTEXTFORPOSITIONMethodPtr _RPARSERCONTEXTFORPOSITION;
-
 
44
	if (!_RPARSERCONTEXTFORPOSITION) _RPARSERCONTEXTFORPOSITION = (RPARSERCONTEXTFORPOSITIONMethodPtr)[self methodForSelector:@selector(parserContextForPosition:)];
-
 
45
	int r = _RPARSERCONTEXTFORPOSITION(self, @selector(parserContextForPosition:), index);
-
 
46
	return r;
-
 
47
}
-
 
48
 
-
 
49
@implementation NSTextView (NSTextView_RAdditions)
40
@implementation NSTextView (NSTextView_RAdditions)
50
 
41
 
51
/**
42
/**
52
 * Returns the range of the current word.
43
 * Returns the range of the current word.
53
 *   finds: [| := caret]  |word  wo|rd  word|
44
 *   finds: [| := caret]  |word  wo|rd  word|
Line 146... Line 137...
146
	NSInteger breakCounter = 10000;
137
	NSInteger breakCounter = 10000;
147
 
138
 
148
	// look for the first non-balanced closing bracket
139
	// look for the first non-balanced closing bracket
149
	for(NSUInteger i=caretPosition; i<stringLength; i++) {
140
	for(NSUInteger i=caretPosition; i<stringLength; i++) {
150
		if(!breakCounter--) return;
141
		if(!breakCounter--) return;
151
		if(RPARSERCONTEXTFORPOSITION((RTextView*)self, i) != pcExpression) continue;
142
		if([(RTextView*)self parserContextForPosition: i] != pcExpression) continue;
152
		switch(CFStringGetCharacterAtIndex(parserStringRef, i)) {
143
		switch(CFStringGetCharacterAtIndex(parserStringRef, i)) {
153
			case ')': 
144
			case ')': 
154
				if(!pcnt) {
145
				if(!pcnt) {
155
					co='(';cc=')';
146
					co='(';cc=')';
156
					i=stringLength;
147
					i=stringLength;
Line 185... Line 176...
185
		bracketCounter++;
176
		bracketCounter++;
186
 
177
 
187
	breakCounter = 10000;
178
	breakCounter = 10000;
188
	for(NSInteger i=caretPosition; i>=0; i--) {
179
	for(NSInteger i=caretPosition; i>=0; i--) {
189
		if(!breakCounter--) return;
180
		if(!breakCounter--) return;
190
		if(RPARSERCONTEXTFORPOSITION((RTextView*)self, i) != pcExpression) continue;
181
		if([(RTextView*)self parserContextForPosition: i] != pcExpression) continue;
191
		c = CFStringGetCharacterAtIndex(parserStringRef, i);
182
		c = CFStringGetCharacterAtIndex(parserStringRef, i);
192
		if(c == co) {
183
		if(c == co) {
193
			if(!bracketCounter) {
184
			if(!bracketCounter) {
194
				start = i;
185
				start = i;
195
				break;
186
				break;
Line 204... Line 195...
204
 
195
 
205
	bracketCounter = 0;
196
	bracketCounter = 0;
206
	breakCounter = 10000;
197
	breakCounter = 10000;
207
	for(NSUInteger i=caretPosition; i<stringLength; i++) {
198
	for(NSUInteger i=caretPosition; i<stringLength; i++) {
208
		if(!breakCounter--) return;
199
		if(!breakCounter--) return;
209
		if(RPARSERCONTEXTFORPOSITION((RTextView*)self, i) != pcExpression) continue;
200
		if([(RTextView*)self parserContextForPosition: i] != pcExpression) continue;
210
		c = CFStringGetCharacterAtIndex(parserStringRef, i);
201
		c = CFStringGetCharacterAtIndex(parserStringRef, i);
211
		if(c == co) {
202
		if(c == co) {
212
			bracketCounter++;
203
			bracketCounter++;
213
		}
204
		}
214
		if(c == cc) {
205
		if(c == cc) {