【问题标题】:Using multiple Python shells in Emacs 'python-mode' with Python or IPython在 Emacs 'python-mode' 中通过 Python 或 IPython 使用多个 Python shell
【发布时间】:2011-11-26 21:29:54
【问题描述】:

有没有办法在运行 Emacs 时强制创建 python-shell 的新实例?在使用单独的工作目录(和不同的模块集)处理多个项目时会很方便。

任何调用python-shell 的尝试都只会拉起当前实例。

【问题讨论】:

    标签: python emacs elisp ipython python-mode


    【解决方案1】:

    在打开一个新的之前,您需要重命名原来的 python-shell。使用 M-x rename-buffer.

    【讨论】:

      【解决方案2】:

      重命名缓冲区对我不起作用,但您可以使用run-python 的第三个参数。

      M - : (run-python nil nil t)RET

      由于切换到当前缓冲区的绑定并没有真正的帮助 你可以把它反弹成更有用的东西

      (defun my-run-python (&optional new)
        (interactive "P")
        (if new
         (run-python nil nil new)
         (pop-to-buffer (process-buffer (python-proc)) t)))
      
      (define-key python-mode-map (kbd "C-c C-z") 'my-run-python)
      

      并使用C-cC-z切换 到当前的 python 解释器和 C-uC-cC-z 切换到新的 python 解释器。

      【讨论】:

      • 谢谢。这很棒,除了它适用于loveshack python而且我使用的是python-mode。我想在某个时候切换,但现在我使用的是iPython,它似乎只与python-mode兼容。
      【解决方案3】:

      当通过 python.el 使用 python-mode 时,每个 Python 缓冲区有一个 Python shell 是默认设置。

      但是,如果您希望多个 Python 缓冲区共享同一个 Python shell,则可以更改此默认行为。为此,在打开第一个 Python 缓冲区后,输入:

      M-x python-set-proc
      

      ...记录在案的:

      Set the default value of `python-buffer' to correspond to this buffer.
      If the current buffer has a local value of `python-buffer', set the
      default (global) value to that.  The associated Python process is the
      one that gets input from C-c C-r et al when used in a buffer that
      doesn't have a local value of `python-buffer'.
      

      然后,如果您希望新的 Python 缓冲区使用自己的 shell,请输入:

      M-x set-variable python-buffer [RET] nil [RET]
      

      这样做并打开一个新的 Python 缓冲区后,将在输入 python-switch-to-pythonC-c C-z 后为该缓冲区创建一个新的 Python shell。

      【讨论】:

        相关资源