Suggestion of a color theme (syntax highlighting) for Elixir?

Hello Everybody,

Does anyone know a good color scheme for syntax highlighting adapted to Elixir.
In my case I’m using VSCode.
I tried some Color Themes dedicated to Elixir found on the extension market but even so I found them not suited for Elixir.
For example when using an inline def, none of them highlights correctly the do: like the def.
I know that it’s in fact a keyword (even in the implementation) but semantically I wanted the do: to be the same as the def.

Anyway, if anyone have a good suggestion I’ll be happy to try it…
Thank you…

Edit: I’ll also try to look at how syntax highlighting works (probably a lot of regex) and I’ll try to tinker with it myself…

Pretty well all the recent knowledge of VS Code themes is collected into this thread:

2 Likes

Thank you…
I’ll take a look there…

The issue with the specific case you describe (do: treated as atom in inline def), is unfortunately not something theme designers can control.

The relevant code is here. The summary is that the syntax currently used by the ElixirLS Fork extension has a long lineage (Atom -> vscode-elixir -> ElixirLS), and no one has yet tackled the specific tweak for do:.

I don’t actually know if do: is a legal keyword/atom name. Presumably not. If it isn’t, then simply adjusting the regexes for keyword.control.elixir (allow do to be followed by :) and/or constant.other.symbol.elixir (disallow do: when it appears alone), would fix the problem.

In the meantime, please check out my Yarra Valley theme for Elixir :slight_smile:

1 Like

:do is definitely a valid atom, and indeed the do: in def something, do: ... is just a normal atom key in a keyword list. So having a special rule for :do atoms would probably not work well.

By the way, really nice theme, I would love to see a port to Vim to be able to use it in my everyday editor :slight_smile:

3 Likes

This would be wrong in my opinion. To be honest, in my opinion, even do/end pairs should be colored as atoms, as they are just syntactic sugar for do: ….

I’d even say, def and friends shouldn’t get special treatment/colors as well, it is just a function call and should not have any different color than foo in foo(:bar).

1 Like

They just atoms, that’s true, but they’re also special cased by being reserved words in elixir:
https://hexdocs.pm/elixir/syntax-reference.html#reserved-words

  • true , false , nil - used as atoms
  • when , and , or , not , in - used as operators
  • fn - used for anonymous function definitions
  • do , end , catch , rescue , after , else - used in do/end blocks
3 Likes

Well…
Indeed we can treat all the keywords as the compiler see them…
Or we can treat them as developers and consider the semantic meaning of them…

Which is actually performed by Elixir itself by providing the syntactic sugar of the keywords listed by @LostKobrakai

I mean if Elixir itself apply some special formatting, indentation, etc. (and even macros under the hoods) to those syntactic sugars, coloring them make total sense in the point we are.

I though of a regex something like that to distinguish do: in inline defs:

/(?!^\s*def.+,\s)(do:)/gm

And if I look at the source code of the vscode-elixir-ls extension provided by @Dusty above the following might work:

{
  "match": "/(?!^\s*def.+,\s)(do:)/gm",
  "name": "keyword.control.elixir"
},

I’ll try to figure out where this file is located and try if this works…

EDIT:
Ok…
I managed to find that the elixir.json file mentioned by @Dusty above is located (on Linux) in $HOME/.vscode/extensions

So I tried the following

{
"match": "(?!^\\s*def.+,\\s)(do:)",
"name": "keyword.control.elixir"
},

And it worked!

So I removed regex delimiters and escaped the \.
Just be sure to put it before the symbols rule (starting on line 95 on the example linked above)

But I didn’t make any kind of test or whatsoever… So it might be necessary to perform some tests be sure there isn’t any edge cases…

Thanks for the details… As I explained above I’ll try to tinker and find out if I can manage to do something…

Also thank you for your theme, I’ll try it right now…

EDIT: I edited the message above and I managed to make it work for the moment.