New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
History navigation in notebook #2203
Conversation
Can you check to confirm that these keyboard shortcuts are not used on On Wed, Jul 25, 2012 at 11:16 AM, v923z
Brian E. Granger |
I could check firefox and chrome on linux, and they both seem to do what I expect. As far as I remember, shift+pageup, and shift+pagedown are used somewhere, but I don't know where. |
Checking to make sure they do as you expect is not enough in this On Wed, Jul 25, 2012 at 11:37 AM, v923z
Brian E. Granger |
Shouldn't this be using history_request, rather than getting it from the cells? That would allow it to use the real IPython history, and retrieve inputs from other sessions, and deleted cells. |
@minrk I see your point, but it could become really confusing. Basically, you would not have an idea as to which line is going to come up until you actually see it. Also, what about cells that do not concern the kernel, like headings, markdowns and so on? |
Shift & arrow keys are used to select text with the keyboard. I'm not sure whether I'd expect it to go through notebook cells or execution history. I'll have to think more about that. |
@ellisonbg chrome seems to be OK http://www.shortcutworld.com/en/linux/Chrome.html, and the same applies to firefox http://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly. Safari is probably also OK, but I can't check that http://www.shortcutworld.com/en/mac/Safari_5.html |
My main reasoning is selfish: I have many times wanted to get code from my IPython history, but I have not had any need for getting code from one cell to another to be better than conventional copy/paste. You bring up a good point about multiple cell types - this shouldn't get cross-type content (no markdown in a code cell, etc.), so if we do it this way, it should skip over cells not of matching type. @takluyver brings up a good point - shift-arrow is used for selecting text, so it must not be used here. |
@takluyver That is true, if there is text in the direction of the arrow, i.e., if you are on the first line of a multiline cell, and press Shfit+down. But if you are on the last line, then nothing is going to be selected. |
Then would you rather test against the edges of the text area, or use a different shortcut? What if a user is selecting the body of the cell with shift-down, and hit it one too many times that would go off the edge? It would be pretty unpleasant if this not only cleared the selection, but replaced the content of the cell. |
I think we need to steer clear of keyboard shortcuts that are already On Wed, Jul 25, 2012 at 11:53 AM, Min RK
Brian E. Granger |
@minrk My main reasoning is selfish: I have many times wanted to get code from my IPython history, but I have not had any need for getting code from one cell to another to be better than conventional copy/paste. Again, I tossed up the idea, but I am not going to fight tooth and nail for the current implementation. I think your point is valid. ... You bring up a good point about multiple cell types - this shouldn't get cross-type content (no markdown in a code cell, etc.), so if we do it this way, it should skip over cells not of matching type. Right. That hasn't been implemented yet. ... @takluyver brings up a good point - shift-arrow is used for selecting text, so it must not be used here. I am not pressing for this particular shortcut. If we find another one, I am fine with it. |
Great, thanks! Finding safe shortcuts is increasingly difficult. |
@ellisonbg Then what about Cntr+Shift+UpArrow or Cntr+Alt+UpArrow? |
Honestly I am fine with any such shortcuts as long as they are 1) On Wed, Jul 25, 2012 at 11:59 AM, v923z
Brian E. Granger |
I did not try, but how is the history position reseted to 0 ?
boom, you are back to the first cell but with content of the selected one. as for This would make me angry, as I often do |
@minrk If you think that navigation of the kernel history is more useful, then I would like to suggest that in addition to the content, we print as a comment the input line number on the first line, so that the user has an idea where the line came from. That would also indicate where you are in the history. |
@Carreau There are actually two position indicators, one that checks the position in the history, and another one that should indicate whether you have moved from the cell. If I understand your concern correctly, this has already been taken care of. |
Cntr+Alt+Up pages through the desktops on gnome, so that we can't take. @Carreau says that Cntr+Shift+Up would not work. But I believe, Cntr+M Up is not taken yet, is it? |
I think ^M-UP is safe. |
Thanks! Then the second issue was whether we should take the kernel history, or the notebook history. You have already put down your vote, but others haven't yet chipped in. Should we wait for feedback on that? |
If well obviously not |
I think Ctrl+m,h,up is getting over complicated for the user. I'm leaning towards Min's position - it's already easy to copy&paste |
On 07/25/2012 10:36 PM, Thomas Kluyver wrote:
|
@minrk , @Carreau I was trying to go along the lines you suggested, but I can't catch the
and it seems that the up arrow is escaped somewhere else. Any comments on this? On a slightly different note, if |
did you try both |
On 07/26/2012 11:03 AM, Bussonnier Matthias wrote:
|
Sounds like the consensus is that we would rather have kernel-level history. @v923z do you think you will implement that in this PR, or should we close this one and open an issue for it? |
Hi Brian, I think I could implement it, but really the question is what we would On 08/10/2012 04:05 AM, Brian E. Granger wrote:
|
I have found 4 keys (Cntr+m Left, Cntr+m Right, Cntr+m PageDown, Cntr+m PageUp) that work without problems, so both versions of the history navigation could be implemented. However, I don't seem to be able to invoke history_request from the notebook. Shouldn't this return something:
I couldn't find any pieces of code that actually calls history_request, thus I am not quite sure whether this is the proper way of using this method. If someone could give me a pointer, I could quickly wrap up this PR. |
On Fri, Aug 10, 2012 at 12:51 PM, v923z notifications@github.com wrote:
It's perfectly possible that this is part of the protocol that we specified All to say that it may require a bit of extra work to get that part of the |
The Qt console does call history_request when it starts up, so the kernel |
The history request message type has not been implemented on the Javascript http://ipython.org/ipython-doc/dev/development/messaging.html#history And then implement things in kernel.js, looking at how we did execute. Cheers, Brian On Fri, Aug 10, 2012 at 12:51 PM, v923z notifications@github.com wrote:
Brian E. Granger |
There are two methods in kernel.js that already have the right logic: https://github.com/ipython/ipython/blob/master/IPython/frontend/html/notebook/static/js/kernel.js#L180 Along with our message dev docs, it should be pretty simply to implement the history request message. You will need to think carefully about what should happen if the request takes some time (the kernel could be busy with other work) or fails. |
Hi Brian,
Thanks for the pointers! I will take a stab at implementing the |
Just use the notification area, it is made (or will be) to alert users. |
I have tried to implement request_history in kernel.js, but there are a couple of hurdles that I can't make. Basically, this is what I have at the moment
and this will print the history on the console. However, I would like to return the history as a string, so that the insertion can be handled in notebook.js. How do I return the string? Also, while the code above worked for the cases I tried, I am not completely convinced that
is the best way to retrieve whatever is in the content. I have read http://ipython.org/ipython-doc/dev/development/messaging.html, but it is not clear to me how exactly I should treat whatever is returned by history_request. |
You probably want to specify 'output': false in the request, then the |
Good point, thanks! |
@v923z did you make any progress with this PR ? |
Hi Matthias, I haven't had too much time recently, but I have already realised that content.history[0][2][0] tooltip.js, where object_info_request is called, seem to work along the var msg_id = IPython.notebook.kernel.object_info_request(re.exec(func), callbacks); for after that the function ends, so that variable doesn't seem to be In any case, I would be willing to work on this, but I just don't know Cheers, On 09/28/2012 05:11 PM, Bussonnier Matthias wrote:
|
I dont have the code nearby but i would say it is a leftover from previous Here 'callback' should be the function that get the response as first i'll try to have a look.Matthias.
|
So I came up with that : Kernel.prototype.history_request = function (hist_line, callback) { //diff
// from http://ipython.org/ipython-doc/dev/development/messaging.html#history
var callbacks = {
// diff, do not handle response in kernel, but pass a function
// that will handle a reply as parameters
'history_reply': callback
}
var content = {
output : false,
raw : true,
hist_access_type : 'range',
'start' : 0,
'stop' : 100,
session: 0, // diff
};
var msg = this._get_msg("history_request", content);
this.shell_channel.send(JSON.stringify(msg));
this.set_callbacks_for_msg(msg.header.msg_id, callbacks);
return msg.content;
} Then in Cell.js Cell.prototype.hct = function (num){
var that=this; // could be made with $.proxy(function, this)
IPython.notebook.kernel.history_request(0,
function(arg){
that.code_mirror.setValue(
arg.history[num][2]
)
});
} from js console dooing
Set the content of cell This does not of course fail gracefully when history does not exist... etc etc. |
Just as a comment, I think the difficulties often came from the way of programming in Python vs JS.
wherease in js you would do
where in python you would go down the stack, and alway return where things have been called, Does it make sens ? |
and BTW, in
the |
Hi Matthias, Thanks for the comments! I will try to clean up the code over the weekend. On 09/28/2012 08:49 PM, Bussonnier Matthias wrote:
|
I would like to close this PR because of 2 months of inactivity. I have created an issue to track it: #2648. We would love to see this work continue, please feel free to reopen this PR once things get started again. Any objections to closing this? |
Actually, I meant to suggest that this should be closed for now. I am not sure I will have the time to clean this up soon, so just go ahead, and close it. I will open a PR, if I have something working. |
OK closing for now. |
Hi all,
As discussed somewhere on the mailing list (I can dig out the reference, if necessary), I implemented basic history navigation in the notebook. Shift+UpArrow or Shift+DownArrow copies the content of the previous, previous-previous, previous-previous-previous (you get the idea) cells into the current cell.
I would like to emphasize that this works on notebook cells, and not on the kernel history. My reason for this would be that first, this would work without the kernel, so one could use it when, e.g., updating documentation in the notebook, but not having access to the kernel, and second, it would be visually rather confusing, if the we were paging through the kernel history, for the kernel commands are not necessarily executed in the order given in the notebook.
Let me know, if there is interest in this feature, and what should be improved upon.
Cheers,
Zoltán