1

我想在 Debian 上使用 emacs 23.4 作为 python (2.7) IDE 有以下工作流程:

  1. 当打开像 $ emacs file.py 这样的文件时,Emacs 会并排启动 2 个窗口
  2. 左侧窗口中已经有一个 shell,右侧窗口中已经有缓冲区 file.py。
  3. 一个快捷方式执行代码(以及部分代码的另一个快捷方式),结果可以在左侧窗口(ipython shell)中看到。焦点保持在右侧窗口,执行命令时缓冲区不会改变。
  4. 快捷方式可以轻松地将焦点从左到右切换,反之亦然。

到目前为止,我可以完成除了第二项(我必须手动使缓冲区可见)之外的所有事情,这似乎很简单。我一直在阅读 emacs 的嘴唇参考手册,以便我可以自己定制 emacs,但我仍然是 emacs 的初学者。我还发现了一些类似的问题,但并不完全有帮助。这是我的 .emacs 的一些相关部分。

;; Initial frame size and position (1280x1024)
(setq default-frame-alist
  '((top . 45) (left . 45)
    (width . 142) (height . 54)))
(if (window-system) 
  (split-window-horizontally (floor (* 0.49 (window-width))))
)

; python-mode
(setq py-install-directory "~/.emacs.d/python-mode.el-6.1.3")
(add-to-list 'load-path py-install-directory)
(require 'python-mode)

; use IPython
(setq-default py-shell-name "ipython")
(setq-default py-which-bufname "IPython")
; use the wx backend, for both mayavi and matplotlib
(setq py-python-command-args
  '("--gui=wx" "--pylab=wx" "--colors=linux"))
(setq py-force-py-shell-name-p t)

; switch to the interpreter after executing code
(setq py-shell-switch-buffers-on-execute-p t)
 ;(setq py-switch-buffers-on-execute-p t)

; don't split windows
(setq py-split-windows-on-execute-p nil)
; try to automagically figure out indentation
(setq py-smart-indentation t)

(defun goto-python-shell () 
  "Go to the python command window (start it if needed)" 
  (interactive)
  (setq current-python-script-buffer (current-buffer))
  (py-shell)
  (end-of-buffer)
)
(goto-python-shell)

我相信解决方案很简单,取决于函数/变量:switch-to-buffer、initial-buffer-choice、other-window、py-shell-switch-buffers-on-execute-p、py-switch-buffers-在执行-p。

但是,我仍然找不到一个可以让这一切正常工作的解决方案。


编辑:

我能够拥有我想要的行为,将最后一部分替换为:

(switch-to-buffer (py-shell))
(end-of-buffer)
(other-window 3)
(switch-to-buffer (current-buffer))

,因为我用 get-buffer-window 发现左窗口显示为 3,右窗口显示为 6。

4

1 回答 1

1

py-split-windows-on-execute-p,py-switch-buffers-on-execute-p设置时,它应该按预期工作 - 无需手写拆分。

仍然是水平/垂直问题。为此,python-mode.elpy-split-windows-on-execute-function在当前主干中提供了自定义:

https://code.launchpad.net/python-mode

于 2014-11-25T07:46:43.897 回答