[R-SIG-Mac] suggestion for wrapping a selected text chunk into	auto-pairs in R.app's Console
    Hans-Jörg Bibiko 
    bibiko at eva.mpg.de
       
    Wed Apr  1 12:43:17 CEST 2009
    
    
  
Dear Simon, dear all,
here my code to wrap a selected text chunk into auto-pairs:
 > foo bar
select 'bar' and type e.g. " -> [ | := caret]
 > foo "bar"|
add in RTextView.m the method:
/*
  * If the textview has a selection, wrap it with the supplied prefix  
and suffix strings;
  * return whether or not any wrap was performed.
  */
- (BOOL) wrapSelectionWithPrefix:(unsigned int)prefix suffix:(NSString  
*)suffix
{
	
	// Only proceed if a selection is active
	if ([self selectedRange].length == 0)
		return NO;
	
	// Replace the current selection with the selected string wrapped in  
prefix and suffix
	[self insertText:
		[NSString stringWithFormat:@"%c%@%@",
		prefix,
		[[self string] substringWithRange:[self selectedRange]],
		suffix
	 	]
	 ];
	return YES;
}
and inside the keyDown: method just after:
case '\'':
	if (!complement) {
		complement = @"\'";
		acCheck = YES;
		if ([self parserContextForPosition:r.location] != pcExpression) break;
	}
add:
if ([self wrapSelectionWithPrefix:ck suffix:complement]) return;
Cheers,
--Hans
**********************************************************
Hans-Joerg Bibiko
Max Planck Institute for Evolutionary Anthropology
Department of Linguistics
Deutscher Platz 6     phone:   +49 (0) 341 3550 341
D-04103 Leipzig       fax:     +49 (0) 341 3550 333
Germany               e-mail:  bibiko at eva.mpg.de
    
    
More information about the R-SIG-Mac
mailing list