web-mode icon indicating copy to clipboard operation
web-mode copied to clipboard

What if only 2 mode in one file

Open bugcook opened this issue 12 years ago • 7 comments

Like when I use web-mode in rails, there're only 2 mode in .js.erb file, javascript and ruby, there's no <script>...</script> in these kind of files. so how to make web-mode render javascript code?

bugcook avatar Jan 15 '14 08:01 bugcook

I do not understand. Could you explain it an other Way please.

And could you post an example on gist please.

fxbois avatar Jan 15 '14 08:01 fxbois

<% if true %>
   // This is javascript code
   alert('aa');
<% end %>

Save this as test.js.erb.

In rails .js.erb file only contain javascript and ruby.

screen shot 2014-01-15 at 4 56 12 pm

You can see that ruby code highlight while javascript not.

bugcook avatar Jan 15 '14 08:01 bugcook

Ok, understood. I ll work on this

fxbois avatar Jan 15 '14 09:01 fxbois

could you try updating the var web-mode-content-types in web-mode.el please

(defvar web-mode-content-types
  '(("css"        . "\\.css\\'\\|\\.css\\.erb\\'")
    ("javascript" . "\\.js\\'\\|\\.js\\.erb\\'")
    ("json"       . "\\.\\(json\\|jsonld\\)\\'")
    ("html"       . "."))
  "content types")

fxbois avatar Jan 16 '14 07:01 fxbois

Works, but there're problems.

Before add the code: screen shot 2014-01-16 at 3 20 06 pm

After: screen shot 2014-01-16 at 3 19 06 pm

The ruby tag <% %> is not highlight and the color is a little different.

Do web-mode have a major mode? normally we use html-mode as major mode, when find the code between <script>...</script>, highlight it with js-mode and find code between <% .. %>, highlight it with ruby-mode, other's use html-mode.

Do web-mode behave like this?

bugcook avatar Jan 16 '14 07:01 bugcook

@eorza web-mode.el is autonomous ... no other mode is used. I'll look at your bug.

fxbois avatar Jan 16 '14 09:01 fxbois

the last github provides compatibility with *.js.erb and *.css.erb The indentation issue described above is not a bug. If the content-type is js ... the indentation is ok

fxbois avatar Feb 02 '14 00:02 fxbois