2

I use Geany (v1.123.1), my favourite text editor for code editing, as it's nice and simple. One thing which it doesn't do right is the syntax highlighting of comments, in erb files (a type of ruby template for web pages).

In erb files, ruby code is injected with special "erb" tags like so:

<% x = "foo" %>

and if we want render out the results, we put an = after the start tag, like so

<%= @user.name %>

These are both handled properly by Geany. However, it fails to handle erb comments:

<%# this is just a comment - note # at start %>

which are treated like one of the previous ones, ie as if they contained actual code. This wouldn't be a disaster, except that they break the highlighting for the rest of the file, ie everything underneath. Eg see this screengrab:

enter image description here

What would be ideal is if it realised these were comments, and rendered everthing in the tag (perhaps including the tags themselves, I don't mind) in the same sort of grey/brown font used for other types of comments.

Is there a fix for this, or can I edit the config myself, to make it process the comments properly?

EDIT: I tried doing the following:

In /usr/share/geany/filetype_extensions.conf, i added this line:

Erb=*.erb;

Then I created this file: /home/max/.config/geany/filedefs/filetypes.erb with these contents:

[styling=HTML]

[settings]

lexer_filetype=HTML

Then I closed geany, reopened it, and reloaded the config for good measure. But it hasn't made any difference. As per the answer below I also tried naming the local config file as filetypes.Erb.conf, but that didn't work either. I think it should be called filetypes.erb, following the format of the other config files.

Max Williams
  • 1,067
  • 2
  • 16
  • 32
  • Doesn't look like that's possible, except for extending the HTML lexer (in C++ code in Scintilla) to add support for ERB. Right now it [defaults to ASP with VBScript](https://github.com/geany/geany/blob/1.36.0/scintilla/lexers/LexHTML.cxx#L1348), though it does have some specific support for Django and Mako (Python) and PHP... – filbranden Feb 27 '20 at 12:47
  • Hmm. That sounds way beyond me. I have been mucking about with the geany config, to no avail so far. – Max Williams Feb 27 '20 at 12:55

1 Answers1

0

Tell me if this works:

under /home/user/.config/geany/filedefs

create the file filetypes.Erb.conf.

Add to the file:

[styling=HTML]

[settings]

lexer_filetype=HTML

Restart geany.

Open your document and choose:

Document → Set Filetype → Erb file

schrodingerscatcuriosity
  • 12,087
  • 3
  • 29
  • 57
  • Thanks, did you definitely mean `filetypes.Erb.conf` rather than `filetypes.erb.conf`? – Max Williams Feb 28 '20 at 09:38
  • Also the other files in `/home/user/.config/geany/filedefs` are called `filetypes.css`, `filetypes.ruby` etc - should it be `filetypes.erb` rather than `filetypes.erb.conf`? – Max Williams Feb 28 '20 at 09:40
  • @MaxWilliams I was following [this](https://geany.org/manual/#id193). But I don't think that the name really matters, is the configuration wha's key, you can see that it's applied whatever name has the file. I will try other things and let you know :) – schrodingerscatcuriosity Feb 28 '20 at 12:56
  • Thanks - I forgot to say, i didn't see "Erb File" in the list of options, in the Document->Set Filetype menu. – Max Williams Feb 28 '20 at 16:03