From 5ea47853acfb811ad72439b4fe2fbd0527c91a08 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 1 Feb 2018 14:55:09 +0000 Subject: [PATCH] jupyter --- C/text.c | 2 +- packages/python/yap_kernel/kernel.js | 39 ++++++++++++------- .../yap_kernel/yap_ipython/prolog/jupyter.yap | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/C/text.c b/C/text.c index 3044212a2..7e38f1fc7 100644 --- a/C/text.c +++ b/C/text.c @@ -845,7 +845,7 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) { // cnt++; int l = push_text_stack(); buf = Yap_readText(inp PASS_REGS); - if (!buf) { + if (!buf || buf[0] == '\0') { pop_text_stack(l); return 0L; } diff --git a/packages/python/yap_kernel/kernel.js b/packages/python/yap_kernel/kernel.js index da9b12d94..a30cc1527 100644 --- a/packages/python/yap_kernel/kernel.js +++ b/packages/python/yap_kernel/kernel.js @@ -1,18 +1,27 @@ +requirejs.config({ + map: { + '*' : { + 'codemirror/mode/prolog/prolog':'/kernelspecs/yap_kernel/prolog.js' + + } + } +}); define([ - "/kernelspecs/yap_kernel/prolog.js"],function(CodeMirror){ + 'codemirror/lib/codemirror', + 'base/js/namespace', + 'base/js/events', +],function(Jupyter,events,CodeMirror){ + var onload = function(){ + var mode = { + mime: "text/x-prolog", + name: "Prolog", + mode: "prolog", + ext: ["pl", "yap", "yss", "P"] + }; + //console.log("I am being loaded"); + CodeMirror.requireMode("prolog", mode); + CodeMirror.setOption("mode",mode); - var onload = function(){ - console.log("I am being loaded"); - var cell = Jupyter.notebook.get_selected_cell(); - var cm = cell.config; - var patch = { - CodeCell:{ - cm_config:{mode: "prolog"} // only change here. - } - }; - config.update(patch); - return {onload:onload}; - } - } - ); + return {onload:onload}; +}}); diff --git a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap index bce258b0e..f4bf4f709 100644 --- a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap +++ b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap @@ -61,7 +61,7 @@ blankc('\n'). blankc('\t'). enter_cell(_Self) :- - %open('//python/sys.stdin', read, _Input, []), + open('//python/input', read, _Input, []), open('//python/sys.stdout', append, _Output, []), open('//python/sys.stdout', append, _Error, []), %set_prolog_flag(user_input, _Input),