millejoh / emacs-ipython-notebook

Jupyter notebook client in Emacs
http://millejoh.github.io/emacs-ipython-notebook/
GNU General Public License v3.0
1.47k stars 123 forks source link

How to revert current notebook? #843

Closed daanturo closed 2 years ago

daanturo commented 2 years ago

At #222 Millejoh suggested ein:notebook-restore-to-checkpoint, but the command doesn't exist anymore.

Is there an equivalent one?

(Isn't directly relevant to #772, which is about check points).

dickmao commented 2 years ago

Sorry, I've said all I wanted to say in #772 .

...the webcentric jupyter "way of doing things" is truly terrible for git, especially if the notebook is being remotely served in which case it's impossible to check into version control. I have no plans on bringing back the checkpointing.

Bring on the torches and pitchforks.

daanturo commented 2 years ago

@dickmao Then how do I write a function what would immitate "refresh"?

My current attempt:

(defun my-ein-revert|refresh-notebook ()
  "Re-open current notebook to get the latest evaluation results.
Pass `no-pop' to `ein:notebook-open' and handle displaying in the
callback."
  (interactive)
  (let* ((notebook ein:notebook)
         (wd (selected-window))
         (pos (point))
         (buffers (-keep #'ein:worksheet-buffer
                         (append (ein:$notebook-worksheets notebook)
                                 (ein:$notebook-scratchsheets notebook)))))
    (mapc 'kill-buffer buffers)
    (ein:notebook-open
     (ein:$notebook-url-or-port notebook)
     (ein:$notebook-notebook-path notebook)
     nil
     (lambda (nb _)
       (with-selected-window wd
         (switch-to-buffer (ein:notebook-buffer nb))
         (goto-char pos)))
     nil
     'no-pop)))

Unfortunately it's a visible disruption since I try to kill "worksheet" buffers before re-openning the notebook (otherwise ein will just "notebook is already open"), therefore Emacs will flash/switch buffer twice.

dickmao commented 2 years ago

That looks pretty good, my guy.

Does C-c C-r not do it for you?

If I used EIN (which I do maybe once a year), I would just C-x k the buffer, and reopen from the notebook list.

daanturo commented 2 years ago

Does C-c C-r not do it for you?

No C-c C-r doesn't update buffer to the latest state of the notebook when it was edited outside of EIN's interface.