Skip to content
Idan edited this page Jan 20, 2016 · 1 revision

Developers

Table of contents

Sublime-Dooble package include files that defines the language HTML++ & Plugins.

For creating plugins in sublime text editor you can use this tutorial:

[http://code.tutsplus.com/tutorials/how-to-create-a-sublime-text-2-plugin--net-22685.](Create Plugin)

For API documentation use this link:

http://www.sublimetext.com/docs/3/.

OR

http://docs.sublimetext.info/en/latest/index.html.

For language definition you can use the above links.

The language definition of sublime text is based on TextMate editor:

https://manual.macromates.com/en/.

Files

TmLanguage –

This file is an XML that define the language syntax and rules of language, in our case you can find three files with the 'tmLanguage' extension in the package:

  • HTML.tmLanguage.
  • JavaScript.tmLanguage.
  • HTMLpp.tmLanguage.

The file is a dictionary of keys and arrays settings that begins with the types that the language include. For example, HTML++ Define three types: html\htm, hpp and config.

Then you can define rules like language comments, in HTML++ comment start with --[ and ends with ]--. You can also define conditions, tags, attribute-name and quotes and so on.

Related link for Syntax definition:

http://docs.sublimetext.info/en/latest/extens ibility/syntaxdefs.html.

HTMLpp.sublime-settings –

This file contain settings like: extensions, auto complete triggers and word separators.

In our file you can find the file extensions that HTML++ contains. It's defined with array 'extensions'.

For auto-complete triggers you need to define a character (defined with 'characters' word), so when you press on him you get a list of auto completes from specific scope. This scope defined with the 'selector' word.

The auto complete triggers is an array, so obviously you can define more than one object.

For word separators you need to include the characters that you want.

NOTE: some of the characters are auto complete triggers by default.

Comments.tmPreferences –

This file define the comments of our language.

The TM_COMMENT_START define the start of comment which is --[ and the TM_COMMENT_END define ]--.

To execute the comments, there is two shortcuts:

  • Ctrl+/ - mark the whole row in comment block.
  • Ctrl+shift+/ - open comment block in the cursor location.

###Sublime - completions – This file define the snippets and begins at the scope that the auto completes should opened.

After that you defined array of completions which contain trigger and content.

Each trigger can start with sign with word that will be a shortcut and ends with full name, in HTML++ the completions starts with '@' sign.

Each content defined with ${number: parameter}. When you have more than one parameter you can press TAB and the cursor focus will pass to the next parameter.

Example: here we have sublime completions to Javascript files.

The scopes where we want to see the auto-complete list include .js files.

Let's assume that we want to add auto-complete to function in Javascript that get input of two parameters and print the sum of them to the screen.

It should look like this screenshot:

completions

To execute the auto-complete open some Javascript file and write the word 'fun' and press ctrl+space.

Then you should get opened list of auto-completes:

![auto complete list](http://htmlpp.yifat.net/content/Images/Sublime/auto complete list.png)

In this window you can see that the list contain shortcuts which include the word 'fun' and from the right side there is description of the shortcut as we defined in the trigger section.

Press enter, the result should look like this:

![fun complete](http://htmlpp.yifat.net/content/Images/Sublime/fun complete.png)

As you can see the focus locate on the first parameter. If we press on Tab it will pass to the next parameter.

pass

Plugins

all files that contains plugins have the extension .py.

The plugins obviously written in Python language and based on the API of sublime.

To open new plugin go to Tools>>New plugin…

You should get new window:

![new plugin](http://htmlpp.yifat.net/content/Images/Sublime/new plugin.png)

To run the plugin press on ctrl+`, it will open the console of sublime:

![new plugin - run](http://htmlpp.yifat.net/content/Images/Sublime/new plugin - run.png)

Then insert the command view.run_command("example") end press enter, it will execute the plugin. The parenthesis get as parameter name of plugin.

Conventions –

  • Every plugin must import sublime and sublime_plugin.

  • Every plugin must include the 'command' word in addition of plugin name.

  • Every plugin need to inherit from one of sublime_plugin (EventListener, ApplicationCommand, WindowCommand, TextCommand).

Each plugin defined by class:

class

The run() method run the plugin. The is_visible() method return true\false (Example: if you want in some case that the plugin won't show up in the context menu, set the method to return false).

The is_enabled() method also return true\false (Example: if you want in some case that the plugin won't execute no matter what, set the method to return false).

In our package we have two files which contain plugins:

  • ModuleAutoComplete.py – responsible to open list of auto complete in HTML++ modules.
  • MenuExtentions.py – helper plugins to files and shortcuts.
  • Every file contain class DoobleIO (Utility).

In real world to run plugins you don't need to write this command view.run_command("example"). There is few ways to run plugin

  • Key map shortcuts.
  • Context menu.
  • Sidebar.

In our package we have:

  • Default(Windows).sublime-keymap.
  • Context.sublime-menu.
  • Side Bar.sublime-menu.

Each file is a JSON that defines the plugin with his name and arguments if there is. The name of plugin written in 'command' variable, if the name of your plugin in the class is 'MyPluginCommand', in the 'command' he need to be separated with underscore between words and the whole name must be in small letters. So the name look like: my_plugin.

To add keyboard shortcuts enter to Default (Windows).sublime-keymap, but before you give shortcut check if he available with sublime.log_input(Ture) command in the console ctrl+`.

To pass arguments you need to add args variable.

NOTE: when you add to the 'args' the words files\paths, you should know that they reserved words. Files – contain path of files and only files. Paths – contain both files and folder paths.

Examples to JSON:

shortcut