0

I have a function consisting of 2 commands.

    (defun my-function ()
        (interactive)
        (call-interactively 'run-python) ; <-- Something is not run after this line.
        (call-interactively 'python-shell-send-buffer))

When executing the 2 commands manually, they work fine. However, when executing the function above, I get

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__PYTHON_EL_eval_file' is not defined
>>>

I suspect some hooks are not run after the run-python line and they are delayed until the whole function is completed. Is there a way to make this work?

Drew
  • 75,699
  • 9
  • 109
  • 225
Gradient
  • 211
  • 1
  • 4
  • https://emacs.stackexchange.com/tags/elisp/info – Drew May 06 '22 at 22:31
  • Have you tried eliminating each of the `call-interactively` calls in turn and seeing if that produces the (python) backtrace you are reporting? Have you checked where `__PYTHON_EL_eval_file` is used and why it is not defined? Have you checked your `*Messages*` buffer? FWIW, I cannot reproduce it with Emacs 29, so you should also post the version of Emacs that you are using. – NickD May 06 '22 at 23:45
  • Kinda late here, but I had the same problem. There's some setup code that gets sent to Python inferior in `python-shell-comint-watch-for-first-prompt-output-filter`, which helps emacs send code to it afterwards. That filter function exposes no convenient hooks to detect when that setup is done, so I think your best bet is just to `(sit-for 0.2)` or something after the call to `run-python`. Not exactly robust, but it seems to work. – Jun Inoue Apr 17 '23 at 09:00

0 Answers0