【问题标题】:emacs python-mode: designate which python shell to send commands toemacs python-mode:指定向哪个python shell发送命令
【发布时间】:2012-01-07 02:55:49
【问题描述】:

跟进question - 如果我有两个在 emacs 中运行的 python shell,我如何指定每个 python 脚本缓冲区中的哪些 shell 命令被发送到?我怀疑这与python-bufferpython-set-proc 有关,但将这些变量设置为shell 的名称显然不是解决方案。

编辑:实际上由于我使用的是python-mode而不是loveshack python,它可能与python-bufferpython-set-proc无关。

【问题讨论】:

    标签: emacs python-mode


    【解决方案1】:

    您可以为python-buffer 设置一个新值。

    (defun my-python-set-proc (buffer-name)
      (interactive "B")
      (setf python-buffer (get-buffer buffer-name))
      (python-set-proc))
    

    然后是M-xmy-python-set-procRET*Python*RET, 或 M-xmy-python-set-procRET*Python*<2>RET

    【讨论】:

    • 谢谢 - 我建议 python-bufferpython-set-proc 是我的错误,因为它们似乎是loveshack python的相关变量,而不是python-mode
    【解决方案2】:

    在任何 Python 缓冲区中,您都可以使用变量 py-which-bufname 来控制在执行代码时将代码发送到哪个 Python shell。该变量是缓冲区本地的,因此为了将其设置为自定义值,您需要通过按M-: 并输入以下内容从缓冲区中更改它

    (setq py-which-bufname "My-Custom-Bufname")
    

    这也使得快速创建进程缓冲区变得容易:如果您将py-which-bufname设置为没有对应进程缓冲区的名称,则只需发出C-c !即可快速创建一个。

    HTH

    【讨论】:

    • 结案!谢谢 - 这正是我所需要的。
    • 这个变量似乎不存在了。由于这个问题首先出现在我的搜索引擎上,所以这是现代方式。该变量现在命名为python-shell-buffer-name。通过使用add-file-variable,您可以使用字符串为该变量定义缓冲区特定值,例如"TOTO"。然后它将使用 python shell 创建一个名为 *TOTO* 的缓冲区。
    【解决方案3】:

    py-shell-name 设置默认值,可能会被命令覆盖

    如果缓冲区代码包含一个指定 pythonVERSION 的 shebang,这将优先于默认设置。

    您可以通过调用 py-execute-buffer-pythonVERSION 类的命令来强制执行特定的 pythonVERSION 缓冲区

    查看菜单 PyExec,进入执行缓冲区 ...

    【讨论】:

      相关资源