There appears to be a pretty significant bug in C-M-x, a.k.a. python-shell-send-defun in the builtin python mode
- start emacs
- create a new file, let's call it
test.py C-c C-ptorun-pythonin the
test.pybuffer, type some simple function, likedef f(x): return x+1C-M-xforpython-shell-send-defun
we get:
return x+1
SyntaxError: 'return' outside function
So what's happening here is that python-shell-send-defun is only sending one line, not both lines as we would expect it to (the corresponding command in emacs lisp major mode for instance works correctly in sending the entire multiline defun prior to the cursor). What's going on here? I tested this in both emacs 25 gui version in Mac OS as well as emacs 24 in Ubuntu. Both exhibit the same error.
Is this a bug, or am I misunderstanding what python-shell-send-defun actually does?
Update: with some further testing, it appears that this error only occurs for functions that start on the very first line. If we insert a blank line right above def f(x):, C-M-x works perfectly.