在 Emacs 中使用多个 Python shell “python-mode”使用 Python 或 IPython

发布于 2024-12-18 13:08:29 字数 144 浏览 0 评论 0原文

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

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

Is there a way to force a new instance of python-shell while running Emacs? It would be convenient when working on multiple projects with separate working directories (and different sets of modules).

Any attempt to invoke python-shell will only pull up the current instance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╄→承喏 2024-12-25 13:08:29

在打开新的 python-shell 之前,您需要重命名原来的 python-shell。使用M-x重命名缓冲区

You need to rename your original python-shell before opening up a new one. Use M-x rename-buffer.

倒数 2024-12-25 13:08:29

重命名缓冲区对我来说不起作用,但您可以使用 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 解释器。

Renaming the buffer doesn't work for me, but you can use the third parameter of run-python.

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

Since the binding to switch to the current buffer isn't really helpful
you can rebound it to something more useful

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

And use C-cC-z to switch
to the current python interpreter and
C-uC-cC-z
to switch to a fresh python interpreter.

夏花。依旧 2024-12-25 13:08:29

通过 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-pythonCc Cz 后,将为该缓冲区创建新的 Python shell。

When using python-mode via python.el, having one Python shell per Python buffer is the default.

However, you can change this default behavior if what you want instead is for multiple Python buffers to share the same Python shell. To do so, after opening the first Python buffer, enter:

M-x python-set-proc

...which is documented:

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'.

Then later, if you want a new Python buffer to use its own shell, enter:

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

After doing so and then opening a new Python buffer, a new Python shell will be created for that buffer after entering python-switch-to-python or C-c C-z.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文