adobe / brackets

An open source code editor for the web, written in JavaScript, HTML and CSS.
http://brackets.io
MIT License
33.25k stars 7.63k forks source link

Improved / Customizable Code Highlighting #6566

Closed ericbieller closed 9 years ago

ericbieller commented 10 years ago

As it stands currently, there isn't a simple way to highlight, for example, style.css.less.erb as CSS.

In prior versions you were able to edit a languages.json file but that seems to be removed (I think it's actually just minified now).

I'm running sprint 0.35.0-10897

Ideally there would be a dropdown to force association. Or possibly clicking the language definition at the bottom right would allow you to override.

redmunds commented 10 years ago

@ericbieller Yes, the languages.json file is concatenated into the main.js file, if you want to edit that file.

Or, you could create a Brackets extension with this code:

var LanguageManager = brackets.getModule("language/LanguageManager");
var language = LanguageManager.getLanguage("css");
language.addFileExtension("erb");

Let me know if you have any questions.

njx commented 10 years ago

I asked @ericbieller to file this because I think there's a general issue around how we deal with this "stacked extensions" pattern. I'm not familiar enough with it to know for sure, but my understanding is that it's a very common pattern in e.g. Rails, and it would be nice if we had a general way to handle it automatically as opposed to requiring people to add extensions for every case.

In this case, for example, it's not the case that every "erb" file would be CSS -- erb is just the general extension for Ruby templates. I think the desired behavior is that if you have file.foo.bar.erb, it should be treated as of type foo no matter what foo is. @ericbieller - is that right?

ericbieller commented 10 years ago

@njx My thoughts exactly. This is pretty standard in most editors and certianly warrants space in the main interface imho

Regarding your question, alternatively you could just associate the entire extension .css.less.erb with a user selected language (in my case less), rather than using the base extension as you mentioned. At least for me that feels like the expected behavior.

peterflynn commented 10 years ago

@njx @ericbieller It's perfectly valid to say language.addFileExtension(".css.less.erb");, so this is supported already. So I think we can close this issue.

njx commented 10 years ago

@peterflynn I wanted to raise this as a possible feature request so that we can handle this more generically for things like .erb instead of making people manually specify every possible extension combination.

peterflynn commented 10 years ago

@njx Ah, you mean some kind of smarts where .foo.erb is automatically handled as just .foo? But I'd venture to guess there are probably less than a dozen combinations that cover 99% of usage, so it may be simpler just to bake in support for those common ones and leave the existing extensibility APIs to handle the rest...

There's also the issue that none of these mode mappings actually grok the Ruby parts of the file (and as a result, don't even always correctly interpret the non-Ruby parts). That's a much more complex thing to tackle though...

ishan1608 commented 10 years ago

If I may just chime in. I agree with @njx to make this as a possible feature request. It would be nice to have a dropdown menu to select syntax highlighting for that file. This may or may not be session persistent. I am supporting this because we won't have to worry about every possible extension combination. Plus a user won't have to write extension everytime he/she needs some specific syntax highlighting for any kind of extension.

peterflynn commented 10 years ago

@ishanatmuz That's a different feature request, which is already captured in the backlog: https://trello.com/c/fH2JF9S6/338-user-selected-language-syntax-mode-per-file-extension

ishan1608 commented 10 years ago

@ericbieller As there isn't a solution for forcing syntax highlighting in the core brackets. I found out that there already exists an extension named brackets-languageswitcher https://github.com/p4bl1t0/brackets-languageswitcher which can be used to force syntax highlighting for the chosen language instead of the one based on file extension. Although the extension is a little buggy, but in all fairness, it is written in the extension's README that it is in alpha state. So you may look into it if it solves your purpose.

ericbieller commented 10 years ago

@ishanatmuz thanks for digging up that extension. Was becoming a huge headache for me so this helps a lot. Glad to see that this is in the backlog.

fr32c commented 10 years ago

Ok, sorry to have disturbed every one, today I learned something new : creating reaaaaaally simple extensions.

Hi. Still "new to coding", but this thread is exactly this morning's problem. I'm ok with @redmunds 's suggestion of writing an extension, since this time i want to highlight .mucow file as a simple xml.

It may seem trivial to many of you here but i have no clue where i put these lines

var LanguageManager = brackets.getModule("language/LanguageManager"); var language = LanguageManager.getLanguage("xml"); language.addFileExtension("mucow");

every extension i tried to open is 15k of code… used to be a simple "add 3 lines to file utils" hack… I checked https://github.com/adobe/brackets/wiki/Brackets-Extensions with no clue as to "how to build a 3 lines extension".

*\ edit: Creating a really simple extension

In your /Users/~/Library/Application Support/Brackets/extensions/user/ folder, create a main.js file. inside, type this :

/_jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 / /_global define, $, brackets, window /

define(function (require, exports, module) { var LanguageManager = brackets.getModule("language/LanguageManager"); var language = LanguageManager.getLanguage("xml"); language.addFileExtension("mucow"); });

peterflynn commented 10 years ago

@fr32c For reference, a good way to get started writing extensions is https://github.com/adobe/brackets/wiki/How-to-write-extensions

redmunds commented 9 years ago

@ericbieller There is now a dropdown menu in status bar for overriding the language for any file. This was introduced in Release 0.42. Additional "Set as Default" functionality was added in Release 0.44. Closing.