<commit_before>function ddg_spice_editor(api_result) {

    var script = $('[src*="/js/spice/editor/"]')[0];
    var source = $(script).attr("src");
    var language = source.match(/editor\/([^\/]+)/)[1];

    nrj(DDG.get_asset_path('editor', 'ace.js'));

        // Function referenced in ace.js
        window.aceScriptLoaded = function() {

            var editor_id = "ace-editor";

            var editor = ace.edit(editor_id);

            // Set theme based on DDG theme
            if ($(".dark-header").length) {
                editor.setTheme("ace/theme/monokai");
            } else {
                editor.setTheme("ace/theme/eclipse");
            }

            // Listen for clicks on the default theme button and change editor theme accordingly
            $(".nav-menu__theme--default").click(function(e) {
                editor.setTheme("ace/theme/eclipse");
                e.stopPropagation();
            });

            // Listen for clicks on the dark theme button and change editor theme accordingly
            $(".nav-menu__theme--d").click(function(e) {
                editor.setTheme("ace/theme/monokai");
                e.stopPropagation();
            });

            editor.getSession().setMode("ace/mode/" + language);

            $("#" + editor_id).height("400px");

            // Stop DDG keybindings, when editor has focus
            $("#" + editor_id).keydown(function(e) {
                e.stopPropagation();
            });
        }

    Spice.add({
        id: 'editor',
        name: 'Editor',
        data: api_result,
        meta: {
            sourceName: "Ace",
            sourceUrl: "http://ace.c9.io/"
        },
        normalize: function(item) {

            function formatLanguageName(language) {
                var languageNames = {
                    "javascript": "JavaScript",
                    "python": "Python"
                };

                return languageNames[language.toLowerCase()];
            }

            return {
                title: formatLanguageName(language) + " Editor"
            };
        },
        templates: {
            group: 'base',
            options: {
                content: Spice.editor.editor
            }
        },
    });
    //Need this to make sure jQuery does add a uniqe key to the requested URL (which causes problems)
    $.ajaxSetup({
        cache: true
    });
    $.getScript("/share/spice/editor/ace.js", function(data, textStatus, jqxhr) {
        var editor_id = "ace-editor";
        var editor = ace.edit(editor_id);

        // Set theme based on DDG theme
        if($(".dark-header").length) {
            editor.setTheme("ace/theme/monokai");
        } else {
            editor.setTheme("ace/theme/eclipse");
        }

        // If the user changes DDG theme, change the editor theme too
        $(".nav-menu__theme--default").click(function(e) {
            editor.setTheme("ace/theme/eclipse");
            e.stopPropagation();
        });

        $(".nav-menu__theme--d").click(function(e) {
            editor.setTheme("ace/theme/monokai");
            e.stopPropagation();
        });

        editor.getSession().setMode("ace/mode/" + language);

        $("#" + editor_id).height("400px");

        // Stop DDG keybindings, when editor has focus
        $("#" + editor_id).keydown(function(e) {
            e.stopPropagation();
        });
    });
};

ddg_spice_editor();<commit_msg>Editor - remove duplicate code<commit_after>function ddg_spice_editor(api_result) {

    var script = $('[src*="/js/spice/editor/"]')[0];
    var source = $(script).attr("src");
    var language = source.match(/editor\/([^\/]+)/)[1];

    nrj(DDG.get_asset_path('editor', 'ace.js'));

        // Function referenced in ace.js
        window.aceScriptLoaded = function() {

            var editor_id = "ace-editor";

            var editor = ace.edit(editor_id);

            // Set theme based on DDG theme
            if ($(".dark-header").length) {
                editor.setTheme("ace/theme/monokai");
            } else {
                editor.setTheme("ace/theme/eclipse");
            }

            // Listen for clicks on the default theme button and change editor theme accordingly
            $(".nav-menu__theme--default").click(function(e) {
                editor.setTheme("ace/theme/eclipse");
                e.stopPropagation();
            });

            // Listen for clicks on the dark theme button and change editor theme accordingly
            $(".nav-menu__theme--d").click(function(e) {
                editor.setTheme("ace/theme/monokai");
                e.stopPropagation();
            });

            editor.getSession().setMode("ace/mode/" + language);

            $("#" + editor_id).height("400px");

            // Stop DDG keybindings, when editor has focus
            $("#" + editor_id).keydown(function(e) {
                e.stopPropagation();
            });
        }

    Spice.add({
        id: 'editor',
        name: 'Editor',
        data: api_result,
        meta: {
            sourceName: "Ace",
            sourceUrl: "http://ace.c9.io/"
        },
        normalize: function(item) {

            function formatLanguageName(language) {
                var languageNames = {
                    "javascript": "JavaScript",
                    "python": "Python"
                };

                return languageNames[language.toLowerCase()];
            }

            return {
                title: formatLanguageName(language) + " Editor"
            };
        },
        templates: {
            group: 'base',
            options: {
                content: Spice.editor.editor
            }
        },
    });
};

ddg_spice_editor();
{'fraction_non_alphanumeric': 0.14273250741580876, 'fraction_numerical': 0.002617344268016053, 'mean_word_length': 1.5796579657965797, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4012260', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1533, 'n_words': 302}