<commit_before>CodeMirror = require 'codemirror'
keymap = require './keymap'
module.exports = (cm, requestAutocompletion) -> # set up autocompletion, common code between session and editor
  tid = null # timeout id
  cm.on 'change', ->
    clearTimeout tid
    tid = setTimeout(
      ->
        tid = null; c = cm.getCursor(); s = cm.getLine c.line; i = c.ch
        if s[i - 1] !in [' ', keymap.getPrefixKey()] then requestAutocompletion s, i
        return
      500
    )
    return
  (skip, options) ->
    if options.length
      c = cm.getCursor(); from = line: c.line, ch: c.ch - skip; sel = ''
      cm.showHint
        completeOnSingleClick: true
        completeSingle: false
        extraKeys:
          Enter:       (cm, m) -> (if sel then m.pick() else cm.execCommand 'ER'); return
          Right:       (cm, m) -> (if !sel then m.moveFocus 1); m.pick(); return
          Tab:         (cm, m) -> m.moveFocus 1; return
          'Shift-Tab': (cm, m) -> m.moveFocus -1; return
        hint: ->
          to = cm.getCursor(); u = cm.getLine(from.line)[from.ch...to.ch].toLowerCase() # u: completion prefix<commit_msg>prevented autocompletion in the beginning of a line<commit_after>CodeMirror = require 'codemirror'
keymap = require './keymap'
module.exports = (cm, requestAutocompletion) -> # set up autocompletion, common code between session and editor
  tid = null # timeout id
  cm.on 'change', ->
    clearTimeout tid
    tid = setTimeout(
      ->
        tid = null; c = cm.getCursor(); s = cm.getLine c.line; i = c.ch
        if i && s[i - 1] !in [' ', keymap.getPrefixKey()] then requestAutocompletion s, i
        return
      500
    )
    return
  (skip, options) ->
    if options.length
      c = cm.getCursor(); from = line: c.line, ch: c.ch - skip; sel = ''
      cm.showHint
        completeOnSingleClick: true
        completeSingle: false
        extraKeys:
          Enter:       (cm, m) -> (if sel then m.pick() else cm.execCommand 'ER'); return
          Right:       (cm, m) -> (if !sel then m.moveFocus 1); m.pick(); return
          Tab:         (cm, m) -> m.moveFocus 1; return
          'Shift-Tab': (cm, m) -> m.moveFocus -1; return
        hint: ->
          to = cm.getCursor(); u = cm.getLine(from.line)[from.ch...to.ch].toLowerCase() # u: completion prefix
{'fraction_non_alphanumeric': 0.13993915688830944, 'fraction_numerical': 0.006084311169056932, 'mean_word_length': 2.1707988980716255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4795316', 'n_tokens_mistral': 739, 'n_tokens_neox': 734, 'n_words': 225}