【问题标题】:Custom Python shell for Emacs python-mode用于 Emacs python-mode 的自定义 Python shell
【发布时间】:2011-06-08 01:28:09
【问题描述】:

在 Emacs 的 python 模式下用自定义的 python shell 替换常规的 /usr/bin/python 需要什么?

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

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

【问题讨论】:

    标签: python emacs


    【解决方案1】:

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

    更新

    这是 EMACS 23.3.1 中 python.el 行 1555 et seq 中的代码:

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

    它正在做的是运行单线

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

    只打印“True”或“False”。修复你的脚本来处理 -c 标志,你应该没问题。

    或者,您可以让黑客退出并强制将python-version-checked 的值更改为t,但它永远不会进行检查。

    【讨论】:

    • 感谢您的指点,查看文件我发现了另一个问题——“-i”标志是硬连线的(因此从 python-python-command-args 中删除它不会阻止它通过)
    • 嗯,这就是他们为您提供资源的原因。但这对我来说尤其像是一个错误。更改它并提交补丁。
    【解决方案2】:

    击败检查的最简单方法是撒谎并告诉python-check-version它已被检查:

    (setq python-version-checked t)
    

    【讨论】:

      【解决方案3】:

      使用 python-mode.el 就可以了

      M-x MY-PYTHON RET

      假设已安装 Python 版本

      https://launchpad.net/python-mode

      【讨论】:

      • 欢迎来到 StackOverflow!我看到你很热情并且有一个最喜欢的工具。但是,在您的所有帖子中推荐或链接到同一站点,并且仅在您的第一天就推荐或链接 10 次,可能会触发该站点上的“潜在垃圾邮件”信号。所以保重!只是一个友好的建议。
      猜你喜欢
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      相关资源
      最近更新 更多