Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Orion/Documentation/Developer Guide/Plugging into the editor"

(Examples)
(orion.edit.highlighter)
Line 57: Line 57:
  
 
= orion.edit.highlighter =
 
= orion.edit.highlighter =
 +
== Service methods ==
 +
None.
 +
 +
== Service attributes ==
 +
Implementations of <tt>orion.edit.highlighter</tt> may define the following attributes:
 +
 +
;type
 +
:<tt>String</tt> What kind of highlight provider is being registered. For now this should always be <tt>"grammar"</tt>, although future versions may support more.
 +
;fileTypes
 +
:<tt>Array</tt> An array of file extensions that this provider will be used for.
 +
;grammar
 +
:<tt>Object</tt> An object giving the grammar to be used to assign style classes. This object is expected to be a JavaScript equivalent of the format described [http://manual.macromates.com/en/language_grammars.html here].
 +
 +
== Examples ==
 +
<source lang="javascript">
 +
var provider = new eclipse.PluginProvider();
 +
provider.registerServiceProvider("orion.edit.highlighter",
 +
  {
 +
  }, {
 +
    type : "grammar",
 +
    fileTypes : ["html", "htm"],
 +
    grammar: {
 +
      patterns: [
 +
          {  begin: "<!--",
 +
            end: "-->",
 +
            captures: { "0": "punctuation.definition.comment.html" },
 +
            contentName: "comment.block.html"
 +
          }
 +
      ]
 +
    }
 +
  });
 +
provider.connect();
 +
</source>
 +
Provides a grammar to be used for <tt>.html</tt> and <tt>.htm</tt> files, which will assign the CSS class <tt>punctuation-definition-comment-html</tt> to the <tt>&lt;!--</tt> and <tt>--&gt;</tt> delimiters, and assign the CSS class <tt>comment-block-html</tt> to the text inside the delimiters. Consult the [http://manual.macromates.com/en/language_grammars.html manual] for a full description of the grammar format.
  
 
= orion.edit.outline =
 
= orion.edit.outline =
  
 
= orion.edit.validator =
 
= orion.edit.validator =

Revision as of 10:23, 21 June 2011

Overview of contributing services to the Orion editor

The built Orion editor defines a number of services for customizing its appearance and behavior. These services will typically be defined by a plug-in providing editing functionality for different programming languages or file extensions. This section will outline the services that are available for editor customization.

orion.edit.command

The orion.edit.command service is the simplest kind of editor extension. A command service simply provides a function that takes some text as input, performs some operation or transformation on the text, and returns a new text value. The command can also optionally receive and return selection information for changing the editor selection.

Service methods

Implementations of orion.edit.command must define the following function:

run(selectedText, text, selection)
selectedText is a string containing the text that is currently selected in the editor. The text argument provides the entire editor buffer. The selection argument is a selection object with start and end fields.

Service attributes

Implementations of orion.edit.command may define the following attributes:

img
The URL of an icon to associate with the command
name
The command text show to the user
key
An optional key binding for the command

Examples

The following simple example just converts the selected text to upper case. In this example the function return value is a simple string, so this is interpreted by the editor as replacement for the original editor selection. In the service properties, we see the command provides a key binding of Ctrl+U (or Cmd+U on Mac).

 var provider = new eclipse.PluginProvider();
 provider.registerServiceProvider("orion.edit.command", {
   run : function(text) {
     return text.toUpperCase();
   }
 }, {
   name : "UPPERCASE",
   img : "/images/gear.gif",
   key : [ "u", true ]
 });
 provider.connect();

Here is an example of a slightly more complex run function that takes the selection and wraps it in C-style block comments. In this example the function returns a complex object with both text and selection fields. These are interpreted by the editor as the new editor buffer contents, and the new editor selection.

 run : function(selectedText, text, selection) {
   return {text: text.substring(0,selection.start) + "/*" + 
     text.substring(selection.start,selection.end) + "*/" + 
     text.substring(selection.end),
     selection: {start:selection.start,end:selection.end+4}};
 }

orion.edit.contentAssist

orion.edit.highlighter

Service methods

None.

Service attributes

Implementations of orion.edit.highlighter may define the following attributes:

type
String What kind of highlight provider is being registered. For now this should always be "grammar", although future versions may support more.
fileTypes
Array An array of file extensions that this provider will be used for.
grammar
Object An object giving the grammar to be used to assign style classes. This object is expected to be a JavaScript equivalent of the format described here.

Examples

var provider = new eclipse.PluginProvider();
provider.registerServiceProvider("orion.edit.highlighter",
  {
  }, {
    type : "grammar",
    fileTypes : ["html", "htm"],
    grammar: {
      patterns: [
          {  begin: "<!--", 
             end: "-->",
             captures: { "0": "punctuation.definition.comment.html" },
             contentName: "comment.block.html"
          }
      ]
    }
  });
 provider.connect();

Provides a grammar to be used for .html and .htm files, which will assign the CSS class punctuation-definition-comment-html to the <!-- and --> delimiters, and assign the CSS class comment-block-html to the text inside the delimiters. Consult the manual for a full description of the grammar format.

orion.edit.outline

orion.edit.validator

Back to the top