Skip to content

Commit

Permalink
Merge pull request #2190 from Carreau/update_code_mirror
Browse files Browse the repository at this point in the history
Update code mirror 2.22 to 2.32

Update codemirror to the latest stable.
And upadte our code here and there to smooth the changes. 
Just the fact that there is a new tab system that was inserting tabs instead of 4 space, we just have to pass a new line when creating e new CM instance.

Should also fix #1464.

See Readme-IPython to see what patch to apply when updating next.
  • Loading branch information
Carreau committed Jul 28, 2012
2 parents 6c82a45 + d7fc63a commit 43a8117
Show file tree
Hide file tree
Showing 162 changed files with 18,314 additions and 584 deletions.
2 changes: 1 addition & 1 deletion IPython/frontend/html/notebook/static/codemirror/LICENSE 100755 → 100644
@@ -1,4 +1,4 @@
Copyright (C) 2011 by Marijn Haverbeke <marijnh@gmail.com>
Copyright (C) 2012 by Marijn Haverbeke <marijnh@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
98 changes: 83 additions & 15 deletions IPython/frontend/html/notebook/static/codemirror/README-IPython.rst
Expand Up @@ -5,29 +5,97 @@
We carry a mostly unmodified copy of CodeMirror. The current version we use
is (*please update this information when updating versions*)::

CodeMirror c813c94
CodeMirror2 4e244d252a26a2dba5446d44eb46adfb3c7f356a , tag : v2.32

The current politics is not to ships the following folders of CodeMirrors :

* doc/
* demo/
* test/


The only changes we've applied so far are these::

diff --git a/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js
index ca94e7a..fc9a503 100644
git show 271e17dd21f4f0c802a573b412e430998a70a78c

commit 271e17dd21f4f0c802a573b412e430998a70a78c
Author: Matthias BUSSONNIER <bussonniermatthias@gmail.com>
Date: Mon Jul 23 14:53:21 2012 +0200

patch SingleOperator in CodeMirror2

diff --git a/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js b/IPython/frontend/html/notebook/static/code
index d6888e8..201da51 100644
--- a/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js
+++ b/IPython/frontend/html/notebook/static/codemirror/mode/python/python.js
@@ -5,7 +5,11 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
}

@@ -4,8 +4,11 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
function wordRegexp(words) {
return new RegExp("^((" + words.join(")|(") + "))\\b");
}
-
- var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
+
+ // IPython-specific changes: add '?' as recognized character.
+ //var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]");
+ var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\\?]");
+ // End IPython changes.
+
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");

+
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))");
var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");

In practice it's just a one-line change, adding `\\?` to singleOperators,
surrounded by a comment. We'll turn this into a proper patchset if it ever
gets more complicated than this, but for now this note should be enough.
surrounded by a comment.

Then don't forget to reintroduce ipython.css

git show 39a602468ee1ca8fdb660826d6185e0f9a026fdf --stat
commit 39a602468ee1ca8fdb660826d6185e0f9a026fdf
Author: Matthias BUSSONNIER <bussonniermatthias@gmail.com>
Date: Mon Jul 23 14:47:08 2012 +0200

reintroduce ipython.css

IPython/frontend/html/notebook/static/codemirror/theme/ipython.css | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)

and

git show head^
commit 331a5f7fe85a6e894c35b64cd7987ed53f59ea57
Author: Matthias BUSSONNIER <bussonniermatthias@gmail.com>
Date: Wed Jul 25 12:41:13 2012 +0200

patch deletion in codemirror

diff --git a/IPython/frontend/html/notebook/static/codemirror/lib/codemirror.js b/IPython/frontend/html/notebook/static/codemirror/lib/codemirror.js
index 89401a9..a9dfdfe 100644
--- a/IPython/frontend/html/notebook/static/codemirror/lib/codemirror.js
+++ b/IPython/frontend/html/notebook/static/codemirror/lib/codemirror.js
@@ -2194,6 +2194,20 @@ var CodeMirror = (function() {
cm.indentLine(cm.getCursor().line);
},
toggleOverwrite: function(cm) {cm.toggleOverwrite();}
+ ,delSpaceToPrevTabStop : function(cm){
+ var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
+ if (!posEq(from, to)) {cm.replaceRange("", from, to); return}
+ var cur = cm.getCursor(), line = cm.getLine(cur.line);
+ var tabsize = cm.getOption('tabSize');
+ var chToPrevTabStop = cur.ch-(Math.ceil(cur.ch/tabsize)-1)*tabsize;
+ var from = {ch:cur.ch-chToPrevTabStop,line:cur.line}
+ var select = cm.getRange(from,cur)
+ if( select.match(/^\ +$/) != null){
+ cm.replaceRange("",from,cur)
+ } else {
+ cm.deleteH(-1,"char")
+ }
+ }
};

var keyMap = CodeMirror.keyMap = {};

that you should be able to apply after updating codemirror with

git cherry-pick 271e17 39a602 331a5f

We'll turn this into a proper patchset if it ever gets more complicated than
this, but for now this note should be enough.
10 changes: 6 additions & 4 deletions IPython/frontend/html/notebook/static/codemirror/README.md 100755 → 100644
@@ -1,6 +1,8 @@
# CodeMirror 2

CodeMirror 2 is a rewrite of [CodeMirror
1](http://github.com/marijnh/CodeMirror). The docs live
[here](http://codemirror.net/doc/manual.html), and the project page is
[http://codemirror.net/](http://codemirror.net/).
CodeMirror is a JavaScript component that provides a code editor in
the browser. When a mode is available for the language you are coding
in, it will color your code, and optionally help with indentation.

The project page is http://codemirror.net
The manual is at http://codemirror.net/doc/manual.html

0 comments on commit 43a8117

Please sign in to comment.