[IPython-User] Swap enter and shift-enter in notebook?

Michael McNeil Forbes michael.forbes+ipython@gmail....
Sun Aug 5 18:03:07 CDT 2012


On 2 Aug 2012, at 5:23 PM, Michael McNeil Forbes wrote:
<some code and instructions to swap enter and shift-enter (included  
below)>

Hi everyone. Please don't take my "solution" seriously.  I Tricked  
myself
into thinking it worked, but it has some problems:

1) You need to modify files in your ~/.ipython directory on the server  
machine.
    (You do not need to modify the server, but I don't yet see how to  
inject js
     code from the client... but I virtually no js experience so maybe  
there is a
     way).
2) My solution of negating the shift flag is not a complete solution:  
in particular
    after swapping, pressing "enter" will indeed execute the block,  
but it will also
    insert a newline (I don't know how to suppress that yet).

I probably need to do the swap earlier (in cellmirror maybe?) but in  
any case, this
needs more work... Suggestions welcome:-)  I will drop a note if I  
make progress
and/or a Pull Request when I get a chance to delve deep into javascript
(won't happen in the near future though).

Thanks for the suggestions.  With some tweaks, I think notebook will  
be a
killer addition to the python arsenal. (I have yet to play with the  
parallel
features but am very excited.)

Michael.

> Le 3 août 2012 à 02:23, Michael McNeil Forbes a écrit :
>
>> On 2 Aug 2012, at 12:39 AM, Matthias Bussonnier wrote:
>>> Sorry for the brievty, answer from my phone.
>>>
>>> If you use 0.14 dev. you can overwrite ipython file without touching
>>> the server.
>>> Just add them into .ipython/profile/profile_xxx/
>>>
>>
>> This seems to work fine:
>> 1) Install IPython 0.14-dev from github on server.
>> 2) Copy notebook.js and codecell.js to ~/.ipython/profile/ 
>> profile_xxx/
>> static/js/ from
>>   https://raw.github.com/ipython/ipython/master/IPython/
>>   Note: this profile name must match the name of the profile on the
>> server. This is a
>>   little strange in terms of UI since the name of this profile is
>> not even visible
>
> usually you start your notebook with --profile=whatever
> if you don't say anything it will use…default
>
>
>>   from the web interface, but probably makes sense from a dev.
>> perspective to localize
>>   the effects.
>> 3) Swap the shift-flag near as follows
>>
>>        if (event.which == key.ENTER) {
>>            // MMF Customization: swap enter and shift-enter
>>            event.shiftKey = !event.shiftKey;
>>        }
>>
>>    Do this near the start of the following function in codecell.js
>>
>>       CodeCell.prototype.handle_codemirror_keyevent = function
>> (editor, event) {
>>
>>    and near the start of the following block in notebook.js
>>
>>       $(document).keydown(function (event) {
>>
>> While I am at it I might add a sequence for joining two adjacent
>> blocks.  Is there
>> a function that will do this simply?
>
> IPython.notebook.merge_cell_above();
> IPython.notebook.merge_cell_below();
>
> is IMHO what you want.
Thanks.  Will try.

> if you ever want to refactor the javascript and
> make something that allows to easily configure the keybindings (dict  
> of {key:function}) for example
> we love Pull requests.

This will require some javascript retooling on my part, so won't  
happen in the near future, but when
I have some time, I will attempt this.  I love github's code review  
feature for PR's which is a
strong motivation to contribute:-)



More information about the IPython-User mailing list