ACE

An embeddable code editor written in JavaScript

README

Ace (Ajax.org Cloud9 Editor)

Build Status  npm

_Note_: The new site at http://ace.c9.io contains all the info below along with an embedding guide and all the other resources you need to get started with Ace.

Ace is a standalone code editor written in JavaScript. Our goal is to create a browser based editor that matches and extends the features, usability and performance of existing native editors such as TextMate, Vim or Eclipse. It can be easily embedded in any web page or JavaScript application. Ace is developed as the primary editor for Cloud9 IDE and the successor of the Mozilla Skywriter (Bespin) Project.

Features


Syntax highlighting for over 120 languages (TextMate/Sublime/_.tmlanguage_ files can be imported)
Over 20 themes (TextMate/Sublime/_.tmtheme_ files can be imported)
Automatic indent and outdent
An optional command line
Handles huge documents (at last check, 4,000,000 lines is the upper limit)
Fully customizable key bindings including vim and Emacs modes
Search and replace with regular expressions
Highlight matching parentheses
Toggle between soft tabs and real tabs
Displays hidden characters
Drag and drop text using the mouse
Line wrapping
Code folding
Multiple cursors and selections
Live syntax checker (currently JavaScript/CoffeeScript/CSS/XQuery)
Cut, copy, and paste functionality

Take Ace for a spin!


Check out the Ace live demo or get a Cloud9 IDE account to experience Ace while editing one of your own GitHub projects.

If you want, you can use Ace as a textarea replacement thanks to the Ace Bookmarklet.

Embedding Ace


Ace can be easily embedded into any existing web page. You can either use one of pre-packaged versions of ace (just copy one ofsrc* subdirectories somewhere into your project), or use requireJS to load contents of lib/ace asace


The easiest version is simply:

  1. ```html
  2. <div id="editor">some text</div>
  3. <script src="src/ace.js" type="text/javascript" charset="utf-8"></script>
  4. <script>
  5.     var editor = ace.edit("editor");
  6. </script>
  7. ```

With "editor" being the id of the DOM element, which should be converted to an editor. Note that this element must be explicitly sized and positioned absolute or relative for Ace to work. e.g.

  1. ```css
  2. #editor {
  3.     position: absolute;
  4.     width: 500px;
  5.     height: 400px;
  6. }
  7. ```

To change the theme simply include the Theme's JavaScript file

  1. ```html
  2. <script src="src/theme-twilight.js" type="text/javascript" charset="utf-8"></script>
  3. ```

and configure the editor to use the theme:

  1. ```javascript
  2. editor.setTheme("ace/theme/twilight");
  3. ```

By default the editor only supports plain text mode; many other languages are available as separate modules. After including the mode's JavaScript file:

  1. ```html
  2. <script src="src/mode-javascript.js" type="text/javascript" charset="utf-8"></script>
  3. ```

The mode can then be used like this:

  1. ```javascript
  2. var JavaScriptMode = ace.require("ace/mode/javascript").Mode;
  3. editor.session.setMode(new JavaScriptMode());
  4. ```

to destroy editor use

  1. ```javascript
  2. editor.destroy();
  3. editor.container.remove();
  4. ```

Documentation


Additional usage information, including events to listen to and extending syntax highlighters, can be found on the main Ace website.

You can also find API documentation at http://ace.c9.io/#nav=api.

Also check out the sample code for the kitchen sink demo app.

If you still need help, feel free to drop a mail on the ace mailing list, or atirc.freenode.net#ace.

Running Ace


After the checkout Ace works out of the box. No build step is required. To try it out, simply start the bundled mini HTTP server using Node.JS

  1. ```bash
  2. node ./static.js
  3. ```

The editor can then be opened at http://localhost:8888/kitchen-sink.html.

To open the editor with a file:/// URL see the wiki.

Building Ace


You do not generally need to build ACE. The ace-builds repository endeavours to maintain the latest build, and you can just copy one of _src*_ subdirectories somewhere into your project.

However, all you need is Node.js and npm installed to package ACE. Just run npm install in the ace folder to install dependencies:

  1. ```bash
  2. npm install
  3. node ./Makefile.dryice.js
  4. ```

To package Ace, we use the dryice build tool developed by the Mozilla Skywriter team. Call node Makefile.dryice.js on the command-line to start the packing. This build script accepts the following options

  1. ```bash
  2. -m                 minify build files with uglify-js          
  3. -nc                namespace require and define calls with "ace"
  4. -bm                builds the bookmarklet version
  5. --target ./path    specify relative path for output folder (default value is "./build")
  6. ```

To generate all the files in the ace-builds repository, run node Makefile.dryice.js full --target ../ace-builds

Running the Unit Tests


The Ace unit tests can run on node.js. Assuming you have already done npm install, just call:

  1. ```bash
  2. npm run test
  3. ```

You can also run the tests in your browser by serving:

    http://localhost:8888/lib/ace/test/tests.html

This makes debugging failing tests way more easier.

Contributing


Ace is a community project and wouldn't be what it is without contributions! We actively encourage and support contributions. The Ace source code is released under the BSD License. This license is very simple, and is friendly to all kinds of projects, whether open source or not. Take charge of your editor and add your favorite language highlighting and keybindings!

Feel free to fork and improve/enhance Ace any way you want. If you feel that the editor or the Ace community will benefit from your changes, please open a pull request. For more information on our contributing guidelines, see CONTRIBUTING.md.