Based on this question I discovered how to fix the echoing problem in the python shell in emacs. What I want to do is add this to my .emacs file so that it will happen automatically.
(defun python-startup ()
(setq comint-process-echoes t))
(add-hook 'py-shell-hook 'python-startup)
If I start a python shell (M-x python-shell
), this hasn't worked.
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 22
22
22
I can run this function with M-: (python-startup)
, and then the echoing behavior stops.
>>> 22
22
I don't know if I'm setting up the hook incorrectly, or if I should be using a different hook altogether. As a side note, how do I know what hook is called for what function? The end goal is to end up being able to use :results output :session
in org-mode so that I can integrate python code without the results echoing every command. I suspect that once I fix the hook, that is the behavior I will have, but I don't actually know if this is true.
My brief investigation into this shows that python-mode
(as found in my Emacs) has no py-shell-hook
, so naturally it won't run anything you put in there.
When I looked at python-mode
, there are no hooks that it runs, so you are a bit out of luck.
Your best bet it to just make your own command, for exmaple:
(defun alex-python-shell ()
"Start a python shell my way."
(interactive)
(python-shell)
(python-startup))
If you need to call python-shell
interactively, use
(call-interactively 'python-shell)
来源:https://stackoverflow.com/questions/9830729/emacs-python-echoing-hooks-and-org-mode