Skip to content

Instantly share code, notes, and snippets.

@v2e4lisp
Created February 2, 2013 06:12
Show Gist options
  • Save v2e4lisp/4696291 to your computer and use it in GitHub Desktop.
Save v2e4lisp/4696291 to your computer and use it in GitHub Desktop.
python-eval eval python code in the current buffer [Emacs]
(defun python-eval ()
" Eval python code in current buffer.
It seems that the default python-mode doesn't have this function"
(interactive)
(let ((script-py (buffer-file-name))
(tmp-script-py "/Users/wenjunyan/.test-code.py")
(output-buffer "*python-eval-output*"))
(if script-py
(progn
(when (buffer-modified-p)
(when (y-or-n-p "This buffer is modified. Save it to file ?")
(save-buffer)))
(shell-command (concat "python " script-py) output-buffer))
(write-file tmp-script-py)
(kill-buffer)
(shell-command (concat "python " tmp-script-py) output-buffer)
(delete-file tmp-script-py))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment