Emacs Python: Echoing, Hooks and Org-mode

孤人 提交于 2019-12-02 05:51:40

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!