on GNU EMACS's python-mode, loading entire buffer
Meredith Montgomery
mmontgomery at levado.to
Sun Sep 4 15:47:07 EDT 2022
Meredith Montgomery <mmontgomery at levado.to> writes:
> Meredith Montgomery <mmontgomery at levado.to> writes:
>
> [...]
>
>> I would also be interested in a command that restarts the REPL afresh
>> and reloads my buffer --- sort of like keyboard's [F5] of the IDLE.
>
> A partial solution for this is the following procedure.
>
> (defun python-revert-and-send-buffer-to-repl ()
> "Revert current buffer and sends it to the Python REPL."
> (interactive)
> (revert-buffer "ignore-auto-no" "no-confirm")
> (python-shell-send-buffer))
>
> We can map this to the F5-key and that improves things. But a restart
> of the REPL would be the ideal. (Sometimes we really want to start
> afresh. Sometimes. Most often we don't want that.)
It's not easy to restart the REPL. You can send "quit()" to it and
invoke run-python again interactively by typing out one command after
another, but if you write a procedure such as this one below, it doesn't
work: it gives me the impression that there's a timing issue, that is,
perhaps the procedure is too fast and something happens before it
should.
(defun python-save-send-buffer-to-repl ()
(interactive)
(save-buffer)
(python-shell-send-string "quit()")
(run-python)
(python-shell-send-buffer)
(python-shell-switch-to-shell))
More information about the Python-list
mailing list