emacs-jupyter / jupyter

An interface to communicate with Jupyter kernels.
GNU General Public License v3.0
930 stars 92 forks source link

Feature request: command to send results from REPL to new buffer #152

Open non-Jedi opened 5 years ago

non-Jedi commented 5 years ago

Often I find myself wanting to do some formatting or just to have the results of a REPL command easily available to me for a longer time. It would be nice if there was a built-in facility to both evaluate the current REPL command and send results to a new buffer and pop the results of the last command to a new buffer.

nnicandro commented 5 years ago

In the REPL you can also evaluate code using C-c C-c. So you can select the region of code, press C-c C-c, and a results buffer will be displayed. You can then rename the buffer so that it sticks around longer. Is this basically what you are trying to accomplish with this feature?

I think what is missing is the ability to force the display of the result in a new buffer since pressing C-c C-c can potentially display the result in the minibuffer according to jupyter-eval-short-result-max-lines.

non-Jedi commented 5 years ago

So after messing around with C-c C-c in the repl buffer, a couple notes on why it doesn't quite work for my workflow:

  1. After C-c C-c, the command I evaluated is still there on an input line in the REPL buffer, so I have to manually delete it before I can do other things with the buffer.
  2. Since the buffers produced use special-mode as its major mode, I end up with q bound as quit-window which can be annoying. The buffers are also read-only when sometimes I want to do some post-processing. If the mode for jupyter output instead was a new major mode inherited from special mode, I could override this behavior. As it is, I just have to manually change the mode for that buffer.
  3. The aforementioned caveat about the minibuffer, though in practice this hasn't been much of an issue since in general if I want output to stick around in its own buffer, it tends to be longer-form output.
nnicandro commented 5 years ago

the command I evaluated is still there on an input line in the REPL buffer

There is also C-c M-: (jupyter-eval-string-command) which lets you enter code to evaluate in the minibuffer. Then you can C-c M-: M-p to repeat the command in the future.

For longer expressions you can just copy and paste them from some other buffer into the minibuffer, but I am also thinking of adding a way to pop-up a buffer to enter longer form input and send it to a kernel similar to how magit asks for a commit message. See https://github.com/dzop/emacs-jupyter/issues/35#issuecomment-497039866 for discussion.

If the mode for jupyter output instead was a new major mode inherited from special mode

👍

Maybe just get rid of the read only behavior and inherit from fundamental-mode instead.

nnicandro commented 5 years ago

Another workflow that I use quite often is to open up the scratch buffer, e.g. using C-c C-s in the REPL, and evaluate code there with C-c C-c. If you want to be able to mess with the output of evaluated code, you can instead do C-u C-c C-c which will insert the text/plain representation of output underneath the code you evaluated.