I recently started using emacs to code in Python. I currently prefer to use python mode (defined in python.el) alongside ansi-term for the python interactive shell. I'm trying to change the behavior of C-c C-c in python mode so it sends the buffer into ansi-term to be executed. That is, I'd like it to act as if I wrote 'execfile([current .py file i'm working on])' in the ansi-term.

Is there a way to do this? If not specifically through C-c C-c, with some other shortcut/method?

  • 1
    The problem is that you could have many ansi-terms open at the same time, so finding the right one would require more thinking, but suppose you want it to be the one called *term* already running Python interpreter, then (let ((f (buffer-file-name))) (with-current-buffer "*term*" (insert (format "execfile(['%s'])" f) (term-send-input))), and then bind this to whatever key you want. – wvxvw Jan 4 '16 at 6:17
  • 1
    Have you looked at isend? – user2699 Jan 4 '16 at 14:25
  • How to define a function that calls a console process using ansi-term? may also be of interest. – phils Jan 4 '16 at 20:19

Your Answer

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

Browse other questions tagged or ask your own question.