【发布时间】:2016-01-24 15:07:27
【问题描述】:
我正在尝试在 Emacs 中为我的 matlab 环境添加一些工具。 基本上,我想要一个额外的缓冲区 (*Matlab Whos*) 来显示我的所有变量。 在 matlab-shell 完成对表达式的求值后,缓冲区应该会自动更新。换句话说,在我在 shell 上按回车键后,一个钩子应该调用一个函数来更新 *Matlab Whos*。
我想出的简单解决方案是:
(defvar matlab-whos-buffer-name "*Matlab Whos*")
(defun matlab-whos-buffer-update ()
"Create Matlab Whos buffer if it doesn't exist.
If it exists, update its values."
(lambda)
(interactive)
(let ((doc-whos (matlab-shell-collect-command-output "whos")))
(with-current-buffer (get-buffer-create matlab-whos-buffer-name)
(erase-buffer)
(insert doc-whos))))
(add-hook 'matlab-shell-mode-hook
(lambda ()
(define-key matlab-shell-mode-map (kbd "<return>")
(lambda ()
(interactive)
(comint-send-input)
(matlab-whos-buffer-update)))))
函数matlab-whos-buffer-update 工作正常。然而,这个解决方案的问题是我的钩子在 matlab shell 完成评估之前调用了函数(由(comint-send-input) 请求)。结果,matlab-whos-buffer-update 返回错误:
Matlab-shell-collect-command-output:MATLAB shell 必须不忙 这样做。
如何跟踪对我的 Matlab shell 缓冲区的更改,以便我的钩子知道它只能在评估结果返回后触发 matlab-whos-buffer-update?
【问题讨论】:
-
您是否尝试过使用
comint-output-filter-functions? -
如何正确使用它?我刚试过
(add-hook 'matlab-shell-mode-hook '(cons 'matlab-whos-buffer-update 'comint-output-filter-functions),但这也没有用。 (什么都没发生) -
一般性注释:一次向钩子添加一个函数,如
(add-hook 'foo-hook 'foo-func)。你的问题很好,但你的评论不行。