Skip to content

Commit 94f9ba2

Browse files
author
Hans-Jörg Bibiko
committed
• improved Rd syntax highlighting
• fixed exception for "Show Help for current Word" in RConsole git-svn-id: https://svn.r-project.org/R-packages/trunk/Mac-GUI@5998 694ef91d-65df-0310-b7bb-92e67a308ead
1 parent 76ada98 commit 94f9ba2

File tree

7 files changed

+44
-15
lines changed

7 files changed

+44
-15
lines changed

RController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
- (IBAction) setDefaultColors:(id)sender;
270270

271271
+ (RController*) sharedController;
272+
- (NSView*) searchToolbarView;
272273

273274
- (void) flushROutput;
274275
- (void) flushTimerHook: (NSTimer*) source; // hook for flush timer

RController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3664,6 +3664,11 @@ - (void) helpSearchTypeChanged
36643664
[[helpSearch cell] setSearchMenuTemplate:m];
36653665
}
36663666

3667+
- (NSView*) searchToolbarView
3668+
{
3669+
return helpSearch;
3670+
}
3671+
36673672
@end
36683673

36693674

RDocumentWinCtrl.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ - (id) initWithWindowNibName:(NSString*) nib
203203
@"R",
204204
@"RdOpts",
205205
@"Rdversion",
206+
@"CRANpkg",
206207
@"S3method",
207208
@"S4method",
208209
@"Sexpr",

RScriptEditorTextView.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ - (void)doSyntaxHighlighting
652652
case RDPT_MACRO_GEN:
653653
tokenColor = shColorIdentifier;
654654
break;
655+
case RDPT_DIRECTIVE:
656+
tokenColor = shColorString;
657+
break;
658+
case RDPT_OTHER:
659+
tokenColor = shColorNormal;
660+
break;
655661
default:
656662
tokenColor = shColorNormal;
657663
}

RTextView.m

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ - (void) showHelpForCurrentFunction
562562

563563
NSString *helpString = [self functionNameForCurrentScope];
564564

565-
if(helpString) {
565+
if(helpString && [helpString length]) {
566566
int oldSearchType = [[HelpManager sharedController] searchType];
567567
[[HelpManager sharedController] setSearchType:kExactMatch];
568568
[[HelpManager sharedController] showHelpFor:helpString];
@@ -572,18 +572,22 @@ - (void) showHelpForCurrentFunction
572572

573573
id aSearchField = nil;
574574

575-
if(console)
576-
aSearchField = [[self delegate] valueForKeyPath:@"helpSearch"];
577-
else {
578-
NSWindow *keyWin = [NSApp keyWindow];
579-
if(![[keyWin toolbar] isVisible])
580-
[keyWin toggleToolbarShown:nil];
581-
aSearchField = [[self delegate] valueForKeyPath:@"searchToolbarField"];
582-
}
575+
NSWindow *keyWin = [NSApp keyWindow];
576+
577+
if(![[keyWin toolbar] isVisible])
578+
[keyWin toggleToolbarShown:nil];
579+
580+
if([[self delegate] respondsToSelector:@selector(searchToolbarView)])
581+
aSearchField = [[self delegate] searchToolbarView];
583582

584583
if(aSearchField == nil || ![aSearchField isKindOfClass:[NSSearchField class]]) return;
584+
585585
[aSearchField setStringValue:[[self string] substringWithRange:[self getRangeForCurrentWord]]];
586-
[[NSApp keyWindow] makeFirstResponder:aSearchField];
586+
587+
if([[aSearchField stringValue] length])
588+
[[HelpManager sharedController] showHelpFor:[aSearchField stringValue]];
589+
else
590+
[[NSApp keyWindow] makeFirstResponder:aSearchField];
587591

588592
}
589593

RdScriptEditorTokens.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@
3939
#define RDPT_SECTION 2
4040
#define RDPT_MACRO_ARG 3
4141
#define RDPT_MACRO_GEN 4
42+
#define RDPT_DIRECTIVE 5
4243
#define RDPT_OTHER 10

RdScriptEditorTokens.l

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,29 @@ s [ \t\n\r]+
5656
break [^a-zA-Z_0--]
5757

5858
section \\(s(ynopsis|ource|e(ction|ealso))|Rd(Opts|version)|n(ote|ame)|concept|title|Sexpr|d(ocType|e(scription|tails))|usage|e(ncoding|xamples)|value|keyword|format|a(uthor|lias|rguments)|references)
59-
macrowarg \\(s(trong|ubsection|pecial|amp|Quote)|href|newcommand|c(ite|o(de|mmand))|t(estonly|abular)|i(tem(ize)?|f(else)?)|S(3method|4method)|o(ut|ption)|d(ont(show|test|run)|e(scribe|qn)|fn|Quote)|url|p(kg|reformatted)|e(n(c|d|umerate|v)|qn|m(ph|ail))|v(erb|ar)|kbd|file|link(S4class)?|acronym|renewcommand|method|b(old|egin))
60-
macrowoarg \\(R|cr|tab|dots|l(dots|eft)|right|ge)
59+
macrowarg \\(s(trong|ubsection|pecial|amp|Quote)|href|newcommand|c(ite|o(de|mmand))|t(estonly|abular)|i(tem(ize)?|f(else)?)|S(3method|4method)|o(ut|ption)|d(ont(show|test|run)|e(scribe|qn)|fn|Quote)|CRANpkg|url|p(kg|reformatted)|e(n(c|d|umerate|v)|qn|m(ph|ail))|v(erb|ar)|kbd|file|link(S4class)?|acronym|renewcommand|method|b(old|egin))
60+
macrowoarg \\(R|cr|tab|item|dots|l(dots|eft)|right|ge)
6161
macrogen \\[a-zA-Z0-9]+
6262

63-
%%
64-
63+
%x verbatim
6564

65+
%%
6666

67+
\\(%) /* ignore escaped comment sign */
6768
%[^\n\r]*(\n|\r)? { return RDPT_COMMENT; } /* % Comments */
69+
^#ifn?def/[ \t] { return RDPT_DIRECTIVE; }
70+
^#endif/[ \t\n\r] { return RDPT_DIRECTIVE; }
71+
\\verb/\{ { BEGIN(verbatim); return RDPT_MACRO_ARG; }
72+
<verbatim>[^\}] /* ignore everything inside \verb{} */
73+
<verbatim>\\\} /* ignore everything inside \verb{} */
74+
<verbatim>\\(%) /* ignore everything inside \verb{} */
75+
<verbatim>%[^\n\r]*(\n|\r)? { return RDPT_COMMENT; } /* % sign is valid inside \verb{} */
76+
<verbatim>\} { BEGIN(INITIAL); } /* verbatim end */
6877
{section}/\{ { return RDPT_SECTION; } /* section macros */
6978
\\Sexpr/\[ { return RDPT_SECTION; } /* section macros */
7079
{macrowarg}/\{ { return RDPT_MACRO_ARG; } /* macros with arguments */
7180
\\link/\[ { return RDPT_MACRO_ARG; } /* macros with arguments */
72-
{macrowoarg}/(\\|{s}|%|{break}) { return RDPT_MACRO_ARG; } /* macros without arguments */
81+
{macrowoarg}/(\\|{s}|%|{break}) { return RDPT_MACRO_ARG; } /* macros without arguments */
7382
{macrogen} { return RDPT_MACRO_GEN; } /* unknown macros */
7483

7584
<<EOF>> {
@@ -162,6 +171,7 @@ usage
162171
value
163172
164173
macros with argument:
174+
CRANpkg
165175
S3method
166176
S4method
167177
acronym
@@ -216,6 +226,7 @@ R
216226
cr
217227
dots
218228
ge
229+
item
219230
ldots
220231
left
221232
right

0 commit comments

Comments
 (0)