<commit_before>'use babel'

const oneIndentForms = ['fn', 'def', 'defn', 'ns', 'let', 'for', 'loop',
  'when', 'when-let', 'if', 'if-let', 'if-not', 'when-not', 'cond', 'do',
  'doseq', 'dotimes'
]

function calculateIndent ({row, column}, content) {
  let x = 0
  let y = 0
  let openBrackets = []

  while (true) {
    const char = content[y][x]

    if (char === '(') {
      const first = content[y].slice(x + 1).split(' ')[0]

      openBrackets.push(
        oneIndentForms.includes(first)
          ? (x + 2)
          : (x + first.length + 2)
        )
    }
    if (char === '[' || char === '{') openBrackets.push(x + 1)
    if (char === ')' || char === ']' || char === '}') openBrackets.pop()

    x++
    if (x >= content[y].length) {
      x = 0
      y++
      if (y >= content.length) {
        break
      }
    }
  }

  return openBrackets.length
    ? ' '.repeat(openBrackets[openBrackets.length - 1])
    : ''
}

export function insertNewLine () {
  const editor = atom.workspace.getActiveTextEditor()
  const {row, column} = editor.getCursorBufferPosition()
  const lines = editor.getTextInBufferRange([[0, 0], [row, column]])
    .split('\n')

  const indent = calculateIndent({row, column}, lines)

  editor.getBuffer().setTextInRange(
    editor.getSelectedBufferRange(),
    '\n' + indent
  )
}
<commit_msg>Added defn-, deftest, deftest- to oneIndentForms<commit_after>'use babel'

const oneIndentForms = ['fn', 'def', 'defn', 'ns', 'let', 'for', 'loop',
  'when', 'when-let', 'if', 'if-let', 'if-not', 'when-not', 'cond', 'do',
  'doseq', 'dotimes', 'defn-', 'deftest', 'deftest-'
]

function calculateIndent ({row, column}, content) {
  let x = 0
  let y = 0
  let openBrackets = []

  while (true) {
    const char = content[y][x]

    if (char === '(') {
      const first = content[y].slice(x + 1).split(' ')[0]

      openBrackets.push(
        oneIndentForms.includes(first)
          ? (x + 2)
          : (x + first.length + 2)
        )
    }
    if (char === '[' || char === '{') openBrackets.push(x + 1)
    if (char === ')' || char === ']' || char === '}') openBrackets.pop()

    x++
    if (x >= content[y].length) {
      x = 0
      y++
      if (y >= content.length) {
        break
      }
    }
  }

  return openBrackets.length
    ? ' '.repeat(openBrackets[openBrackets.length - 1])
    : ''
}

export function insertNewLine () {
  const editor = atom.workspace.getActiveTextEditor()
  const {row, column} = editor.getCursorBufferPosition()
  const lines = editor.getTextInBufferRange([[0, 0], [row, column]])
    .split('\n')

  const indent = calculateIndent({row, column}, lines)

  editor.getBuffer().setTextInRange(
    editor.getSelectedBufferRange(),
    '\n' + indent
  )
}

{'fraction_non_alphanumeric': 0.19765309864319766, 'fraction_numerical': 0.008067473414008068, 'mean_word_length': 2.73187414500684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3585950', 'n_tokens_mistral': 1009, 'n_tokens_neox': 961, 'n_words': 216}