src/language/LanguageManager.js
function defineLanguage(id, definition) {
        var result = new $.Deferred();

        if (_pendingLanguages[id]) {
            result.reject("Language \"" + id + "\" is waiting to be resolved.");
            return result.promise();
        }
        if (_languages[id]) {
            result.reject("Language \"" + id + "\" is already defined");
            return result.promise();
        }

        var language       = new Language(),
            name           = definition.name,
            fileExtensions = definition.fileExtensions,
            fileNames      = definition.fileNames,
            blockComment   = definition.blockComment,
            lineComment    = definition.lineComment,
            i,
            l;

        function _finishRegisteringLanguage() {
            if (fileExtensions) {
                for (i = 0, l = fileExtensions.length; i < l; i++) {
                    language.addFileExtension(fileExtensions[i]);
                }
            }
            // register language file names after mode has loaded
            if (fileNames) {
                for (i = 0, l = fileNames.length; i < l; i++) {
                    language.addFileName(fileNames[i]);
                }
            }

            language._setBinary(!!definition.isBinary);

            // store language to language map
            _languages[language.getId()] = language;

            // restore any preferences for non-default languages
            if(PreferencesManager) {
                _updateFromPrefs(_EXTENSION_MAP_PREF);
                _updateFromPrefs(_NAME_MAP_PREF);
            }
        }

        if (!language._setId(id) || !language._setName(name) ||
                (blockComment && !language.setBlockCommentSyntax(blockComment[0], blockComment[1])) ||
                (lineComment && !language.setLineCommentSyntax(lineComment))) {
            result.reject();
            return result.promise();
        }


        if (definition.isBinary) {
            // add file extensions and store language to language map
            _finishRegisteringLanguage();

            result.resolve(language);
            // Not notifying DocumentManager via event LanguageAdded, because DocumentManager
            // does not care about binary files.
        } else {
            // track languages that are currently loading
            _pendingLanguages[id] = language;

            language._loadAndSetMode(definition.mode).done(function () {

                // globally associate mode to language
                _setLanguageForMode(language.getMode(), language);

                // add file extensions and store language to language map
                _finishRegisteringLanguage();

                // fire an event to notify DocumentManager of the new language
                _triggerLanguageAdded(language);

                result.resolve(language);
            }).fail(function (error) {
                console.error(error);
                result.reject(error);
            }).always(function () {
                // delete from pending languages after success and failure
                delete _pendingLanguages[id];
            });
        }

        return result.promise();
    }
function defineLanguage(id, definition) {
        var result = new $.Deferred();

        if (_pendingLanguages[id]) {
            result.reject("Language \"" + id + "\" is waiting to be resolved.");
            return result.promise();
        }
        if (_languages[id]) {
            result.reject("Language \"" + id + "\" is already defined");
            return result.promise();
        }

        var language       = new Language(),
            name           = definition.name,
            fileExtensions = definition.fileExtensions,
            fileNames      = definition.fileNames,
            blockComment   = definition.blockComment,
            lineComment    = definition.lineComment,
            i,
            l;

        function _finishRegisteringLanguage() {
            if (fileExtensions) {
                for (i = 0, l = fileExtensions.length; i < l; i++) {
                    language.addFileExtension(fileExtensions[i]);
                }
            }
            // register language file names after mode has loaded
            if (fileNames) {
                for (i = 0, l = fileNames.length; i < l; i++) {
                    language.addFileName(fileNames[i]);
                }
            }

            language._setBinary(!!definition.isBinary);

            // store language to language map
            _languages[language.getId()] = language;

            // restore any preferences for non-default languages
            if(PreferencesManager) {
                _updateFromPrefs(_EXTENSION_MAP_PREF);
                _updateFromPrefs(_NAME_MAP_PREF);
            }
        }

        if (!language._setId(id) || !language._setName(name) ||
                (blockComment && !language.setBlockCommentSyntax(blockComment[0], blockComment[1])) ||
                (lineComment && !language.setLineCommentSyntax(lineComment))) {
            result.reject();
            return result.promise();
        }


        if (definition.isBinary) {
            // add file extensions and store language to language map
            _finishRegisteringLanguage();

            result.resolve(language);
            // Not notifying DocumentManager via event LanguageAdded, because DocumentManager
            // does not care about binary files.
        } else {
            // track languages that are currently loading
            _pendingLanguages[id] = language;

            language._loadAndSetMode(definition.mode).done(function () {

                // globally associate mode to language
                _setLanguageForMode(language.getMode(), language);

                // add file extensions and store language to language map
                _finishRegisteringLanguage();

                // fire an event to notify DocumentManager of the new language
                _triggerLanguageAdded(language);

                result.resolve(language);
            }).fail(function (error) {
                console.error(error);
                result.reject(error);
            }).always(function () {
                // delete from pending languages after success and failure
                delete _pendingLanguages[id];
            });
        }

        return result.promise();
    }
function defineLanguage ( id , definition ) { var result = new $ . Deferred ( ) ; if ( _pendingLanguages [ id ] ) { result . reject ( "Language \"" + id + "\" is waiting to be resolved." ) ; return result . promise ( ) ; } if ( _languages [ id ] ) { result . reject ( "Language \"" + id + "\" is already defined" ) ; return result . promise ( ) ; } var language = new Language ( ) , name = definition . name , fileExtensions = definition . fileExtensions , fileNames = definition . fileNames , blockComment = definition . blockComment , lineComment = definition . lineComment , i , l ; function _finishRegisteringLanguage ( ) { if ( fileExtensions ) { for ( i = 0 , l = fileExtensions . length ; i < l ; i ++ ) { language . addFileExtension ( fileExtensions [ i ] ) ; } } // register language file names after mode has loaded if ( fileNames ) { for ( i = 0 , l = fileNames . length ; i < l ; i ++ ) { language . addFileName ( fileNames [ i ] ) ; } } language . _setBinary ( ! ! definition . isBinary ) ; // store language to language map _languages [ language . getId ( ) ] = language ; // restore any preferences for non-default languages if ( PreferencesManager ) { _updateFromPrefs ( _EXTENSION_MAP_PREF ) ; _updateFromPrefs ( _NAME_MAP_PREF ) ; } } if ( ! language . _setId ( id ) || ! language . _setName ( name ) || ( blockComment && ! language . setBlockCommentSyntax ( blockComment [ 0 ] , blockComment [ 1 ] ) ) || ( lineComment && ! language . setLineCommentSyntax ( lineComment ) ) ) { result . reject ( ) ; return result . promise ( ) ; } if ( definition . isBinary ) { // add file extensions and store language to language map _finishRegisteringLanguage ( ) ; result . resolve ( language ) ; // Not notifying DocumentManager via event LanguageAdded, because DocumentManager // does not care about binary files. } else { // track languages that are currently loading _pendingLanguages [ id ] = language ; language . _loadAndSetMode ( definition . mode ) . done ( function ( ) { // globally associate mode to language _setLanguageForMode ( language . getMode ( ) , language ) ; // add file extensions and store language to language map _finishRegisteringLanguage ( ) ; // fire an event to notify DocumentManager of the new language _triggerLanguageAdded ( language ) ; result . resolve ( language ) ; } ) . fail ( function ( error ) { console . error ( error ) ; result . reject ( error ) ; } ) . always ( function ( ) { // delete from pending languages after success and failure delete _pendingLanguages [ id ] ; } ) ; } return result . promise ( ) ; }
Defines a language.

@param {!string}               id                        Unique identifier for this language: lowercase letters, digits, and _ separators (e.g. "cpp", "foo_bar", "c99")
@param {!Object}               definition                An object describing the language
@param {!string}               definition.name           Human-readable name of the language, as it's commonly referred to (e.g. "C++")
@param {Array.<string>}        definition.fileExtensions List of file extensions used by this language (e.g. ["php", "php3"] or ["coffee.md"] - may contain dots)
@param {Array.<string>}        definition.fileNames      List of exact file names (e.g. ["Makefile"] or ["package.json]). Higher precedence than file extension.
@param {Array.<string>}        definition.blockComment   Array with two entries defining the block comment prefix and suffix (e.g. ["<!--", "-->"])
@param {(string|Array.<string>)} definition.lineComment  Line comment prefixes (e.g. "//" or ["//", "#"])
@param {(string|Array.<string>)} definition.mode         CodeMirror mode (e.g. "htmlmixed"), optionally with a MIME mode defined by that mode ["clike", "text/x-c++src"]
Unless the mode is located in thirdparty/CodeMirror/mode/<name>/<name>.js, you need to first load it yourself.

@return {$.Promise} A promise object that will be resolved with a Language object
Defines a language .