Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining new language based on C++

I would like to add a new language (called 'kiwi') into the Brackets code editor which is based on C++. It uses the exact same rules but has additional keywords.

I've already done the part of adding the additional keywords with separate syntax highlighting directly on the clike.js file but i don't really like directly modifying the def for C++

Can someone explain to me how I can achieve this? I don't really understand the difference between using def() and CodeMirror.defineMIME(). If this new language will take cpp/hpp input files, how will the editor switch from C++ -> kiwi?

Thanks in advance

like image 764
user3595781 Avatar asked May 10 '26 23:05

user3595781


1 Answers

Patching your local copy of the code, as you've done, might be perfectly fine for your needs. (And if you run from a Git copy of the source, it's easy to pull down updates without losing your local diffs).

If you want to do it a "cleaner" way, you can write a Brackets extension to define the new language - this way the change is easily shareable with others, and updating Brackets is even easier.

The way you'd do this roughly follows the Defining a new language docs:

  • Write an extension to package up your code that will define the new language (below)
  • The CM mode "clike" is already loaded, so you don't need to worry about that
  • Call CodeMirror.defineMIME() to set up a clike configuration with the right list of keywords - using a new mimetype name of your choosing. (Looking at the def() code in clike.js, I don't think the extra stuff it does is especially relevant for Brackets).
  • Call LanguageManager.defineLanguage() to tell Brackets about your new language mode (and what file extensions map to it, etc.). You should be able to mostly copy how the C++ mode is defined here - except with your new MIME name instead.
like image 50
peterflynn Avatar answered May 18 '26 16:05

peterflynn