-
-
Notifications
You must be signed in to change notification settings - Fork 303
Advanced: Accessing somewhat hidden ACE features
Dmitry edited this page Feb 13, 2015
·
2 revisions
Basically, If you would like to use any ACE extension and have an example code for pure ACE like this:
<!-- load ace -->
<script src="../build/src-noconflict/ace.js"></script>
<!-- load ace language tools -->
<script src="../build/src-noconflict/ext-language_tools.js"></script>
<script>
// trigger extension
ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");
// enable autocompletion and snippets
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false
});
</script>
You should replace with a following browserify equivalent:
var ace = require('brace'); // <script src="../build/src-noconflict/ace.js"></script>
require('brace/ext/language_tools.js') // <script src="../build/src-noconflict/ext-language_tools.js">
// trigger extension
ace.acequire("ace/ext/language_tools");//ace.require("ace/ext/language_tools");
var editor = ace.edit("editor");
// enable autocompletion and snippets
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: false
});
</script>
Why do you have to require the extension twice? First require
tells browserify
to include this file via CommonJS
module system. But if you look at source code:
ace.define("ace/snippets",["require","exports","module","ace/lib/oop"], function(acequire, exports, module) {
// module
});
ace.define("ace/autocomplete",["require","exports","module","ace/keyboard/hash_handler","ace/autocomplete/popup","ace/autocomplete/util","ace/lib/event","ace/lib/lang","ace/snippets"], function(acequire, exports, module) {
// module
});
(function() {
ace.acequire(["ace/ext/language_tools"], function() {});
})();
You see ACE internal module system, with RequireJS
conventions. So you need to perform second require, at this time there is an alias for this ace.acequire
.