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:@"%...@%@",
                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:  bib...@eva.mpg.de

_______________________________________________
R-SIG-Mac mailing list
R-SIG-Mac@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Reply via email to