# { } CodeMirror

    /* In-browser code editing
       made bearable */

CodeMirror is a JavaScript component that provides a code editor in the browser. When a mode is available for the language you are coding in, it will color your code, and optionally help with indentation.

A rich programming API and a CSS theming system are available for customizing CodeMirror to fit your application, and extending it with new functionality.

## Supported modes:

- C, C++, C#, Java, and similar
- Clojure
- CoffeeScript
- CSS
- diff
- ECL
- Go
- Groovy
- Haskell
- HTML embedded scripts
- HTML mixed-mode
- JavaScript
- Jinja2
- LESS
- Lua
- Markdown (Github-flavour)
- MySQL
- NTriples
- Pascal
- Perl
- PHP
- Pig Latin
- PL/SQL
- Properties files
- Python
- R
- RPM spec and changelog
- reStructuredText
- Ruby
- Rust
- Scheme
- Shell
- Smalltalk
- Smarty
- SPARQL
- sTeX, LaTeX
- Tiddlywiki
- Tiki wiki
- VBScript
- Velocity
- Verilog
- XML/HTML (alternative XML)
- XQuery
- YAML

## Usage demos:

- Autocompletion
- Mode overlays
- Search/replace
- Code folding
- HTML editor with preview
- Auto-resizing editor
- Setting breakpoints
- Highlighting the current line
- Highlighting selection matches
- Theming
- Stand-alone highlighting
- Full-screen editing
- Mode auto-changing
- Visible tabs
- Autoformatting of code
- Emacs keybindings
- Vim keybindings
- Automatic xml tag closing
- Lazy mode loading

## Real-world uses:

- jsbin.com (JS playground)
- Sage demo (math system)
- sourceLair (online IDE)
- Eloquent JavaScript (book)
- Mergely (interactive diffing)
- Paper.js (graphics scripting)
- WeScheme (learning tool)
- WebGL playground
- ql.io (http API query helper)
- Elm language examples
- BlueGriffon (HTML editor)
- JSHint (JS linter)
- kl1p (paste service)
- SQLFiddle (SQL playground)
- Go language tour

## Getting the code

All of CodeMirror is released under a MIT-style license. To get it, you can download the latest release or the current development snapshot as zip files. To create a custom minified script file, you can use the compression API.

We use git for version control. The main repository can be fetched in this way:

    git clone http://marijnhaverbeke.nl/git/codemirror2

CodeMirror can also be found on GitHub at marijnh/CodeMirror2. If you plan to hack on the code and contribute patches, the best way to do it is to create a GitHub fork, and send pull requests.

## Documentation

The manual is your first stop for learning how to use this library. It starts with a quick explanation of how to use the editor, and then describes the API in detail.

For those who want to learn more about the code, there is an overview of the internals available. The source code itself is, for the most part, also well commented.

## Support and bug reports

There is a Google group (a sort of mailing list/newsgroup thing) for discussion and news related to CodeMirror. When reporting a bug, read this first. If you have a github account, simply open an issue there. Otherwise, post something to the group, or e-mail me directly: Marijn Haverbeke.

## Supported browsers

The following browsers are able to run CodeMirror:

- Firefox 2 or higher
- Chrome, any version
- Safari 3 or higher
- Internet Explorer 7 or higher in standards (non-quirks) mode
- Opera 9 or higher (with some key-handling problems on OS X)

I am not actively testing against every new browser release, and vendors have a habit of introducing bugs all the time, so I am relying on the community to tell me when something breaks. See here for information on how to contact me.

## Commercial support

CodeMirror is developed and maintained by me, Marijn Haverbeke, in my own time. If your company is getting value out of CodeMirror, please consider purchasing a support contract.

- You'll be funding further work on CodeMirror.
- You ensure that you get a quick response when you have a problem, even when I am otherwise busy.

CodeMirror support contracts exist in two forms—basic at €100 per month, and premium at €500 per month. Contact me for further information.

Download the latest release

## Support CodeMirror

- Donate (Paypal or bank)
- Purchase commercial support

Bank: Rabobank
Country: Netherlands
SWIFT: RABONL2U
Account: 147850770
Name: Marijn Haverbeke
IBAN: NL26 RABO 0147 8507 70

## Releases:

23-04-2012: Version 2.24:

- Drop support for Internet Explorer 6.
- New modes: Shell, Tiki wiki, Pig Latin.
- New themes: Ambiance, Blackboard.
- More control over drag/drop with `dragDrop` and `onDragEvent` options.
- Make HTML mode a bit less pedantic.
- Add `compoundChange` API method.
- Several fixes in undo history and line hiding.
- Remove (broken) support for `catchall` in key maps, add `nofallthrough` boolean field instead.

26-03-2012: Version 2.23:

- Change default binding for tab [more]
  Starting in 2.23, these bindings are default:
  - Tab: Insert tab character
  - Shift-tab: Reset line indentation to default
  - Ctrl/Cmd-[: Reduce line indentation (old tab behaviour)
  - Ctrl/Cmd-]: Increase line indentation (old shift-tab behaviour)
- New modes: XQuery and VBScript.
- Two new themes: lesser-dark and xq-dark.
- Differentiate between background and text styles in `setLineClass`.
- Fix drag-and-drop in IE9+.
- Extend `charCoords` and `cursorCoords` with a `mode` argument.
- Add `autofocus` option.
- Add `findMarksAt` method.

27-02-2012: Version 2.22:

- Allow key handlers to pass up events, allow binding characters.
- Add `autoClearEmptyLines` option.
- Properly use tab stops when rendering tabs.
- Make PHP mode more robust.
- Support indentation blocks in code folder.
- Add a script for highlighting instances of the selection.
- New .properties mode.
- Fix many bugs.

27-01-2012: Version 2.21:

- Added LESS, MySQL, Go, and Verilog modes.
- Add `smartIndent` option.
- Support a cursor in `readOnly`-mode.
- Support assigning multiple styles to a token.
- Use a new approach to drawing the selection.
- Add `scrollTo` method.
- Allow undo/redo events to span non-adjacent lines.
- Lots and lots of bugfixes.

20-12-2011: Version 2.2:

- Slightly incompatible API changes. Read this.
- New approach to binding keys, support for custom bindings.
- Support for overwrite (insert).
- Custom-width and stylable tabs.
- Moved more code into add-on scripts.
- Support for sane vertical cursor movement in wrapped lines.
- More reliable handling of editing marked text.
- Add minimal emacs and vim bindings.
- Rename `coordsFromIndex` to `posFromIndex`, add `indexFromPos` method.

21-11-2011: Version 2.18:

Fixes `TextMarker.clear`, which is broken in 2.17.

21-11-2011: Version 2.17:

- Add support for line wrapping and code folding.
- Add Github-style Markdown mode.
- Add Monokai and Rubyblue themes.
- Add `setBookmark` method.
- Move some of the demo code into reusable components under `lib/util`.
- Make screen-coord-finding code faster and more reliable.
- Fix drag-and-drop in Firefox.
- Improve support for IME.
- Speed up content rendering.
- Fix browser's built-in search in Webkit.
- Make double- and triple-click work in IE.
- Various fixes to modes.

27-10-2011: Version 2.16:

- Add Perl, Rust, TiddlyWiki, and Groovy modes.
- Dragging text inside the editor now moves, rather than copies.
- Add a `coordsFromIndex` method.
- API change: `setValue` now no longer clears history. Use `clearHistory` for that.
- API change: `markText` now returns an object with `clear` and `find` methods. Marked text is now more robust when edited.
- Fix editing code with tabs in Internet Explorer.

26-09-2011: Version 2.15:

Fix bug that snuck into 2.14: Clicking the character that currently has the cursor didn't re-focus the editor.

26-09-2011: Version 2.14:

- Add Clojure, Pascal, NTriples, Jinja2, and Markdown modes.
- Add Cobalt and Eclipse themes.
- Add a `fixedGutter` option.
- Fix bug with `setValue` breaking cursor movement.
- Make gutter updates much more efficient.
- Allow dragging of text out of the editor (on modern browsers).

Older releases...