Reputation: 2343
In Emacs (with C-:
), those 2 calls yield different results :
(progn (run-python (python-shell-parse-command) nil nil) (python-shell-send-buffer))
and
(run-python (python-shell-parse-command) nil nil)
# then, in another C-:
(python-shell-send-buffer)
In the first call, I get a python shell with the following error:
>>> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__PYTHON_EL_eval' is not defined
Why is the result different for these 2 elisp codes? I am trying to put these commands in a function, but I cannot if they yield an error together.
Upvotes: 0
Views: 59
Reputation: 73274
As suggested by @Lindydancer, run-python
selects the comint buffer, so python-shell-send-buffer
will be called with that as the current buffer, which probably isn't what you intended.
See also C-hf save-current-buffer
Also note that the inferior process is started asynchronously, so run-python
might return before the process is ready to receive input. You may or may not have to take that into account.
In general there is no reason to expect running two things in immediate sequence via progn
to produce the same results as two completely independent calls to each of those things, separated by not only time but also by trips through the Emacs command loop, with all of the intervening executed code which that entails.
Upvotes: 1