<commit_before>PythonDebuggerView = require './python-debugger-view'

module.exports =
  pythonDebuggerView: null

  activate: ->
    atom.workspaceView.command "python-debugger:insert", => @insert()
    atom.workspaceView.command "python-debugger:remove", => @remove()

  insert: ->
    IMPORT_STATEMENT = "import ipdb\n"
    editor = atom.workspace.activePaneItem
    cursors = editor.getCursors()
    saved_positions = []

    for cursor in cursors
      cursor.moveToFirstCharacterOfLine()
      saved_positions.push cursor.getBufferPosition()

    editor.insertText(
      "ipdb.set_trace()  ######### Break Point ###########\n",
      options={
        "autoIndentNewline": true
        "autoIndent": true
      }
    )

    editor.moveCursorToTop()
    editor.moveCursorToBeginningOfLine()
    editor.selectToEndOfLine()
    line = editor.getSelectedText()
    if not line.startsWith "from __future__"
      console.log "First import is not from __future__"
      if not IMPORT_STATEMENT.startsWith line
        editor.moveCursorToBeginningOfLine()
        editor.insertText(IMPORT_STATEMENT)

    else
      console.log "First import is from __future__"
      editor.moveCursorToBeginningOfLine()
      editor.moveCursorDown()
      editor.selectToEndOfLine()
      line = editor.getSelectedText()
      if not IMPORT_STATEMENT.startsWith line
        editor.moveCursorToBeginningOfLine()
        editor.insertText(IMPORT_STATEMENT)

    for cursor, index in cursors<commit_msg>Import statement is now added on the first line following 'from __future__' imports and comments, even when empty lines are used<commit_after>PythonDebuggerView = require './python-debugger-view'

module.exports =
  pythonDebuggerView: null

  activate: ->
    atom.workspaceView.command "python-debugger:insert", => @insert()
    atom.workspaceView.command "python-debugger:remove", => @remove()

  insert: ->
    IMPORT_STATEMENT = "import ipdb\n"
    editor = atom.workspace.activePaneItem
    cursors = editor.getCursors()
    saved_positions = []

    for cursor in cursors
      cursor.moveToFirstCharacterOfLine()
      saved_positions.push cursor.getBufferPosition()

    editor.insertText(
      "ipdb.set_trace()  ######### Break Point ###########\n",
      options={
        "autoIndentNewline": true
        "autoIndent": true
      }
    )

    editor.moveCursorToTop()
    insert_position = editor.getCursorBufferPosition()
    editor.moveCursorToBeginningOfLine()
    editor.selectToEndOfLine()
    line = editor.getSelectedText()

    # skip comments (and Python headers), "from __future__" imports and empty lines
    while (line.startsWith "#") or (line.startsWith "from __future__") or (not line)
      editor.moveCursorToBeginningOfLine()
      editor.moveCursorDown()
      editor.selectToEndOfLine()
      if line
        insert_position = editor.getCursorBufferPosition()
      line = editor.getSelectedText()

    editor.setCursorBufferPosition(insert_position)

    if not (IMPORT_STATEMENT.startsWith line)
      editor.moveCursorToBeginningOfLine()
      editor.insertText(IMPORT_STATEMENT)

    for cursor, index in cursors
{'fraction_non_alphanumeric': 0.10360216767612368, 'fraction_numerical': 0.0, 'mean_word_length': 3.4828571428571427, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, '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': '6508887', 'n_tokens_mistral': 918, 'n_tokens_neox': 903, 'n_words': 191}