Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Colour matched parenthesis/braces #1888

Closed
thomasp85 opened this issue Dec 28, 2017 · 43 comments · Fixed by #7027
Closed

Enhancement: Colour matched parenthesis/braces #1888

thomasp85 opened this issue Dec 28, 2017 · 43 comments · Fixed by #7027

Comments

@thomasp85
Copy link

In order to enhance the visual parsing of deeply nested parenthesis and braces it could be beneficial to colour code pairs in different colours (cycling through a palette of, say, 6 different colours).

This is akin to the colour highlighting done in formulas in Excel and is also something that has been implemented in the VIM plugin Rainbow Parentheses and in several Visual Studio Code plugin, e.g. Visafora

@thomasp85 thomasp85 changed the title Feature request: Colour matched parenthesis/braces Enhancement: Colour matched parenthesis/braces Dec 28, 2017
@rdrr1990
Copy link

As someone who uses RStudio to teach data science, this feature would be super useful. (As someone who sometimes codes for too long in one sitting, it would be good too.)

@CGTZA2
Copy link

CGTZA2 commented Dec 31, 2017

Indents are supposed to solve this, but they don't really. Agreed, would be most welcome

@verajosemanuel
Copy link

This would be a huge improvement when programming shiny apps. I always get crazy with so many brackets

@IndrajeetPatil
Copy link

Yes, please!! Life would be so much easier with this feature.

image

@james-ferguson
Copy link

Totally want this asap.

However meanwhile - RStudio does rock in other ways.

@MilesMcBain
Copy link

The difference this makes to my coding experience is profound. When I flip back to RStudio I have a genuine low grade stress associated with matching parens that I don't have in my regular editor.

I think some people find this less of a big deal than others. I've always struggled with counting repeated characters in a sequence. To the point where I see this as in the 'Accessibility' class of features.

Bring forth the rainbow!

@jonthegeek
Copy link

This would be soooooo helpful! I spend so much time putting in carriage returns and indentation when I copy/paste code, trying to sort out what matches what. This would help soooo much!

@oscarbaruffa
Copy link

This would be amazingly helpful. I really have to strain sometimes to see where I am in a nest. Great for teaching purposes too

@kevinushey kevinushey added this to the v1.3 milestone Jun 22, 2019
@njtierney
Copy link

After seeing @MilesMcBain 's video where he has matching colour parentheses...I need this in my life!

@brunocarlin
Copy link

We need this, super useful to the point I sometimes debug R in visual studio code

@joshua-theisen
Copy link

I agree with this suggestion

@samrickman
Copy link

This would be so useful in Shiny apps in particular. No matter how much I try to make complex parts of code their own functions, I quickly end up with three nested functions each with a pair of brackets and curly braces. Can get very confusing quickly, e.g.:

server <- function(input, output, session) {
    output$contents <- renderTable({
         if(input$match_to_data){
             
            # Define files to read in
            files_DT <- dir("~/data/",
                            pattern = "DT", 
                            full.names = TRUE)
            
            for(current_filename in files_DT){
                # Read in file, set names and key
                this_file <- read_rds(current_filename)
                
                setnames(this_file, "Location_ID", "lsoa11cd")
                setkey(this_file, lsoa11cd)
                
                # Reduce it to matches
                these_matches <- 
                    this_file[matches, nomatch=0]
                # Set order
                setcolorder(these_matches, c("Postcode")
                names(extra_matches)[i] <<- gsub("_DT.rds", "", basename(current_filename))
            }
        }
}

Have I ended the brackets for the for loop, if statement renderTable and server function? Pretty hard to tell.

Rstudio already knows which brackets match so presumably this wouldn't be that difficult to implement? Or is there a way to do it already with themes?

@jmcphers jmcphers removed this from the v1.3 milestone Dec 2, 2019
@jmcphers jmcphers added the ace label Dec 2, 2019
@AHoerner
Copy link

On behalf of dylsexic programmers everywhere, I give this an up vote. I'd give it 10 if I could. No, 100. Well, I don't know how many I would give it, but a lot.

@gtritchie
Copy link
Member

Adding accessibility label, this feature could be helpful with cognitive overload.

@sfd99
Copy link

sfd99 commented Dec 29, 2019

+1 to the nth power!.
Color matching parens now!.
(in both, Console Panel and Source Panel of Rstudio)...

@Seeingredagain
Copy link

I'm crushed that it still isn't solved. It's an absolute must have not only on mondays. If it's a tough issue (seen it only in payware so far, e. g. WinEdt) I'm not above begging, groveling, and bootlicking. Pleeease?

@greglum
Copy link

greglum commented Apr 12, 2020

Quite disappointing that nearly 2.5 years later this still hasn’t been resolved. We need this.

@kevinushey kevinushey added this to the v1.4 milestone Apr 12, 2020
@gtritchie gtritchie added this to To do in Accessibility (Open Source 1.4) via automation May 21, 2020
@gtritchie gtritchie moved this from To do to Review in Accessibility (Open Source 1.4) May 21, 2020
Accessibility (Open Source 1.4) automation moved this from Review to Done Jun 18, 2020
@pnacht
Copy link

pnacht commented Jun 19, 2020

@adamconroy Fantastic! Any idea when the next stable release (or whichever one will have this feature) will be?

@zemega
Copy link

zemega commented Jun 23, 2020

@adamconroy I just installed RStudio Desktop 1.3.959. Its released May 22 2020. Could not find any option about this feature.
Any idea when the feature will be released?

@Farbfetzen
Copy link

This is a 1.4 feature as indicated by the milestone in the sidebar.

@jmcphers
Copy link
Member

For anyone who wants to try this out, we have daily builds here:

https://dailies.rstudio.com/

Feedback would be very welcome on our community forum! https://community.rstudio.com/c/rstudio-ide

@ari-nz
Copy link

ari-nz commented Jul 2, 2020

Looks great!

image

@jzadra
Copy link

jzadra commented Aug 17, 2020

Another thing that would help with this issue is if the matching bracket highlight color was much, much more visible. It doesn't seem to be something that can be set in a theme. They should both become bold and the matching one should also get perhaps an underline and a background color like red or green or something other than a light grey:

image

@ronblum
Copy link
Contributor

ronblum commented Aug 17, 2020

@jzadra This looks like a separate (though related) issue. Could you file an enhancement request for it so that we can track it separately? Thanks!

@jzadra
Copy link

jzadra commented Aug 17, 2020

It appears that the rainbow parens are ignoring the rsTheme setting font-weight:bold; in ace_keyword.ace_operator

@jzadra
Copy link

jzadra commented Aug 31, 2020

It is fantastic that you are implementing rainbow brackets. I've installed daily build 1.4.714 and have the following feedback:

While I love the rainbow, it actually isn't very functional to have the brackets change in rainbow order because adjacent brackets are similarly colored (it's hard to tell red from orange and orange from yellow). It would be better if the appeared in order of colors on opposite sides of the color wheel as those are the most distinct from each other, ie red, green, orange, blue, yellow, purple, etc:

image

Also, while the colors are helpful when there are nested brackets, they detract from legibility when they are needed for non-nested brackets because the pink is quite pale. When there is no nesting, I'd suggest leaving them the default color of the theme might be more legible.

@adamconroy
Copy link
Contributor

We've changed the colors a few times based on feedback, in fact I was doing opposite sides of the color wheel in the initial implementation until I got a bevy of feedback wanting the more predictable ROYGIV ordering. I hope that we can eventually have in-app theme customization but until then I think the standard answer will have to be suggesting to the users to customize their theme to their liking. This can be done easily using the .ace_color_paren_0 through .ace_color_paren_6 CSS class selectors.

@pnacht
Copy link

pnacht commented Aug 31, 2020

Also, while the colors are helpful when there are nested brackets, they detract from legibility when they are needed for non-nested brackets because the pink is quite pale. When there is no nesting, I'd suggest leaving them the default color of the theme might be more legible.

I can't try the dev version on this machine, but from this comment I take it that the colors are changing sequentially: the first pair of parentheses are blue, the second green, then yellow, etc:

() #blue
() #green
() #yellow

This is definitely an improvement over no rainbow braces, but I second the preference for having the rainbow dependent on depth: the first parentheses are blue, the parentheses within the first are purple, but the next parentheses (not within the first or second) are blue again:

(     #blue
    (     #green
        ()    #yellow
    )     #green
    ()    #green
)     #blue
()    #blue

This is very useful since it allows for an at-a-glance identification of the depth one's working in, which is even useful to identify bugs caused by unmatched braces. "Hey, why is this depth-1 parenthesis green and not blue?... Oh, duh, I forgot to close the parentheses up here!"

@jzadra
Copy link

jzadra commented Aug 31, 2020

I've tried updating my .rstheme as follows, but am not seeing any changes. Have I done this correctly?


.ace_color_paren_0 {
  color: #000000 
  /* black */
}


.ace_color_paren_1 {
  color: #ffc800
  /* yellow */
}

.ace_color_paren_2 {
  color: #0008ff
  /* blue */
}

.ace_color_paren_3 {
  color: #FF0000
  /* red */
}

.ace_color_paren_4 {
  color: #00c21a
  /* green */
}


.ace_color_paren_5 {
  color: #ff00f7
  /* magenta */
}

.ace_color_paren_6 {
  color: #00f0ec
  /* cyan */
}

@jzadra
Copy link

jzadra commented Sep 1, 2020

Also, while the colors are helpful when there are nested brackets, they detract from legibility when they are needed for non-nested brackets because the pink is quite pale. When there is no nesting, I'd suggest leaving them the default color of the theme might be more legible.

I can't try the dev version on this machine, but from this comment I take it that the colors are changing sequentially: the first pair of parentheses are blue, the second green, then yellow, etc:

() #blue
() #green
() #yellow

This is definitely an improvement over no rainbow braces, but I second the preference for having the rainbow dependent on depth: the first parentheses are blue, the parentheses within the first are purple, but the next parentheses (not within the first or second) are blue again:

(     #blue
    (     #green
        ()    #yellow
    )     #green
    ()    #green
)     #blue
()    #blue

This is very useful since it allows for an at-a-glance identification of the depth one's working in, which is even useful to identify bugs caused by unmatched braces. "Hey, why is this depth-1 parenthesis green and not blue?... Oh, duh, I forgot to close the parentheses up here!"

The rainbow is dependent on depth. You should try it (?).

image

Your example (thought obviously with different colors but the same repeat colors:
image

@jzadra
Copy link

jzadra commented Sep 10, 2020

I'm still unable to get the .rsTheme to work, any suggestions?

@adamconroy
Copy link
Contributor

@jzadra can you right click -> inspect the element and drill down into the ace_content -> ace_line div to find the parens and look at your classes? Here's an example:
HBRua61

I'm not sure why it's not respecting your rsTheme settings.

@jzadra
Copy link

jzadra commented Sep 10, 2020

Ah, that was simple.

Your example and my code was ace_color_paren_x, but it should be ace_paren_color_x

All working now.

@adamconroy
Copy link
Contributor

Ah sorry about giving you the wrong info earlier, I was recalling from memory late at night and made a mistake. Enjoy your preferred colors!

@jzadra
Copy link

jzadra commented Oct 16, 2020

I'd like to suggest that the color level for parenthesis/braces/brackets be independent of each other.

IE currently the print parens will be the second color level because the brackets took the first level. I think it would be more useful to have each type start at the first level independent of being nested within other types.

if(TRUE) {
   print("hello")
}

@markbneal
Copy link

markbneal commented Nov 5, 2020

To help out those working this out for themselves, here is a the default editor theme (textmate) that has been modified with the code for custom colours for rainbow parentheses (at the end) to download - click [Download Zip].

Then you can dump it wherever your .rsTheme files are stored (on my computer C:\Program Files\RStudio\resources\themes), then open RStudio, go to Tools|Global options|Appearance and in Editor themes it should be available to select with the name textmate rainbow.

image

Go to town if you don't like the colours by googling html colour picker and substituting in to the theme file your preferred colour (#xxxxxx).

image

It might be possible to suck the theme directly from my gist with something like
rstudioapi::addTheme("http://your/theme/path/theme.rstheme", apply = TRUE)
as suggested here, though I have not tried it.

Edit:
I tested it - you can access my theme from the gist by running:
rstudioapi::addTheme("https://gist.githubusercontent.com/markbneal/947f34496c139b21598cb2362152db02/raw/00c2969e3d5b30b658ee62fd64edb9ab36f2e128/textmate_rainbow.rstheme", apply = TRUE)

@Fuechsl
Copy link

Fuechsl commented Feb 2, 2021

I've tried to modify a dark theme for using rainbow parenthesis. First it didn't work since the editor_dark tags overwrite my color settings in .ace_paren_color_x. I had to use !important to make it work. The problem seems that editor_dark has ace_paren_color_x settings and is applied AFTER the theme settings. Is this a bug which should be reported and fixed or do you just have to know (where from?!) that for dark themes you have to set the rainbow color tags !imporant?

Cheers, Martin

@s14230
Copy link

s14230 commented Jul 28, 2021

Thanks, I also needed the !important. Definitely a bug here

@ronblum
Copy link
Contributor

ronblum commented Jul 28, 2021

@Fuechsl Can you open a new issue for it? Then we can determine whether this is a bug we should fix, a possible enhancement, or expected behavior. Thanks!

@Fuechsl
Copy link

Fuechsl commented Jul 28, 2021 via email

@s14230
Copy link

s14230 commented Jul 28, 2021

I opened one there @Fuechsl , thanks for the solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.