Debug tooltips only intermittently work: global `mlgud-tooltip-mode` ends up off while `matlab-shell-gud-minor-mode` is on
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 59/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- emacs
- 领域
- devtools
调研方向
Read matlab-shell-gud.el and mlgud.el, starting with the minor mode bodies and the debug prompt transition described in the issue. Trace how enabling or disabling the buffer local modes changes the global tooltip mode, then check the transition behavior with the supplied run.sh reproduction. Done means tooltips stay enabled while debugging is active and are disabled when debugging ends.
由索引模型根据 Issue 内容生成。
描述
Description
With matlab-shell-debug-tooltips-p set to t, hovering over a variable in a .m buffer while stopped at the K>> prompt only sometimes shows its value. Tooltips are supposed to turn on whenever debugging starts. In an affected buffer, the local matlab-shell-gud-minor-mode was t but the global mlgud-tooltip-mode was nil (and track-mouse was nil), i.e. tooltips were off even though debug mode was active. Tooltips are controlled by one global switch, but they are turned on and off by modes that are local to each buffer.
Cause
mlgud-tooltip-modeis:global t(mlgud.el).- In
matlab-shell-gud.el,matlab-shell-gud-minor-modecalls(mlgud-tooltip-mode 1)when it is enabled, ifmatlab-shell-debug-tooltips-pis set. - The body of
matlab-shell-inactive-gud-minor-modecalls(mlgud-tooltip-mode -1)unconditionally, so it runs both when the mode is enabled and when it is disabled. Likewisematlab-shell-gud-minor-mode's disable branch calls it. - On entering the
K>>prompt, the prompt-tracking code runs(global-matlab-shell-gud-minor-mode 1)and then(global-matlab-shell-inactive-gud-minor-mode -1). Disabling the inactive mode runs its body, which switches the global tooltip mode off right after the first call switched it on.
I confirmed this order with trace-function on mlgud-tooltip-mode, matlab-shell-gud-minor-mode and matlab-shell-inactive-gud-minor-mode while entering K>>, with two matlab buffers open and no workaround hook active (trace abridged):
1 -> (matlab-shell-gud-minor-mode 1)
| 2 -> (mlgud-tooltip-mode 1)
| 2 <- mlgud-tooltip-mode: t
1 <- matlab-shell-gud-minor-mode: t
(same again for the second buffer)
1 -> (matlab-shell-inactive-gud-minor-mode -1)
| 2 -> (mlgud-tooltip-mode -1)
| 2 <- mlgud-tooltip-mode: nil
1 <- matlab-shell-inactive-gud-minor-mode: nil
(same again for the second buffer)
The last call is (mlgud-tooltip-mode -1), so the global mode is nil once debug mode is active.
As far as I can tell from the repository history, matlab-shell-gud.el has not changed since 8.2.0, so this likely affects the latest release as well. I have not tested 8.2.2.
Workarounds
Killing the source buffer and running dbstep usually brings tooltips back. This fits the cause. Running dbstep reopens the file, and global-matlab-shell-gud-minor-mode enables matlab-shell-gud-minor-mode in the new buffer. That calls (mlgud-tooltip-mode 1), which turns the global switch back on and re-enables track-mouse in the buffers. No (global-matlab-shell-inactive-gud-minor-mode -1) call follows it, so nothing switches the global mode off again. That would also explain why it works "usually" and not always: it depends on whether something else toggles the inactive mode afterwards. I haven't traced this case.
A less intrusive workaround is to turn tooltips back on once the debug prompt is active:
(add-hook 'gud-matlab-debug-activate-hook
(lambda () (when matlab-shell-debug-tooltips-p (mlgud-tooltip-mode 1))))
With this hook, tooltips work reliably in my setup. gud-matlab-debug-activate-hook runs right after (global-matlab-shell-inactive-gud-minor-mode -1) in the prompt transition, so the hook re-enables the global switch after the call that turns it off.
The hook treats the symptom, not the root cause. The per-buffer minor modes still toggle the global mlgud-tooltip-mode, and the hook just puts it back afterwards. It runs only when K>> becomes active. If something else toggled the inactive mode later in the same debug session, tooltips could be switched off again until the next transition. I haven't observed that.
Suggested direction
Enable and disable the global tooltip mode in one place, when debugging starts and ends (for example from the gud-matlab-debug-active transition), not from the per-buffer minor modes.
Environment
- Emacs 29.4, Linux
- matlab-emacs 8.2.0
matlab-shell-debug-tooltips-p=t
Reproduction (bare Emacs, scripted)
Requires a MATLAB installation. Tested with Emacs 29.4, matlab-emacs 8.2.0 and MATLAB R2022b. Save the two files below in the same directory, then run:
M=/path/to/Emacs-MATLAB-Mode ./run.sh # without workaround
REPRO_HOOK=1 M=/path/to/Emacs-MATLAB-Mode ./run.sh # with the workaround hook
Optional: EMACS=/path/to/emacs and MATLAB_CMD=/path/to/matlab if they are not on your PATH.
The script starts matlab-shell in emacs -Q (with an empty startup.m and MATLABPATH unset), sets a breakpoint in a small test function, runs it to K>>, and prints the state of the tooltip modes plus a trace-function trace. A mouse hover can't be tested in batch mode, so it checks the state that tooltips depend on.
Results (single matlab buffer):
| Run | matlab-shell-gud-minor-mode (local) |
mlgud-tooltip-mode (global) |
track-mouse (local) |
Verdict |
|---|---|---|---|---|
./run.sh |
t |
nil |
nil |
BUG REPRODUCED |
REPRO_HOOK=1 ./run.sh |
t |
t |
t |
OK |
Trace without the hook (the same shape as in the trace above, one buffer):
1 -> (matlab-shell-gud-minor-mode 1)
| 2 -> (mlgud-tooltip-mode 1)
| 2 <- mlgud-tooltip-mode: t
1 <- matlab-shell-gud-minor-mode: t
1 -> (matlab-shell-inactive-gud-minor-mode -1)
| 2 -> (mlgud-tooltip-mode -1)
| 2 <- mlgud-tooltip-mode: nil
1 <- matlab-shell-inactive-gud-minor-mode: nil
run.sh
#!/bin/sh
# Batch repro of the matlab-shell debug tooltip issue, in a bare Emacs (emacs -Q).
# Usage: M=/path/to/Emacs-MATLAB-Mode ./run.sh -> without workaround (expect: BUG REPRODUCED)
# REPRO_HOOK=1 M=/path/to/Emacs-MATLAB-Mode ./run.sh -> with the workaround hook (expect: OK)
# Optional: EMACS=/path/to/emacs MATLAB_CMD=/path/to/matlab
here=$(cd "$(dirname "$0")" && pwd)
: "${M:?set M to the matlab-emacs directory, e.g. M=/path/to/Emacs-MATLAB-Mode}"
EMACS=${EMACS:-emacs}
MATLAB_CMD=${MATLAB_CMD:-matlab}
work=$(mktemp -d) || exit 1
echo '% empty' > "$work/startup.m" # unaltered startup, as recommended in DEBUGGING.org
cd "$work" || exit 1
env MATLABPATH= REPRO_DIR="$work" MATLAB_CMD="$MATLAB_CMD" \
"$EMACS" -Q --batch -L "$M" -l "$M/matlab-autoload.el" -l "$here/repro.el"
status=$?
echo "(exit status $status; work dir $work)"
exit $status
repro.el
;;; repro.el --- batch repro of the matlab-shell debug tooltip problem -*- lexical-binding: t; -*-
;;
;; Run through run.sh. Starts matlab-shell, stops at a breakpoint, then reports
;; whether the global `mlgud-tooltip-mode' is still on while
;; `matlab-shell-gud-minor-mode' is on in the source buffer.
;; A mouse hover can't be tested in batch mode; this checks the state that makes it work.
;;
;; Environment:
;; REPRO_DIR working dir (must be writable) - set by run.sh
;; MATLAB_CMD MATLAB executable - set by run.sh
;; REPRO_HOOK non-empty: install the workaround hook (expected result: tooltips stay on)
(require 'trace)
(require 'matlab-shell)
(require 'matlab-shell-gud)
(defvar repro-dir (file-name-as-directory (expand-file-name (getenv "REPRO_DIR"))))
(setq default-directory repro-dir)
(setq matlab-shell-command (or (getenv "MATLAB_CMD") "matlab"))
(setq matlab-shell-command-switches '("-nodesktop" "-nosplash" "-nodisplay"))
(setq matlab-shell-debug-tooltips-p t)
(when (not (string-empty-p (or (getenv "REPRO_HOOK") "")))
(add-hook 'gud-matlab-debug-activate-hook
(lambda () (when matlab-shell-debug-tooltips-p (mlgud-tooltip-mode 1)))))
(defun repro-say (fmt &rest args) (princ (apply #'format (concat fmt "\n") args)))
(defun repro-shell-buffer () (matlab-shell-active-p))
(defun repro-wait (pred timeout what)
"Wait until PRED returns non-nil, or fail after TIMEOUT seconds."
(let ((end (+ (float-time) timeout)))
(while (and (not (funcall pred)) (< (float-time) end))
(accept-process-output nil 0.2))
(unless (funcall pred)
(repro-say "TIMEOUT waiting for: %s" what)
(when (repro-shell-buffer)
(with-current-buffer (repro-shell-buffer)
(repro-say "--- tail of MATLAB buffer ---\n%s"
(buffer-substring (max (point-min) (- (point-max) 1500)) (point-max)))))
(kill-emacs 2))))
(defun repro-on-prompt ()
(and (repro-shell-buffer)
(with-current-buffer (repro-shell-buffer) (matlab-on-prompt-p))))
(defun repro-send (cmd)
(matlab-shell-send-command cmd)
(accept-process-output nil 0.3))
;; Test file: breakpoint goes on line 3.
(defvar repro-file (expand-file-name "tooltip_repro.m" repro-dir))
(with-temp-file repro-file
(insert "function tooltip_repro\nx = 1;\ny = x + 1;\ndisp(y)\nend\n"))
(defvar repro-src (find-file-noselect repro-file))
(repro-say "Starting matlab-shell (%s)..." matlab-shell-command)
(save-window-excursion (matlab-shell))
(repro-wait #'repro-on-prompt 180 "first MATLAB prompt")
;; Trace only after startup, so the output covers just the debug transition.
(dolist (f '(mlgud-tooltip-mode matlab-shell-gud-minor-mode matlab-shell-inactive-gud-minor-mode))
(trace-function-background f))
(repro-send (format "cd('%s')" repro-dir))
(repro-wait #'repro-on-prompt 60 "prompt after cd")
(repro-send "dbstop in tooltip_repro at 3")
(repro-wait #'repro-on-prompt 60 "prompt after dbstop")
(repro-send "tooltip_repro")
(repro-wait (lambda () gud-matlab-debug-active) 60 "K>> debug prompt (gud-matlab-debug-active)")
(let ((end (+ (float-time) 2.0))) (while (< (float-time) end) (accept-process-output nil 0.2)))
(let ((tip mlgud-tooltip-mode)
(gud (buffer-local-value 'matlab-shell-gud-minor-mode repro-src))
(trk (buffer-local-value 'track-mouse repro-src)))
(repro-say "\n===== STATE AT K>> (source buffer %s) =====" (buffer-name repro-src))
(repro-say "matlab-shell-gud-minor-mode (local) = %S" gud)
(repro-say "mlgud-tooltip-mode (global) = %S" tip)
(repro-say "track-mouse (local) = %S" trk)
(repro-say "REPRO_HOOK = %S" (getenv "REPRO_HOOK"))
(repro-say "\n===== TRACE =====")
(with-current-buffer (get-buffer-create "*trace-output*")
(repro-say "%s" (buffer-string)))
(repro-say "===== VERDICT =====")
(cond ((and gud (not tip)) (repro-say "BUG REPRODUCED: debug mode is on but tooltips are off."))
((and gud tip) (repro-say "OK: tooltips are on while debug mode is on."))
(t (repro-say "INCONCLUSIVE: gud minor mode is not on in the source buffer.")))
(ignore-errors (repro-send "dbquit"))
(ignore-errors (repro-send "exit"))
(kill-emacs (cond ((and gud (not tip)) 1) (gud 0) (t 3))))
- 主要语言
- Emacs Lisp
- 星标
- 27
- 派生
- 5
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mathworks/Emacs-MATLAB-Mode 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 40/100
-
难度 5/5 一周以上 新手友好度 15/100
-
enhancement help wanted
难度 4/5 3-5 天 新手友好度 38/100
-
难度 3/5 1-2 天 新手友好度 28/100
mathworks/Emacs-MATLAB-Mode#59 · 3 条评论 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 25/100
mathworks/Emacs-MATLAB-Mode#50 · 1 条评论 ·
查看 mathworks/Emacs-MATLAB-Mode 的全部 Issue
相似的 Issue
-
bounty good first issue help wanted
难度 2/5 1-3 小时 新手友好度 78/100
fitzss/valun-open#15 · 1 条评论 ·
维护者通常 1 天内回复
-
compaction help wanted
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 72/100
jqlang/playground#398 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 86/100
sickpancake/PancakeNotch#222 ·
维护者通常 1 天内回复
-
enhancement help wanted
难度 2/5 1-3 小时 新手友好度 82/100