Emacs Python:回声,钩子和组织模式 [英] Emacs Python: Echoing, Hooks and Org-mode

查看:132
本文介绍了Emacs Python:回声,钩子和组织模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此问题,我发现如何解决回显问题emacs中的python shell。我想做的是将它添加到我的.emacs文件中,以便它会自动发生。

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)

如果我启动一个python shell( Mx python-shell ),这不行。

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

我可以使用 M-:(python-startup),然后回显行为停止。

I can run this function with M-: (python-startup), and then the echoing behavior stops.

>>> 22
22

我不知道我是否正确设置挂钩,或者如果我应该使用一个不同的钩子。作为一个附注,我该怎么知道什么钩子被称为什么功能?最终的目标是最终能够在org-mode中使用:results output:session ,以便我可以集成python代码,而不会使每个命令回显结果。我怀疑一旦我修复了钩子,那就是我会拥有的行为,但是我实际上并不知道这是否是真的。

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.

推荐答案

我对此的简短调查显示, python-mode (在我的Emacs中找到)没有 py-shell-hook ,所以自然不会运行你放在那里的任何东西。

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.

当我看着 python-mode ,它没有钩子,它运行,所以你有点不幸运。

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))

如果您需要以交互方式调用 python-shell ,请使用

If you need to call python-shell interactively, use

(call-interactively 'python-shell)

这篇关于Emacs Python:回声,钩子和组织模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆