Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off auto-closing parentheses in ipython

I stay up-to-date with ipython's dev branch (because ipython is pretty much the most awesome thing ever). Fairly recently (before yesterday's awesome ipython 2.0 release) I noticed that it has started to automatically close parentheses, brackets, quotes, etc., as I type them. It happens in both terminal [nothing else I use in terminal does it] and notebook sessions, so I assume it was an intentional choice on the part of the developers. I can respect that other people might like this feature, but it drives me completely nuts.

I can't find any option for it in the configuration files. I can't even google for it, because I don't know what it's called. The only thing that comes up is the different feature of automatic parentheses. I did actually find this question, but that's old, and suggests that the behavior I'm seeing can't happen.

How can I turn this feature off?

[I mostly just use the notebook interface anyway, so just turning it off there would be fine, but I'd prefer to turn it off in both notebooks and ipython sessions at the terminal.]

like image 257
Mike Avatar asked Apr 03 '14 16:04

Mike


People also ask

How do I turn off autocomplete in Jupyter notebook?

Tools>Options>IDE Options: Uncheck complete as you type.

How do I stop a Jupyter notebook from running shortcuts?

To stop running a piece of code, press the stop button. To create new cells, use the plus (+) button in the toolbar or hit SHIFT+ENTER on the last cell in the Notebook.


2 Answers

@minrk's answer is the meat and bones of the fix, but you'll need to wrap it in an initialization callback, at least with IPython-3.1.0. In your custom.js:

require(['base/js/namespace', 'base/js/events'], function(IPython, events) {
  events.on('app_initialized.NotebookApp', function() {
    IPython.CodeCell.options_default.cm_config.autoCloseBrackets = false;
  });
});

Thanks @Mike for your comment about IPython's RequireJS dependency loading and the pointer to a better formulation at IPython/Jupyter Installing Extensions.

Edit for Jupyter 4.0.x:

The current IPython notebook implementation, Jupyter 4.0.0, revamped JS customizations. It now uses ~/.jupyter/custom/custom.js by default, and you'll need to replace that whole require(... events.on(...)) snippet with just the following in global scope:

IPython.CodeCell.options_default.cm_config.autoCloseBrackets = false;

Likewise, if you want to use jQuery to manipulate anything, just use the jQuery global directly. For example, I like to hide the fixed header by default, which gives me another 40px of space for my code, which I find a bit more valuable than looking at the Jupyter logo all the time:

jQuery('#header-container').hide();

Edit for Jupyter ≥ 4.0.6 (but < Jupyter Lab):

If the custom.js solution above doesn't work, try adding the following to your ~/.jupyter/nbconfig/notebook.json:

{
  "CodeCell": {
    "cm_config": {
      "autoCloseBrackets": false
    }
  }
}
like image 55
chbrown Avatar answered Oct 11 '22 14:10

chbrown


The notebook behavior is the result of the CodeMirror autoCloseBrackets plugin. You can turn this off by editing (create it with ipython profile create if you haven't already) ~/.ipython/profile_default/static/custom/custom.js and adding:

if (IPython.CodeCell) {
  IPython.CodeCell.options_default.cm_config.autoCloseBrackets = false;
}

As for the terminal, I don't see the parenthesis behavior you describe. Do you perhaps have a PYTHONSTARTUP defined? IPython executes this file by default, which you can disable by adding to ~/.ipython/profile_default/ipython_config.py:

c.InteractiveShellApp.exec_PYTHONSTARTUP = False
like image 24
minrk Avatar answered Oct 11 '22 14:10

minrk