atom-packages/wizard/lib/wizard.js
// we call convert() to convert some text we may or may not have highlighted
we call convert() to convert some text we may or may not have highlighted
we call convert () to convert some text we may or may not have highlighted
convert() {
    const editor = atom.workspace.getActiveTextEditor()
    if (editor) {
      const selection = editor.getSelectedText()
      if (editor.getTitle().endsWith(".py")) {
        if (selection.length == 0) {
          editor.insertText("print(\"\")");
          editor.moveLeft(2)
        } else {
          if (selection.indexOf("(") !== -1) {
            var start = selection.substring(0, selection.indexOf("(")+1);
            var middle = selection.substring(selection.indexOf("(")+1, selection.indexOf(")"));
            var end = selection.substring(selection.indexOf(")")+1);
            editor.insertText("print(\"" + start + "\"+str(" + middle + ")" + end +"+\") = \" + " + "str(" + selection + ")))");
            editor.backspace();
          } else {
            editor.backspace();
            editor.insertText("print(\"" + selection + " = \" + " + "str(" + selection + "))");
          }
        }
      }
      else if (editor.getTitle().endsWith(".java")) {
        if (selection.length == 0) {
          editor.insertText("System.out.println(\"\")");
          editor.moveLeft(2)
        } else {
          editor.backspace();
          editor.insertText("System.out.println(\"" + selection + " = \" + " + selection + ")");
        }
      }
      else if (editor.getTitle().endsWith(".c")) {
        if (selection.length == 0) {
          editor.insertText("printf(\"%s\\n\", );");
          editor.moveLeft(9)
        } else {
          editor.backspace();
          editor.insertText("printf(\""+selection+" = %s\\n\", " + selection + ");");
        }
      }
    }
  }
convert ( ) { const editor = atom . workspace . getActiveTextEditor ( ) if ( editor ) { const selection = editor . getSelectedText ( ) if ( editor . getTitle ( ) . endsWith ( ".py" ) ) { if ( selection . length == 0 ) { editor . insertText ( "print(\"\")" ) ; editor . moveLeft ( 2 ) } else { if ( selection . indexOf ( "(" ) !== - 1 ) { var start = selection . substring ( 0 , selection . indexOf ( "(" ) + 1 ) ; var middle = selection . substring ( selection . indexOf ( "(" ) + 1 , selection . indexOf ( ")" ) ) ; var end = selection . substring ( selection . indexOf ( ")" ) + 1 ) ; editor . insertText ( "print(\"" + start + "\"+str(" + middle + ")" + end + "+\") = \" + " + "str(" + selection + ")))" ) ; editor . backspace ( ) ; } else { editor . backspace ( ) ; editor . insertText ( "print(\"" + selection + " = \" + " + "str(" + selection + "))" ) ; } } } else if ( editor . getTitle ( ) . endsWith ( ".java" ) ) { if ( selection . length == 0 ) { editor . insertText ( "System.out.println(\"\")" ) ; editor . moveLeft ( 2 ) } else { editor . backspace ( ) ; editor . insertText ( "System.out.println(\"" + selection + " = \" + " + selection + ")" ) ; } } else if ( editor . getTitle ( ) . endsWith ( ".c" ) ) { if ( selection . length == 0 ) { editor . insertText ( "printf(\"%s\\n\", );" ) ; editor . moveLeft ( 9 ) } else { editor . backspace ( ) ; editor . insertText ( "printf(\"" + selection + " = %s\\n\", " + selection + ");" ) ; } } } }
we call convert() to convert some text we may or may not have highlighted
we call convert () to convert some text we may or may not have highlighted
// get editor // check if editor is not null // get selected text // PYTHON // Print statement // turn f(x) into print("f("+str(x)+") = " + str(f(x))) // JAVA // Print statement // do nothing // C // Print statement // do nothing