简体   繁体   English

自定义 Python shell 用于 Emacs python 模式

[英]Custom Python shell for Emacs python-mode

What does it take to replace regular /usr/bin/python with a custom python shell in Emacs' python-mode?在 Emacs 的 python 模式下用自定义 python shell 替换常规 /usr/bin/python 需要什么?

Basically I have a binary /usr/bin/mypython which does some initializations before starting python interpreter prompt, and for all interaction purposes, the resulting interpreter shell is equivalent to /usr/bin/python.基本上我有一个二进制 /usr/bin/mypython 在启动 python 解释器提示之前进行一些初始化,并且出于所有交互目的,生成的解释器 shell 等效于 /usr/bin/python。

However, if I specify this binary in "python-python-command" (using python.el in Emacs 23.3), I get "Only Python versions >=2.2 and < 3.0 are supported"但是,如果我在“python-python-command”中指定此二进制文件(在 Emacs 23.3 中使用 python.el),我会得到“仅支持 Python 版本 >=2.”。

I'm about to read the elisp to check, but I'd bet if you added a --version flag that gave the save results as /usr/bin/python , emacs would be happy.我即将阅读 elisp 进行检查,但我敢打赌,如果您添加了一个--version标志,将保存结果显示为/usr/bin/python ,emacs 会很高兴。

Update更新

Here's the code in python.el line 1555 et seq in EMACS 23.3.1:这是 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)))

What it's doing is running a one-liner它正在做的是运行单线

from sys import version_info;
print version_info >= (2, 2) and version_info < (3, 0)

that just prints "True" or "False".只打印“True”或“False”。 Fix your script to handle the -c flag and you should be fine.修复你的脚本来处理 -c 标志,你应该没问题。

Alternatively, you could take the hacker's way out and force the value of python-version-checked to t , and it'll never do the check.或者,您可以采取黑客的出路并将python-version-checked的值强制为t ,它永远不会进行检查。

The easiest way to defeat the check is to lie and tell python-check-version that it's already checked:击败检查的最简单方法是撒谎并告诉python-check-version它已经检查过:

(setq python-version-checked t)

with python-mode.el just do使用 python-mode.el 就可以了

Mx MY-PYTHON RET Mx MY-Python RET

given the Python version is installed鉴于已安装 Python 版本

https://launchpad.net/python-mode https://launchpad.net/python-mode

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

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