<commit_before>'use babel';

// AnySyn package (https://github.com/mark-hahn/anysyn)

import * as SubAtom from 'sub-atom';

let log = console.log.bind(console);

export let config = {
  regexes: {
    title: 'Regexes to match file paths to syntax plugins',
    description: 'Format is regex:plugin-name, separate with commas',
    type: 'array',
    default: ['.*/anysyn1.js:coffee', '.*/anysyn2.js:coffee'],
    items: { type: 'string' }
  }
}

export let activate = () => {
  this.subs = new SubAtom;
  
  log('AnySyn activated');
  this.syntaxServices = [];
  atom.config.observe('anysyn.regexes', () => this.parseRegexes());
  this.opener = (filePath, options) => {
    log('opener', {filePath, options});
    for (regexMatch of this.regexMatches) {
      if (regexMatch.regex.test(filePath)) {
        for (service of this.syntaxServices) {
          if (service.name === regexMatch.plugin) {
            found = true;
            this.loadFile(filePath, service);
            return new atom.TextEditor;
          }
        }
        log(`AnySyn, Plugin not found: ${regexMatch.plugin}`);
      }
    }
  }
  atom.workspace.addOpener(this.opener);
  this.subs.add(this.opener);
}

export let addSyntax = (syntaxService) => {
  log('addSyntax', syntaxService.name);
  syntaxServices.push(syntaxService);
}

export let deActivate = () =>  {
  this.subs.dispose();
  log('AnySyn deActivated');
}

// ------------ Private ------------

this.parseRegexes = () => {
  this.regexMatches = [];
  for (regex of atom.config.get('anysyn.regexes')) {
    let [regexStr, plugin] = regex.split(':');
    if (typeof regexStr !== 'string' || typeof plugin !== 'string')
      log(`AnySyn: Configuration parse error for ${regexStr}:${plugin}`);
    this.regexMatches.push({regex: new RegExp(regexStr), plugin});
  }
  log('this.regexMatches', this.regexMatches);
}

this.loadFile = (filePath, service) => {
  log('loadFile', {filePath, service});
}

<commit_msg>added checkeditor<commit_after>'use babel';

// AnySyn package (https://github.com/mark-hahn/anysyn)

import SubAtom from 'sub-atom';

const log = console.log.bind(console);
const self = {};

export const config = {
  regexes: {
    title:       'Regexes to match file paths to syntax plugins',
    description: 'Format is regex:plugin-name, separate with commas',
    type:        'array',
    default:    ['.*/anysyn1.js:coffee', '.*/anysyn2.js:coffee'],
    items: { 
      type: 'string' 
    }
  }
}

export const activate = () => {
  self.subs = new SubAtom;
  self.syntaxServices = [];
  self.subs.add(atom.config.observe('anysyn.regexes', () => self.parseRegexes()));
  self.subs.add(atom.workspace.observeTextEditors((editor) => self.checkEditor(editor)));
}

export const addSyntax = (syntaxService) => {
  log('addSyntax', syntaxService.name);
  self.syntaxServices.push(syntaxService);
}

export const deActivate = () =>  {
  // self.subs.disposeAll();
  // log('AnySyn deActivated');
}

// ------------ Private --------------

self.parseRegexes = () => {
  self.regexMatches = [];
  for (regex of atom.config.get('anysyn.regexes')) {
    const [regexStr, plugin] = regex.split(':');
    if (typeof regexStr !== 'string' || typeof plugin !== 'string')
      log(`AnySyn: Configuration parse error for ${regexStr}:${plugin}`);
      continue;
    self.regexMatches.push({regex: new RegExp(regexStr), plugin});
  }
  log('self.regexMatches', self.regexMatches);
}

self.checkEditor = (editor) => {  
  log('checkEditor', {editor});
  let filePath = editor.getPath();
  for (regexMatch of self.regexMatches) {
    if (regexMatch.regex.test(filePath)) {
      for (service of self.syntaxServices) {
        if (service.name === regexMatch.plugin) {
          self.loadFile(editor, filePath, service);
          return
        }
      }
      log(`AnySyn, Plugin not found: ${regexMatch.plugin}`);
    }
  }
}

self.loadFile = (editor, filePath, service) => {
  log('loadFile', {editor, filePath, service});
}

{'fraction_non_alphanumeric': 0.17893145161290322, 'fraction_numerical': 0.0010080645161290322, 'mean_word_length': 3.173501577287066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '2164203', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1304, 'n_words': 269}