用于Emacs python-mode的自定义Python shell

Yar*_*tov 6 python emacs

在Emacs的python-mode中用常规python shell替换常规/ usr/bin/python需要什么?

基本上我有一个二进制文件/ usr/bin/mypython,它在启动python interpreter提示符之前进行一些初始化,并且出于所有交互目的,生成的解释器shell等同于/ usr/bin/python.

但是,如果我在"python-python-command"中指定这个二进制文件(在Emacs 23.3中使用python.el),我会得到"只支持Python版本> = 2.2且支持<3.0"

Cha*_*tin 5

我即将阅读elisp进行检查,但我敢打赌,如果你添加了一个--version标志,保存结果为/usr/bin/python,emacs会很高兴.

更新

这是EMACS 23.3.1中python.el第1555及以下代码中的代码:

(defvar python-version-checked nil)
(defun python-check-version (cmd)
  "Check that CMD runs a suitable version of Python."
  ;; Fixme:  Check on Jython.
  (unless (or python-version-checked
          (equal 0 (string-match (regexp-quote python-python-command)
                     cmd)))
    (unless (shell-command-to-string cmd)
      (error "Can't run Python command `%s'" cmd))
    (let* ((res (shell-command-to-string
                 (concat cmd
                         " -c \"from sys import version_info;\
print version_info >= (2, 2) and version_info < (3, 0)\""))))
      (unless (string-match "True" res)
    (error "Only Python versions >= 2.2 and < 3.0 are supported")))
    (setq python-version-checked t)))
Run Code Online (Sandbox Code Playgroud)

它正在做的是运行单线程

from sys import version_info;
print version_info >= (2, 2) and version_info < (3, 0)
Run Code Online (Sandbox Code Playgroud)

只打印"真"或"假".修复你的脚本来处理-c标志,你应该没问题.

或者,你可以采取黑客的出路,迫使价值python-version-checkedt,它永远不会做检查.