简体   繁体   English

使Emacs的Python交互模式突出显示和缩进

[英]Making Python Interactive Mode of Emacs Highlight and Indent

I am using Emacs 23 with python-mode 5.1.0 to edit my python programs. 我正在使用带有python-mode 5.1.0的Emacs 23来编辑我的python程序。 Sometimes when writing a program I want to run a small throwaway python script and so I run the interactive move (Cc !). 有时在编写程序时我想运行一个小的一次性python脚本,所以我运行了交互式移动(抄送!)。 This is fine, but it neither indents nor highlights the code, and if I try running python mode while in it, it no longer evaluates. 这很好,但它既没有缩进也没有突出显示代码,如果我尝试在其中运行python模式,它就不再评估了。 So, how do I set it to indent and highlight? 那么,如何将其设置为缩进和突出显示?

Adding these to my .emacs seems to have done it. 将这些添加到我的.emacs似乎已经完成了。

The bit where it checks the buffer name in the advice would probably be better as a test on a buffer-local variable set by set-pycomint-keywords, but you get the idea. 检查建议中缓冲区名称的位可能会更好地作为对set-pycomint-keywords设置的缓冲区局部变量的测试,但是你明白了。

(defun set-pycomint-keywords ()
  (setq font-lock-keywords      python-font-lock-keywords))

(add-hook 'py-shell-hook 'set-pycomint-keywords)



 (defadvice comint-send-input (around block-comint-formatting activate)
  (if (string= (buffer-name) "*Python*")
      (letf (((symbol-function 'add-text-properties) (lambda (x y z) nil)))
        ad-do-it))
  ad-do-it)

I don't have time to try it now, but i found you can replace python shell when you press Cc with this that should be more powerful: 我现在没有时间尝试,但是我发现当你按下具有更强大功能的Cc时你可以替换python shell:

http://ipython.scipy.org/moin/ http://ipython.scipy.org/moin/

When i'll have time I'll give it a try 当我有时间的时候我会试一试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM