From 92361c93c2e192b4c060a0d5204d8c90e490d415 Mon Sep 17 00:00:00 2001 From: Andrew Gibiansky Date: Mon, 6 Jan 2014 13:26:32 -0500 Subject: [PATCH] fixing code mirror mode to ignore :! things --- build.sh | 7 ++++--- profile/static/custom/custom.js | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index daa6892a..b6570b1e 100755 --- a/build.sh +++ b/build.sh @@ -4,6 +4,10 @@ rm -f profile.tar tar -cvf profile.tar * cd .. cabal install --force-reinstalls || exit 1 + +# Remove my profile +rm -rf ~/.ipython/profile_haskell + cd ihaskell-display for dir in `ls` do @@ -11,6 +15,3 @@ do cabal install || exit 1 cd .. done - -# Remove my profile -rm -rf ~/.ipython/profile_haskell diff --git a/profile/static/custom/custom.js b/profile/static/custom/custom.js index 85ab5f38..65bb10b9 100644 --- a/profile/static/custom/custom.js +++ b/profile/static/custom/custom.js @@ -15,8 +15,22 @@ $([IPython.events]).on('app_initialized.NotebookApp', function(){ // add here logic that shoudl be run once per **page load** // like adding specific UI, or changing the default value // of codecell highlight. - + CodeMirror.requireMode('haskell', function(){ + // Create a multiplexing mode that uses Haskell highlighting by default but + // doesn't highlight command-line directives. + CodeMirror.defineMode("ihaskell", function(config) { + return CodeMirror.multiplexingMode( + CodeMirror.getMode(config, "haskell"), + { + open: /:(?=!)/, // Matches : followed by !, but doesn't consume ! + close: /^(?!!)/, // Matches start of line not followed by !, doesn't consume character + mode: CodeMirror.getMode(config, "text/plain"), + delimStyle: "delimit" + } + ); + }); + cells = IPython.notebook.get_cells(); for(var i in cells){ c = cells[i]; @@ -24,7 +38,7 @@ $([IPython.events]).on('app_initialized.NotebookApp', function(){ // Force the mode to be Haskell // This is necessary, otherwise sometimes highlighting just doesn't happen. // This may be an IPython bug. - c.code_mirror.setOption('mode', 'haskell'); + c.code_mirror.setOption('mode', 'ihaskell'); c.auto_highlight() }