5

This is dim, but I've forgotten how to do this, and I can't work it out, sorry:

I'm in python mode with elpy, and I want to run the function python-nav-beginning-of-defun in a python buffer, to see what it does

M-x python-nav-beginning-of-defun 

won't work, because the function is not a command (it has no interactive spec).

And putting (python-nav-beginning-of-defun) in a buffer and using C-x C-e will disturb the buffer and move the point.

I seem to remember that there's some way that I can type (python-nav-beginning-of-defun) in a mini-buffer somewhere, and see what it does to the python buffer, without disturbing the buffer.

Can anyone tell me what it's called / what the magic keys are?

8

You're looking for M-: which runs the command eval-expression

2

You can execute Lisp code with the command eval-expression, bound to M-: by default (i.e. Alt+: or Esc :).

At the prompt, type the code to evaluate. To call a function, put the function name in parentheses.

M-: (python-nav-beginning-of-defun) RET

If there are arguments, put them after the function name, within the parentheses.

M-: (+ 2 2) RET

The return value of the function is displayed in the echo area. (In your case it isn't interesting, I mention that for the general case.) If it doesn't fit, or you want to see it afterwards or to copy-paste it, switch to the *Messages* buffer. If you'd rather assign the result to a variable, use the setq function:

M-: (setq x (+ 2 2)) RET

If the code triggers an error and a debugger window pops up, press q in the debugger window. If the code prompts for something and you want to cancel, press ESC three times (keyboard-escape-quit). If the code goes into a tight loop, break with C-g as usual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.