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

expose syntax theme colors to julia? #15

Closed
mkborregaard opened this issue Oct 8, 2016 · 11 comments
Closed

expose syntax theme colors to julia? #15

mkborregaard opened this issue Oct 8, 2016 · 11 comments

Comments

@mkborregaard
Copy link

mkborregaard commented Oct 8, 2016

Hi, I saw that @pkofod have been doing some themes for Plots.jl, among them a dark theme that would fit well with Atom I'm sure (PlotThemes.jl). I had the idea that it would be cool to have a Plots color scheme for use specifically in Atom that automatically selected colors based on Atom's current syntax color theme. Is that less file exposed by Atom in some way (or could it be)? Thanks!

@ChrisRackauckas
Copy link
Member

I don't see why this wouldn't be possible. One of the obstructions would be that I don't think this information could be gotten directly via Juno.jl, so it would require an Atom dependency. But Juno.jl could export a macro which will error when Atom isn't installed, but gives this information when it is (by simply making the expression which calls that right Atom.jl function). Then it would just require a Juno.jl dependency for PlotThemes.jl (which is a light dependency) and work on @pkofod's side to integrate it.

@pkofod
Copy link

pkofod commented Oct 8, 2016

For the record, I don't mind adding Juno.jl as a dependency, and think this is a cool idea.

@mkborregaard
Copy link
Author

Thanks @pkofod. I don't mind making the PR on PlotThemes if I can work out how to get this info from Atom. Would be cool (I think?) to also use the Atom font for axis labels etc.

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Oct 8, 2016

Another way to do this without dependencies is to use Main.Atom. ... to preface the function calls. This form of conditional dependencies is safe, but only will work with something like Juno since it requires that the user has imported Atom. Luckily, that is done in the Juno startup process, so Main.Atom will always be able to call the function if the user has Atom installed.

You can combine this by checking isdefined(Main,:Atom) which is true only if Atom has been imported into Main (i.e. only if the user is using Juno).

This route wouldn't require Juno.jl exposing anything through a macro (it works for different reasons, but gets to the same endpoint).

@MikeInnes
Copy link
Member

I think this should be doable – but I'm not yet sure how to do the appropriate reflection inside Atom. Will look into it.

@mkborregaard
Copy link
Author

mkborregaard commented Feb 26, 2017

Hi, I still think it would be cool to do this and wouldn't mind putting it together on the PlotThemes side (though I am not sure it is still viable to depend on Juno, as PlotThemes is now a Plots dependency). Maybe a conditional dependency approach is viable?

@pfitzseb
Copy link
Member

This is possible with Juno.syntaxcolors(selectors) (once #93 is merged):

julia> Juno.syntaxcolors()
Dict{String,Any} with 12 entries:
  "string"     => "#98bc37"
  "number"     => "#98bc37"
  "variable"   => "#adaaa4"
  "comment"    => "#918175"
  "macro"      => "#0aaeb3"
  "symbol"     => "#98bc37"
  "operator"   => "#adaaa4"
  "funcdef"    => "#e02c6d"
  "funccall"   => "#0aaeb3"
  "keyword"    => "#ff3128"
  "type"       => "#adaaa4"
  "background" => "#1c1b19"

I chose those selectors based on what OhMyREPL uses so we can generate a theme for that, but you can in principle query every syntax color you want (as long as you know the appropriate selector, obviously).

@MikeInnes
Copy link
Member

@mkborregaard if you want to use this, it should be pretty easy to do it with requires to avoid the dependency.

@pfitzseb
Copy link
Member

pfitzseb commented Jan 15, 2018

And if anyone wants to use this to create an OhMyREPL theme:

using OhMyREPL, Crayons
using OhMyREPL: Passes.SyntaxHighlighter

function generateOMRtheme()
  cs = SyntaxHighlighter.ColorScheme()

  colors = Juno.syntaxcolors()
  
  SyntaxHighlighter.symbol!(cs, Crayon(foreground = colors["symbol"]))
  SyntaxHighlighter.comment!(cs, Crayon(foreground = colors["comment"]))
  SyntaxHighlighter.string!(cs, Crayon(foreground = colors["string"]))
  SyntaxHighlighter.call!(cs, Crayon(foreground = colors["funccall"]))
  SyntaxHighlighter.op!(cs, Crayon(foreground = colors["operator"]))
  SyntaxHighlighter.keyword!(cs, Crayon(foreground = colors["keyword"]))
  SyntaxHighlighter.text!(cs, Crayon(foreground = colors["variable"]))
  SyntaxHighlighter.macro!(cs, Crayon(foreground = colors["macro"]))
  SyntaxHighlighter.function_def!(cs, Crayon(foreground = colors["funcdef"]))
  SyntaxHighlighter.argdef!(cs, Crayon(foreground = colors["type"]))
  SyntaxHighlighter.number!(cs, Crayon(foreground = colors["number"]))

  SyntaxHighlighter.add!("Atom", cs)
  
  OhMyREPL.colorscheme!("Atom")
  
  return cs
end

generateOMRtheme()

Can't test that right now though because I'm on windows :(

@MikeInnes
Copy link
Member

Should we be loading that by default when OhMyREPL is present?

@mkborregaard
Copy link
Author

Awesome!!! 💯 💖

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

No branches or pull requests

5 participants