我使用 emacs 有一段时间了,但对 lisp 编程不是很熟悉。就在几天前,我开始在 emacs 上编写 Python 代码。我发现 python-mode 非常有用,我想进一步探索它。我在互联网上发现了一些 emacs 的嘴唇功能,对它们进行了一些修改以使界面用户友好。我正在尝试实现以下操作
我通常用 2 个垂直窗口启动 emacs,一个带有 python 源,另一个是 shell。我应该能够使用键盘绑定进行以下操作
- 在缓冲区之间切换(工作)
- 执行一个区域(工作),但用 shell 缓冲区替换源缓冲区。我想在原始 shell 缓冲区中执行选定区域。
- 执行一行(工作)但与上述相同的问题。当我说,该行应该在 python shell 中执行而不替换任何缓冲区。所以复制该行,切换到python shell,执行行,切换回python源缓冲区。
我无法实现上述切换动作。以下是我的 init.el 文件中的代码
(defun goto-python-shell ()
"Go to the python command window (start it if needed)"
(interactive)
(setq current-python-script-buffer (current-buffer))
(if (boundp 'current-python-shell-buffer)
(switch-to-buffer-other-window current-python-shell-buffer)
(py-shell))
(end-of-buffer)
)
(defun goto-python-source ()
"switch back to source window"
(interactive)
(setq current-python-shell-buffer (current-buffer))
(switch-to-buffer-other-window current-python-script-buffer)
)
(defun py-execute-statement-and-step ()
"select a statement, submit as a region and then step forward"
(interactive)
(beginning-of-line 1)
(let ((beg (point)))
(py-next-statement 1)
; if last statement.
(if (= (point) beg) (end-of-buffer ))
; (switch-to-buffer-other-window current-python-shell-buffer)
(py-execute-region beg (point))
(switch-to-buffer-other-window current-python-script-buffer)
)
)
; some key bindings
(define-key python-mode-map (quote [f9]) 'py-execute-statement-and-step)
;(define-key python-mode-map (quote [f10]) `py-execute-region)
;py-shell-switch-buffers-on-execute
(define-key python-mode-map (quote [f10]) `py-shell-switch-buffers-on-execute)
(define-key python-mode-map (quote [f11]) `py-execute-buffer)
(define-key python-mode-map (quote [f12]) `goto-python-shell)
(define-key py-shell-map (quote [f12]) `goto-python-source)
请指教。
另外,由于我是 python 模式的新手,有人可以分享使用类似于上面的 python 模式的不错的初始化吗?
非常感谢您的帮助。
问候, AJ