//  Copyright (C) 2013  The IPython Development Team
//
//  Distributed under the terms of the BSD License.  The full license is in
//  the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------

// add hotkey to comment/uncomment complete lines in codecells

$.getScript('/static/components/codemirror/addon/comment/comment.js')

(function (IPython) {
	
    var commentkey = { "Alt-C" : function(cm){toggleComments(cm)}};

	function toggleComments(cm) { 
		var from = cm.getCursor("start"), to = cm.getCursor("end");
		cm.uncomment(from, to, {'lineComment': '#'}) || cm.lineComment(from, to, {'lineComment': '#'});
	};

    /* http://stackoverflow.com/questions/2454295/javascript-concatenate-properties-from-multiple-objects-associative-array */
    function collect() {
        var ret = {};
        var len = arguments.length;
        for (var i=0; i<len; i++) {
            for (p in arguments[i]) {
                if (arguments[i].hasOwnProperty(p)) {
                    ret[p] = arguments[i][p];
                }
            }
        }
        return ret;
    }
	
    /**
     * Register new extraKeys to codemirror for newly created cell
     *
     * @param {Object} event
     * @param {Object} nbcell notebook cell
     */
    create_cell = function (event,nbcell,nbindex) {
        var cell = nbcell.cell;
        if (cell.cell_type == "code") {
            var keys = cell.code_mirror.getOption('extraKeys');
            cell.code_mirror.setOption('extraKeys', collect(keys, commentkey ));  
        }
    };

    $([IPython.events]).on('create.Cell',create_cell);
    console.log("Comment-uncomment extension loaded correctly");
}(IPython));


@@ -327,16 +327,32 @@
 odecells
+%0A%22using strict%22;
 %0A%0A$.getS
@@ -419,37 +419,75 @@
 s')%0A
-%0A(function (IPython) %7B%0A%09%0A    
+IPython.hotkeys%5B%22Alt-C%22%5D = %22comment/uncomment%3Cbr%3Eselected lines%22;%0A%0A
 var 
@@ -547,17 +547,16 @@
 cm)%7D%7D;%0A%0A
-%09
 function
@@ -578,18 +578,20 @@
 (cm) %7B %0A
-%09%09
+    
 var from
@@ -646,10 +646,12 @@
 %22);%0A
-%09%09
+    
 cm.u
@@ -746,17 +746,12 @@
 %7D);%0A
-%09
 %7D;%0A%0A
-    
 /* h
@@ -869,20 +869,16 @@
 rray */%0A
-    
 function
@@ -886,28 +886,24 @@
 collect() %7B%0A
-    
     var ret 
@@ -908,28 +908,24 @@
 t = %7B%7D;%0A    
- 
-   
 var len = ar
@@ -940,28 +940,24 @@
 length;%0A    
-   
- 
 for (var i=0
@@ -980,20 +980,16 @@
         
-    
 for (p i
@@ -1014,28 +1014,24 @@
             
-  
-  
 if (argument
@@ -1072,20 +1072,16 @@
         
-    
 ret%5Bp%5D =
@@ -1106,34 +1106,26 @@
             
- 
-   %7D%0A    
+%7D%0A
         %7D%0A  
@@ -1126,30 +1126,22 @@
   %7D%0A    
-    %7D%0A  
+%7D%0A
     
-  
 return r
@@ -1148,28 +1148,15 @@
 et;%0A
-    %7D%0A%09%0A    
+%7D%0A%0A
 /**%0A
-    
  * R
@@ -1219,18 +1219,10 @@
 ll%0A 
-    *%0A    
+*%0A
  * @
@@ -1242,20 +1242,16 @@
 %7D event%0A
-    
  * @para
@@ -1287,19 +1287,11 @@
 ll%0A 
-    */%0A    
+*/%0A
 crea
@@ -1330,28 +1330,24 @@
 ,nbindex) %7B%0A
-    
     var cell
@@ -1362,28 +1362,24 @@
 l.cell;%0A    
-  
-  
 if (cell.cel
@@ -1394,24 +1394,21 @@
 = %22code%22
+ 
 ) %7B%0A
-    
         
@@ -1467,20 +1467,16 @@
         
-    
 cell.cod
@@ -1546,26 +1546,14 @@
     
-  
-  %7D%0A    %7D;%0A%0A    
+%7D%0A%7D;%0A%0A
 $(%5BI
@@ -1599,20 +1599,16 @@
 _cell);%0A
-    
 console.
@@ -1663,19 +1663,6 @@
 y%22);
-%0A%7D(IPython));
 %0A%0A

Add hotkey info for help_panel