<commit_before>/* global atom document:true */

const { KillRing } = require('../kill-ring');
const Searcher = require('./searcher');
const SelectList = require('atom-select-list');

module.exports = {
  config: {
    useLegacySearch: {
      type: 'boolean',
      default: true
    },
    inputControlCharacter: {
      type: 'boolean',
      default: false
    },
    killRing: {
      type: 'object',
      properties: {
        persistent: {
          type: 'boolean',
          default: true
        },
        length: {
          type: 'integer',
          default: 10,
          minimum: 1
        }
      }
    }
  },

  killring: null,
  commands: null,
  eventListeners: [],
  editorViews: [],
  addTextEditorListener: null,
  isUserCommand: true,
  searcher: null,

  activate: state => {
    module.exports.isUserCommand = true;
    module.exports.searcher = new Searcher();

    module.exports.commands = atom.commands.add('atom-text-editor', {
      'emacs:cancel': () => module.exports.cancel(),
      'emacs:set-mark': () => module.exports.setMark(),
      'emacs:yank': () => module.exports.yank(),
      'emacs:kill': () => module.exports.kill(),
      'emacs:show-kill-ring': () => module.exports.showKillRing(),
      'emacs:kill-region': () => module.exports.killRegion(),
      'emacs:copy-region': () => module.exports.copyRegion(),
      'emacs:kill-backward-word': () => module.exports.killBackwardWord(),
      'emacs:kill-region-or-backward-word': () => module.exports.killRegionOrBackwardWord(),
      'emacs:isearch': e => module.exports.searcher.search(e, true, false),
      'emacs:backward-isearch': e => module.exports.searcher.search(e, false, false),
      'emacs:isearch-regexp': e => module.exports.searcher.search(e, true, true),
      'emacs:backward-isearch-regexp': e => module.exports.searcher.search(e, false, true),
      'emacs:backspace': () => module.exports.backspace()
    });

    const addEditorEventListner = editor => {
      module.exports.eventListeners.push(
        editor.onDidChangeCursorPosition(() => {
          if (module.exports.isUserCommand && module.exports.killring)
            module.exports.killring.seal();
          if (module.exports.searcher.isUserCommand && module.exports.searcher)
            module.exports.searcher.deactivateISearch();
        })
      );
      let editorView = atom.views.getView(editor);
      module.exports.clickListener = () => {
        editorView.classList.remove('transient-marked');
        const findAndReplace = atom.packages.getActivePackage('find-and-replace');
        if (
          findAndReplace &&
          findAndReplace.mainModule.findPanel &&
          findAndReplace.mainModule.findPanel.isVisible()
        )
          findAndReplace.mainModule.findPanel.hide();
      };
      editorView.addEventListener('click', module.exports.clickListener);
      module.exports.editorViews.push(editorView);
    };

    atom.workspace.getTextEditors().forEach(addEditorEventListner);
    module.exports.addTextEditorListener = atom.workspace.onDidAddTextEditor(event =>
      addEditorEventListner(event.textEditor)
    );

    module.exports.searcher.addIsearchCommands();
    if (atom.config.get('transient-emacs.inputControlCharacter'))
      module.exports.addInputCtrlsCommands();

    module.exports.killring =
      state && state.killring ? atom.deserializers.deserialize(state.killring) : new KillRing([]);
  },

  deserializeKillRing: ({ buffer }) => new KillRing(buffer),

  addInputCtrlsCommands: () => {
    let inputCtrlKeybindings = {};
    let inputCtrlCommandMap = {};
    let inputCtrlSelector = 'atom-text-editor';
    inputCtrlKeybindings[inputCtrlSelector] = {};
    for (let code = 0; code < 32; code++) {
      const command = 'emacs:input-ctrl-' + code;
      const keybind = 'ctrl-q ctrl-' + String.fromCharCode(code + (0 < code < 27 ? 96 : 64));<commit_msg>Use clipboardy for atom editor<commit_after>/* global atom document:true */

const { KillRing } = require('../kill-ring');
const Searcher = require('./searcher');
const SelectList = require('atom-select-list');
const clipboardy = require('clipboardy');

module.exports = {
  config: {
    useLegacySearch: {
      type: 'boolean',
      default: true
    },
    inputControlCharacter: {
      type: 'boolean',
      default: false
    },
    killRing: {
      type: 'object',
      properties: {
        persistent: {
          type: 'boolean',
          default: true
        },
        length: {
          type: 'integer',
          default: 10,
          minimum: 1
        }
      }
    }
  },

  killring: null,
  commands: null,
  eventListeners: [],
  editorViews: [],
  addTextEditorListener: null,
  isUserCommand: true,
  searcher: null,

  activate: state => {
    module.exports.isUserCommand = true;
    module.exports.searcher = new Searcher();

    module.exports.commands = atom.commands.add('atom-text-editor', {
      'emacs:cancel': () => module.exports.cancel(),
      'emacs:set-mark': () => module.exports.setMark(),
      'emacs:yank': () => module.exports.yank(),
      'emacs:kill': () => module.exports.kill(),
      'emacs:show-kill-ring': () => module.exports.showKillRing(),
      'emacs:kill-region': () => module.exports.killRegion(),
      'emacs:copy-region': () => module.exports.copyRegion(),
      'emacs:kill-backward-word': () => module.exports.killBackwardWord(),
      'emacs:kill-region-or-backward-word': () => module.exports.killRegionOrBackwardWord(),
      'emacs:isearch': e => module.exports.searcher.search(e, true, false),
      'emacs:backward-isearch': e => module.exports.searcher.search(e, false, false),
      'emacs:isearch-regexp': e => module.exports.searcher.search(e, true, true),
      'emacs:backward-isearch-regexp': e => module.exports.searcher.search(e, false, true),
      'emacs:backspace': () => module.exports.backspace()
    });

    const addEditorEventListner = editor => {
      module.exports.eventListeners.push(
        editor.onDidChangeCursorPosition(() => {
          if (module.exports.isUserCommand && module.exports.killring)
            module.exports.killring.seal();
          if (module.exports.searcher.isUserCommand && module.exports.searcher)
            module.exports.searcher.deactivateISearch();
        })
      );
      let editorView = atom.views.getView(editor);
      module.exports.clickListener = () => {
        editorView.classList.remove('transient-marked');
        const findAndReplace = atom.packages.getActivePackage('find-and-replace');
        if (
          findAndReplace &&
          findAndReplace.mainModule.findPanel &&
          findAndReplace.mainModule.findPanel.isVisible()
        )
          findAndReplace.mainModule.findPanel.hide();
      };
      editorView.addEventListener('click', module.exports.clickListener);
      module.exports.editorViews.push(editorView);
    };

    atom.workspace.getTextEditors().forEach(addEditorEventListner);
    module.exports.addTextEditorListener = atom.workspace.onDidAddTextEditor(event =>
      addEditorEventListner(event.textEditor)
    );

    module.exports.searcher.addIsearchCommands();
    if (atom.config.get('transient-emacs.inputControlCharacter'))
      module.exports.addInputCtrlsCommands();

    module.exports.killring =
      state && state.killring
        ? atom.deserializers.deserialize(state.killring)
        : new KillRing([], clipboardy.read, clipboardy.write);
  },

  deserializeKillRing: ({ buffer }) => new KillRing(buffer),

  addInputCtrlsCommands: () => {
    let inputCtrlKeybindings = {};
    let inputCtrlCommandMap = {};
    let inputCtrlSelector = 'atom-text-editor';
    inputCtrlKeybindings[inputCtrlSelector] = {};
    for (let code = 0; code < 32; code++) {
      const command = 'emacs:input-ctrl-' + code;
      const keybind = 'ctrl-q ctrl-' + String.fromCharCode(code + (0 < code < 27 ? 96 : 64));
{'fraction_non_alphanumeric': 0.14991136996708027, 'fraction_numerical': 0.0032919726513041276, 'mean_word_length': 3.011681056373794, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, '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': '4464257', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2374, 'n_words': 366}