Skip to content

Commit

Permalink
debug magic: protection when running code in another cell; added show…
Browse files Browse the repository at this point in the history
… magic - puts data into pager area; removed debug info
  • Loading branch information
dsblank committed Sep 28, 2014
1 parent a85739b commit c491e80
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
6 changes: 1 addition & 5 deletions jupyter_kernel/magics/debug_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def cell_debug(self):
function breakpoint_q(line) {
var info = cell.code_mirror.lineInfo(line - 1);
return (info.gutterMarkers != null);
return (info && info.gutterMarkers != null);
}
var cell = IPython.notebook.get_selected_cell();
Expand Down Expand Up @@ -115,8 +115,6 @@ def cell_debug(self):
function handle_output(out){
var res = null;
var data = null;
console.log(out);
// if output is a print statement
if (out.msg_type == "stream") {
res = out.content.data;
document.getElementById("result_stream").innerText = res.toString() + document.getElementById("result_stream").innerText;
Expand All @@ -134,8 +132,6 @@ def cell_debug(self):
data = JSON.parse(str.substring(12, str.length - 1));
var speed = Number(document.getElementById("speed").value);
if (data) {
//console.log(data);
//console.log(breakpoint_q(data[0]));
var breakp = breakpoint_q(data[0]);
if (speed < 100 || !running || breakp) { // max_speed
highlight(cell, data);
Expand Down
29 changes: 29 additions & 0 deletions jupyter_kernel/magics/show_magic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Calico Development Team.
# Distributed under the terms of the Modified BSD License.
# http://calicoproject.org/

from jupyter_kernel import Magic, option
import os

class ShowMagic(Magic):

def cell_show(self):
"""
%%show - load cell contents into system pager
This cell magic will put the contents the cell into
the system pager.
Example:
%%show
This information will appear in the pager.
"""
self.kernel.payload = [{"data": {"text/plain": self.code},
"start_line_number": 0,
"source": "page"}]
self.evaluate = False

def register_magics(kernel):
kernel.register_magics(ShowMagic)

0 comments on commit c491e80

Please sign in to comment.