在Emacs的'python-mode'中使用多个Python或IPython shell
有没有办法在使用Emacs的时候强制创建一个新的python-shell
实例?这样在处理多个项目时就很方便了,因为每个项目都有自己的工作目录和不同的模块。
每次尝试调用python-shell
时,系统只会调出当前的实例。
3 个回答
0
在使用 python-mode
通过 python.el 时,默认情况下每个 Python 文件都会有一个自己的 Python 解释器。
不过,如果你想让多个 Python 文件共享同一个解释器,可以改变这个默认设置。要做到这一点,在打开第一个 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 文件使用自己的解释器,可以输入:
M-x set-variable python-buffer [RET] nil [RET]
这样做之后,当你打开一个新的 Python 文件时,输入 python-switch-to-python
或 C-c C-z
,就会为那个文件创建一个新的 Python 解释器。
3
重命名缓冲区对我来说没什么用,但你可以使用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解释器。
3
在打开一个新的Python命令行之前,你需要先给你原来的Python命令行改个名字。可以使用 M-x 然后输入 rename-buffer
来完成这个操作。