Skip to content

Commit

Permalink
Rainbow parentheses feature (#7027)
Browse files Browse the repository at this point in the history
* initial rainbow parentheses implementation

* regenerate themes with parentheses colors

* just use the standard nomenclature of rainbow parentheses to in user facing settings

* remove debug code and re-enable sync rainbow editor setting

* add NEWS entry

* pr feedback

* pr feedback, update user pref for new interface

* make token cursor paren matching consistent

* move paren_color style from rsthemes to themeStyles.css, update rainbow_parens UserPref

* remove ace_paren from rstheme tests
  • Loading branch information
adamconroy committed Jun 18, 2020
1 parent 67491e9 commit 1d578c6
Show file tree
Hide file tree
Showing 20 changed files with 704 additions and 518 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Expand Up @@ -27,6 +27,7 @@
* New option to configure soft wrapping for R Markdown files, and command to change the soft wrap mode of the editor on the fly (#2341)
* Add option `www-url-path-prefix` to force a path on auth cookies (Pro #1608)
* New Command Palette for searching and running build-in commands and add-ins (#5168)
* Colorize parentheses, braces, and brackets in assorted colors (#7027)
* Option to display Console error and message output in same color as regular output (#7029)
* Moved console options to a new pane in Global Options (#7047)

Expand Down
7 changes: 7 additions & 0 deletions src/cpp/session/include/session/prefs/UserPrefValues.hpp
Expand Up @@ -148,6 +148,7 @@ namespace prefs {
#define kHighlightConsoleErrors "highlight_console_errors"
#define kScrollPastEndOfDocument "scroll_past_end_of_document"
#define kHighlightRFunctionCalls "highlight_r_function_calls"
#define kRainbowParentheses "rainbow_parentheses"
#define kConsoleLineLengthLimit "console_line_length_limit"
#define kConsoleMaxLines "console_max_lines"
#define kAnsiConsoleMode "ansi_console_mode"
Expand Down Expand Up @@ -795,6 +796,12 @@ class UserPrefValues: public Preferences
bool highlightRFunctionCalls();
core::Error setHighlightRFunctionCalls(bool val);

/**
* Whether to highlight parentheses in a variety of colors.
*/
bool rainbowParentheses();
core::Error setRainbowParentheses(bool val);

/**
* The maximum number of characters to display in a single line in the R console.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/cpp/session/prefs/UserPrefValues.cpp
Expand Up @@ -959,6 +959,19 @@ core::Error UserPrefValues::setHighlightRFunctionCalls(bool val)
return writePref("highlight_r_function_calls", val);
}

/**
* Whether to highlight parentheses in a variety of colors.
*/
bool UserPrefValues::rainbowParentheses()
{
return readPref<bool>("rainbow_parentheses");
}

core::Error UserPrefValues::setRainbowParentheses(bool val)
{
return writePref("rainbow_parentheses", val);
}

/**
* The maximum number of characters to display in a single line in the R console.
*/
Expand Down Expand Up @@ -2685,6 +2698,7 @@ std::vector<std::string> UserPrefValues::allKeys()
kHighlightConsoleErrors,
kScrollPastEndOfDocument,
kHighlightRFunctionCalls,
kRainbowParentheses,
kConsoleLineLengthLimit,
kConsoleMaxLines,
kAnsiConsoleMode,
Expand Down
6 changes: 6 additions & 0 deletions src/cpp/session/resources/schema/user-prefs-schema.json
Expand Up @@ -527,6 +527,12 @@
"title": "Highlight R function calls",
"description": "Whether to highlight R function calls in the code editor."
},
"rainbow_parentheses": {
"type": "boolean",
"default": false,
"title": "Rainbow parentheses",
"description": "Whether to highlight parentheses in a variety of colors."
},
"console_line_length_limit": {
"type": "integer",
"default": 1000,
Expand Down
8 changes: 7 additions & 1 deletion src/gwt/acesupport/acemode/c_cpp.js
Expand Up @@ -157,7 +157,13 @@ oop.inherits(Mode, TextMode);

this.inRLanguageMode = function(state)
{
return state.match(/^r-/);
if (!state)
return null;

if (typeof(state) === "object" && state.hasOwnProperty("length") && state.length > 0) {
state = state[0];
}
return state.match(/^r-/);
};

this.getNextLineIndent = function(state, line, tab, row, dontSubset)
Expand Down
31 changes: 11 additions & 20 deletions src/gwt/acesupport/acemode/c_cpp_highlight_rules.js
Expand Up @@ -34,6 +34,7 @@ var DocCommentHighlightRules = require("mode/doc_comment_highlight_rules").DocCo
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var TexHighlightRules = require("mode/tex_highlight_rules").TexHighlightRules;
var RHighlightRules = require("mode/r_highlight_rules").RHighlightRules;
var RainbowParenHighlightRules = require("mode/rainbow_paren_highlight_rules").RainbowParenHighlightRules;

var c_cppHighlightRules = function() {

Expand Down Expand Up @@ -181,24 +182,16 @@ var c_cppHighlightRules = function() {
token : "keyword.punctuation.operator",
merge : false,
regex : "\\?|\\:|\\,|\\;|\\.|\\\\"
}, {
// Obviously these are neither keywords nor operators, but
// labelling them as such was the easiest way to get them
// to be colored distinctly from regular text
token : "paren.keyword.operator",
merge : false,
regex : "[[({<]"
}, {
// Obviously these are neither keywords nor operators, but
// labelling them as such was the easiest way to get them
// to be colored distinctly from regular text
token : "paren.keyword.operator",
merge : false,
regex : "[\\])}>]"
}, {
token : "text",
regex : "\\s+"
}
},
RainbowParenHighlightRules.getParenRule(),
{
token : "paren.keyword.operator",
merge : false,
regex : "[<>]"
}, {
token : "text",
regex : "\\s+"
}
],
"comment" : [
{
Expand Down Expand Up @@ -292,8 +285,6 @@ var c_cppHighlightRules = function() {
regex: "\\*\\/",
next: "start"
});


};

oop.inherits(c_cppHighlightRules, TextHighlightRules);
Expand Down
13 changes: 4 additions & 9 deletions src/gwt/acesupport/acemode/python_highlight_rules.js
Expand Up @@ -57,6 +57,7 @@ define("mode/python_highlight_rules", ["require", "exports", "module"], function
var oop = require("ace/lib/oop");
var Utils = require("mode/utils");
var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
var RainbowParenHighlightRules = require("mode/rainbow_paren_highlight_rules").RainbowParenHighlightRules;

var PythonHighlightRules = function() {

Expand Down Expand Up @@ -146,15 +147,9 @@ var PythonHighlightRules = function() {
token : "keyword.operator",
regex : "//=|\\*\\*=|>>=|<<=|//|\\*\\*|==|!=|>=|<=|>>|<<|\\+=|-=|\\*=|/=|&=|%=|\\|=|\\^=|\\+|-|\\*|/|%|>|<|\\^|~|\\||&|=|:|\\.|;|,",
merge : false
}, {
token : "paren.lparen.keyword.operator",
regex : "[\\[\\(\\{]",
merge : false
}, {
token : "paren.rparen.keyword.operator",
regex : "[\\]\\)\\}]",
merge : false
}, {
},
RainbowParenHighlightRules.getParenRule(),
{
token : "text",
regex : "\\s+"
} ],
Expand Down

0 comments on commit 1d578c6

Please sign in to comment.