开发者

Making Python Interactive Mode of Emacs Highlight and Indent

开发者 https://www.devze.com 2022-12-17 10:35 出处:网络
I am using Emacs 23 with python-mode 5.1.0 to edit my python programs. Sometimes when writing a program I want to run a small throwaway python script and so I run the interactiv开发者_如何学运维e move

I am using Emacs 23 with python-mode 5.1.0 to edit my python programs. Sometimes when writing a program I want to run a small throwaway python script and so I run the interactiv开发者_如何学运维e move (C-c !). 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. So, how do I set it to indent and highlight?


Adding these to my .emacs seems to have done it.

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.

(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 C-c with this that should be more powerful:

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

When i'll have time I'll give it a try

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号