                 @markerBubbleMap[marker.id].destroy()
                 delete @markerBubbleMap[marker.id]
 
-    run: (andMoveDown = false, runAll = false, runAllAbove = false) ->
-        editor = atom.workspace.getActiveTextEditor()
-        grammar = editor.getGrammar()
-        language = grammar.name.toLowerCase()
-
-        if language? and KernelManager.languageHasKernel(language)
-            @startKernelIfNeeded language, (kernel) =>
-                if @watchSidebar? and
-                        @watchSidebar.element.contains(document.activeElement)
-                    @watchSidebar.run()
-                else
-                    statusView = kernel.statusView
-                    @setStatusBarElement(statusView.getElement())
-                    if not @watchSidebar?
-                        @setWatchSidebar(kernel.watchSidebar)
-
-                    # if not @watchSidebar?
-                        # @watchSidebar = new WatchSidebar(kernel, grammar)
-                    # @showWatchSidebar()
-
-                    @createResultBubble(andMoveDown, runAll, runAllAbove)
-        else
-            atom.notifications.addError(
-                "No kernel for language `#{language}` found",
-                {
-                    detail: "Check that the language for this file is set in Atom
-                             and that you have a Jupyter kernel installed for it."
-                })
+
+    moveDown: (row) ->
+        lastRow = @editor.getLastBufferRow()
+
+        if row >= lastRow
+            @editor.moveToBottom()
+            @editor.insertNewline()
+            return
+
+        while row < lastRow
+            row++
+            break if not @blank(row)
+
+        @editor.setCursorBufferPosition
+            row: row
+            column: 0
+
+
+    run: () ->
+        codeBlock = @findCodeBlock()
+        unless codeBlock?
+            return
+
+        [code, row] = codeBlock
+        if code? and row?
+            @createResultBubble code, row
+
+
+    runAll: () ->
+        code = @editor.getText()
+        row = @editor.getLastBufferRow()
+        codeBlock = [code, row]
+        @createResultBubble code, row
+
+
+    runAllAbove: () ->
+        codeBlock = @findCodeBlock(true)
+        unless codeBlock?
+            return
+
+        [code, row] = codeBlock
+        if code? and row?
+            @createResultBubble code, row
+
+
+    runAndMoveDown: () ->
+        codeBlock = @findCodeBlock()
+        unless codeBlock?
+            return
+
+        [code, row] = codeBlock
+        if code? and row?
+            @createResultBubble code, row
+            @moveDown row
+
 
     removeStatusBarElement: ->
         if @statusBarElement?

            if onStarted?
                onStarted(runningKernel)

    findCodeBlock: (runAll = false, runAllAbove = false) ->
        if runAll
            return [@editor.getText(), @editor.getLastBufferRow()]

        buffer = @editor.getBuffer()
        selectedText = @editor.getSelectedText()


        @subscriptions = new CompositeDisposable

        @subscriptions.add atom.commands.add 'atom-text-editor',
            'hydrogen:run': => @run()
            'hydrogen:run-all': => @runAll()
            'hydrogen:run-all-above': => @runAllAbove()
            'hydrogen:run-and-move-down': => @runAndMoveDown()
            'hydrogen:show-kernel-commands': => @showKernelCommands()
            'hydrogen:toggle-watches': => @toggleWatchSidebar()
            'hydrogen:select-watch-kernel': => @showWatchLanguagePicker()
