Skip to content

Commit

Permalink
• improved Rd syntax highlighting
Browse files Browse the repository at this point in the history
• 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
  • Loading branch information
Hans-Jörg Bibiko committed Jan 12, 2012
1 parent 76ada98 commit 94f9ba2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
1 change: 1 addition & 0 deletions RController.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
- (IBAction) setDefaultColors:(id)sender;

+ (RController*) sharedController;
- (NSView*) searchToolbarView;

- (void) flushROutput;
- (void) flushTimerHook: (NSTimer*) source; // hook for flush timer
Expand Down
5 changes: 5 additions & 0 deletions RController.m
Original file line number Diff line number Diff line change
Expand Up @@ -3664,6 +3664,11 @@ - (void) helpSearchTypeChanged
[[helpSearch cell] setSearchMenuTemplate:m];
}

- (NSView*) searchToolbarView
{
return helpSearch;
}

@end


1 change: 1 addition & 0 deletions RDocumentWinCtrl.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ - (id) initWithWindowNibName:(NSString*) nib
@"R",
@"RdOpts",
@"Rdversion",
@"CRANpkg",
@"S3method",
@"S4method",
@"Sexpr",
Expand Down
6 changes: 6 additions & 0 deletions RScriptEditorTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ - (void)doSyntaxHighlighting
case RDPT_MACRO_GEN:
tokenColor = shColorIdentifier;
break;
case RDPT_DIRECTIVE:
tokenColor = shColorString;
break;
case RDPT_OTHER:
tokenColor = shColorNormal;
break;
default:
tokenColor = shColorNormal;
}
Expand Down
24 changes: 14 additions & 10 deletions RTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ - (void) showHelpForCurrentFunction

NSString *helpString = [self functionNameForCurrentScope];

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

id aSearchField = nil;

if(console)
aSearchField = [[self delegate] valueForKeyPath:@"helpSearch"];
else {
NSWindow *keyWin = [NSApp keyWindow];
if(![[keyWin toolbar] isVisible])
[keyWin toggleToolbarShown:nil];
aSearchField = [[self delegate] valueForKeyPath:@"searchToolbarField"];
}
NSWindow *keyWin = [NSApp keyWindow];

if(![[keyWin toolbar] isVisible])
[keyWin toggleToolbarShown:nil];

if([[self delegate] respondsToSelector:@selector(searchToolbarView)])
aSearchField = [[self delegate] searchToolbarView];

if(aSearchField == nil || ![aSearchField isKindOfClass:[NSSearchField class]]) return;

[aSearchField setStringValue:[[self string] substringWithRange:[self getRangeForCurrentWord]]];
[[NSApp keyWindow] makeFirstResponder:aSearchField];

if([[aSearchField stringValue] length])
[[HelpManager sharedController] showHelpFor:[aSearchField stringValue]];
else
[[NSApp keyWindow] makeFirstResponder:aSearchField];

}

Expand Down
1 change: 1 addition & 0 deletions RdScriptEditorTokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
#define RDPT_SECTION 2
#define RDPT_MACRO_ARG 3
#define RDPT_MACRO_GEN 4
#define RDPT_DIRECTIVE 5
#define RDPT_OTHER 10
21 changes: 16 additions & 5 deletions RdScriptEditorTokens.l
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,29 @@ s [ \t\n\r]+
break [^a-zA-Z_0-9À-゚]

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)
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))
macrowoarg \\(R|cr|tab|dots|l(dots|eft)|right|ge)
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))
macrowoarg \\(R|cr|tab|item|dots|l(dots|eft)|right|ge)
macrogen \\[a-zA-Z0-9]+

%%

%x verbatim

%%

\\(%) /* ignore escaped comment sign */
%[^\n\r]*(\n|\r)? { return RDPT_COMMENT; } /* % Comments */
^#ifn?def/[ \t] { return RDPT_DIRECTIVE; }
^#endif/[ \t\n\r] { return RDPT_DIRECTIVE; }
\\verb/\{ { BEGIN(verbatim); return RDPT_MACRO_ARG; }
<verbatim>[^\}] /* ignore everything inside \verb{} */
<verbatim>\\\} /* ignore everything inside \verb{} */
<verbatim>\\(%) /* ignore everything inside \verb{} */
<verbatim>%[^\n\r]*(\n|\r)? { return RDPT_COMMENT; } /* % sign is valid inside \verb{} */
<verbatim>\} { BEGIN(INITIAL); } /* verbatim end */
{section}/\{ { return RDPT_SECTION; } /* section macros */
\\Sexpr/\[ { return RDPT_SECTION; } /* section macros */
{macrowarg}/\{ { return RDPT_MACRO_ARG; } /* macros with arguments */
\\link/\[ { return RDPT_MACRO_ARG; } /* macros with arguments */
{macrowoarg}/(\\|{s}|%|{break}) { return RDPT_MACRO_ARG; } /* macros without arguments */
{macrowoarg}/(\\|{s}|%|{break}) { return RDPT_MACRO_ARG; } /* macros without arguments */
{macrogen} { return RDPT_MACRO_GEN; } /* unknown macros */

<<EOF>> {
Expand Down Expand Up @@ -162,6 +171,7 @@ usage
value

macros with argument:
CRANpkg
S3method
S4method
acronym
Expand Down Expand Up @@ -216,6 +226,7 @@ R
cr
dots
ge
item
ldots
left
right
Expand Down

0 comments on commit 94f9ba2

Please sign in to comment.