disabling blinking

Background: Text editing in the IPython Notebook is provided by an excellent JavaScript-based CodeMirror text editor. This might be more detail than you want, but I'm a vision scientist so I hope you'll indulge me.

The cursor is meant to tell the user the current location.

The human visual system has a pre-cortical lag of roughly 50-90 ms (read more about P1).

That's how long it takes from something changing on the screen to cause an avalanche of photons to barrel towards your eyeball, be phototransduced and processed by several stages of cells in the retina, finally causing retinal ganglion cells to fire an action potential down their axons through the optic nerve, make its way to a processing relay station called the LGN, with those cells firing action potential down their axons, with those spikes finally ending up in the primary visual cortex.

By ~150 ms, our brains have processed the visual input enough to perform a non- trivial ammount of object recognition.

The default blink rate for CodeMirror is 530ms.

That's as slow as molasses in January!

Say that I've been distracted and looked away from the screen. When I look back at the scree, half of the time it will take 3 times longer for me to get the information that I want ("where's my cursor") than if that cursor was clearly visible at all times. Now it's not always that bad, because sometimes my gaze will land on the screen and even though the cursor isn't visible, it appears in a few milliseconds, and so it takes just as long as if the cursor was there the whole time. But if I happen to be particularly unlucky (there's a reason I don't gamble), it can take 6 times longer.

Try it out

Here's the bit of JavaScript code you need to disable blinking in CodeMirror.

CodeMirror.defaults.cursorBlinkRate=0

If you type that into the JavaScript console of your webbrowser, that setting will apply to all cells created in the current IPython Notebook. If you don't know how to open your browser's Javascript console, don't frett, just make a new cell with just the following lines in there, execute it, and make a new cell to see how you like it.

%%javascript
CodeMirror.defaults.cursorBlinkRate=0

Make the change stick

IPython has a notion of profiles to allow for different kinds of configurations. If this is news to you, you've probably just been using the default profile and not known it. In the shell, run the ipython profile create command to be sure (don't worry, if you alreay have a profile, this won't overwrite it). Now ipython locate profile will tell you the directory which contains all of the configuration for the default profile.

In [1]:
!ipython profile create

In [2]:
!ipython locate profile

/home/pi/.ipython/profile_default

In [3]:
x = !ipython locate profile

In [4]:
cd $x.s

/home/pi/.ipython/profile_default

In [5]:
ls

db/  history.sqlite  history.sqlite-journal  ipython_config.py  ipython_nbconvert_config.py  ipython_notebook_config.py  log/  pid/  security/  startup/  static/

There's a lot of stuff there, but we just need to add our one line to the end of the file in static/custom/custom.js

In [6]:
cd static/custom/
/home/pi/.ipython/profile_default/static/custom

In [7]:
ls

custom.css  custom.js

In [8]:
!echo "codemirror.defaults.cursorblinkrate=0" >> custom.js

"I want it all and I want it now!"

You say you don't want to save your current notebook and reload it to get the updated CodeMirror settings? You just want all cells in the current notebook to change their behavior? Well, OK, Freddie:

In [9]:
%%javascript
var rate = 0;
// apply setting to  all current CodeMirror instances
IPython.notebook.get_cells().map(
    function(c) {  return c.code_mirror.options.cursorBlinkRate=rate;  }
);

// make sure new CodeMirror instance also use this setting
CodeMirror.defaults.cursorBlinkRate=rate;

I hope you enjoyed this little IPython customization detour. If you want more information about how to get rid of blinking in other programs you use every day, here is an invaluable resource on that matter.

Remember, blinking in user interfaces is bad, but blinking in vision is very important.

This post was written as an IPython Notebook. You can view it on nbviewer, or download it


Want to share this article?

Want to respond to directly? I'd love to hear from you.

Comments !

social