<commit_before>"use 6to5";

var language = require('./geck-language');

module.exports = {
  // The basic regular expression string used to find GECK functions
  geckFnRegEx: '\\b[\\w_\\-]+\\b/',

  // The base URL used for documentation reference for GECK functions
  urlBase: 'http://geck.bethsoft.com/index.php?title=',

  // Base functions page
  fnBase: 'http://geck.bethsoft.com/index.php?title=Category:Functions',

  // Language syntax
  syntax: language,

  // Grammars Added
  grammarsAdded: false,

  // Configuration
  config: {
    highlightVegas: {
      type: 'boolean',
      'default': true
    },
    highlightNVSE: {
      "type": "boolean",
      "default": true
    },
    highlightFOSE: {
      "type": "boolean",
      "default": true
    },
    highlightNX: {
      "type": "boolean",
      "default": true
    }
  },

  /**
   * This is the primary required function for an exported module. This
   * function invokes _getSelectedText with a regular expression string
   * used to determine the name of the function in question and then
   * takes that matching text and opens a web browser to that page if
   * <NAME>'s web-browser package is installed.
   */
  activate: function(state) {
    atom.commands.add(
      'atom-text-editor',
      'language-geck:lookup',
      this.lookupSelected.bind(this)
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleFOSE',
      this.toggleConfig.bind(this, 'language-geck.highlightFOSE')
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleVegas',
      this.toggleConfig.bind(this, 'language-geck.highlightVegas')
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleNVSE',
      this.toggleConfig.bind(this, 'language-geck.highlightNVSE')
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleNX',
      this.toggleConfig.bind(this, 'language-geck.highlightNX')
    );

    atom.packages.on('activated', this.updateGrammars.bind(this));
    this.updateGrammars();
  },

  /**
   * Command: language-geck:lookup
   *
   * This function is invoked in a manner of ways (menu, context-menu, and
   * keymap); it's purpose is to either open the selected text, hopefully
   * a function known to GECK, in a web browser or the root functions page
   * if the rest is unavailable.
   */
  lookupSelected: function() {
    console.log("[language-geck] lookup invoked!");
    this._getSelectedText(this.geckFnRegEx, (function(text) {
      var browser;

      browser = atom.packages.getActivePackage('web-browser');
      if (browser) {
        if (text.length) {
          console.log('[language-geck] Selected function -> %o', text);
          atom.workspace.open([this.urlBase, text].join(''));
        }
        else {
          console.log('[language-geck] Opening functions root');
          atom.workspace.open(this.fnBase);
        }
      }
      else {
        console.error("[language-geck] web-browser is a required package.");
      }
    }).bind(this));
  },

  toggleConfig: function(config, event) {
    var value = atom.config.get(config);
    atom.config.set(config, !value);
    this.updateGrammars();
  },

  updateGrammars: function() {
    // Obtain the highlight flags
    var cfg = atom.config.get('language-geck');

    // Supplement grammer
    var grammar = atom.grammars.grammarsByScopeName['source.geck'];

    // Remove dynamic grammars
    for (let a = grammar.rawPatterns, i = 0; i < a.length; i++) {
      if (a[i].___type && a[i].___type === 'dynamic') {
        a.splice(i, 1);
        i--;
      }
    }

    var patterns = [
      [true, 'keyword.geck-keyword', [language.keywords]],
      [true, 'keyword.control.geck.blocktype', [language.blocktypes, true]],<commit_msg>updateGrammars will wait 1s if not ready<commit_after>"use 6to5";

var language = require('./geck-language');

module.exports = {
  // The basic regular expression string used to find GECK functions
  geckFnRegEx: '\\b[\\w_\\-]+\\b/',

  // The base URL used for documentation reference for GECK functions
  urlBase: 'http://geck.bethsoft.com/index.php?title=',

  // Base functions page
  fnBase: 'http://geck.bethsoft.com/index.php?title=Category:Functions',

  // Language syntax
  syntax: language,

  // Grammars Added
  grammarsAdded: false,

  // Configuration
  config: {
    highlightVegas: {
      type: 'boolean',
      'default': true
    },
    highlightNVSE: {
      "type": "boolean",
      "default": true
    },
    highlightFOSE: {
      "type": "boolean",
      "default": true
    },
    highlightNX: {
      "type": "boolean",
      "default": true
    }
  },

  /**
   * This is the primary required function for an exported module. This
   * function invokes _getSelectedText with a regular expression string
   * used to determine the name of the function in question and then
   * takes that matching text and opens a web browser to that page if
   * Mark Hahn's web-browser package is installed.
   */
  activate: function(state) {
    atom.commands.add(
      'atom-text-editor',
      'language-geck:lookup',
      this.lookupSelected.bind(this)
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleFOSE',
      this.toggleConfig.bind(this, 'language-geck.highlightFOSE')
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleVegas',
      this.toggleConfig.bind(this, 'language-geck.highlightVegas')
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleNVSE',
      this.toggleConfig.bind(this, 'language-geck.highlightNVSE')
    );

    atom.commands.add(
      'atom-text-editor',
      'language-geck:toggleNX',
      this.toggleConfig.bind(this, 'language-geck.highlightNX')
    );

    atom.packages.on('activated', this.updateGrammars.bind(this));
    this.updateGrammars();
  },

  /**
   * Command: language-geck:lookup
   *
   * This function is invoked in a manner of ways (menu, context-menu, and
   * keymap); it's purpose is to either open the selected text, hopefully
   * a function known to GECK, in a web browser or the root functions page
   * if the rest is unavailable.
   */
  lookupSelected: function() {
    console.log("[language-geck] lookup invoked!");
    this._getSelectedText(this.geckFnRegEx, (function(text) {
      var browser;

      browser = atom.packages.getActivePackage('web-browser');
      if (browser) {
        if (text.length) {
          console.log('[language-geck] Selected function -> %o', text);
          atom.workspace.open([this.urlBase, text].join(''));
        }
        else {
          console.log('[language-geck] Opening functions root');
          atom.workspace.open(this.fnBase);
        }
      }
      else {
        console.error("[language-geck] web-browser is a required package.");
      }
    }).bind(this));
  },

  toggleConfig: function(config, event) {
    var value = atom.config.get(config);
    atom.config.set(config, !value);
    this.updateGrammars();
  },

  updateGrammars: function() {
    // Obtain the highlight flags
    var cfg = atom.config.get('language-geck');

    // Supplement grammer
    var grammar = atom.grammars.grammarsByScopeName['source.geck'];
    if (!grammar) {
      setTimeout(this.updateGrammars.bind(this), 1000);
      console.log('Grammar not yet available, trying again in 1s');
      return;
    }

    // Remove dynamic grammars
    for (let a = grammar.rawPatterns, i = 0; i < a.length; i++) {
      if (a[i].___type && a[i].___type === 'dynamic') {
        a.splice(i, 1);
        i--;
      }
    }

    var patterns = [
      [true, 'keyword.geck-keyword', [language.keywords]],
      [true, 'keyword.control.geck.blocktype', [language.blocktypes, true]],
{'fraction_non_alphanumeric': 0.13960955561263808, 'fraction_numerical': 0.0017980991523246853, 'mean_word_length': 2.6800567107750473, 'pattern_counts': {'":': 12, '<': 6, '<?xml version=': 0, '>': 6, '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': '2234185', 'n_tokens_mistral': 2509, 'n_tokens_neox': 2436, 'n_words': 567}