matlab - Track buffer changes and trigger a hook after event in Emacs -


i'm trying add facilities matlab environment within emacs. basically, want have buffer (*matlab whos*) display variables. buffer should update automatically after matlab-shell finishes evaluating expression. in other words, after press return on shell, hook should call function update *matlab whos*.

the simple solution came is:

(defvar matlab-whos-buffer-name "*matlab whos*")  (defun matlab-whos-buffer-update ()  "create matlab whos buffer if doesn't exist.   if exists, update 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))))) 

the function matlab-whos-buffer-update works fine. however, problem solution hook calls function before matlab shell finishes evaluation (requested (comint-send-input)). consequence, matlab-whos-buffer-update returns error saying:

matlab-shell-collect-command-output: matlab shell must non-busy that.

how can track changes matlab shell buffer, hook knows can trigger matlab-whos-buffer-update, after result of evaluation has returned?

you can start like

(add-hook 'matlab-shell-mode-hook           (lambda ()             (add-hook 'comint-output-filter-functions                       #'matlab-whos-buffer-update                       nil 'local))) 

but note call function everytime sent process. can foresee 2 problems it:

  • it may fail miserably if matlab-shell-collect-command-output ends using same setup (and hence calling matlab-whos-buffer-update.
  • it might run many times (if process sends output in 5 chunks, run 5 times).

try , come question if doesn't work enough.


Comments