Fix conflict between matlab-shell debugging and C++ (or other language) debugging.

Fix conflict between matlab-shell debugging and C++ (or other language) debugging.
- matlab-shell debugging previously leveraged gud.el for debugging of *.m files.
- C++ debugging also leverages gud.el for debugging.
- Only one instance of a gud.el debugger can be active. If you run two, say
  *.m debugging and C++ debugging. Then you get odd errors such as the
  ebbreak not being recognized by gdb.
To fix these issue, I copied gud.el and made a new namespace "mlgud". I also
removed a lot of unused code from mlgud.el, though there's still more that can
be removed. Now one can debug *.m files and *.cpp files in one Emacs session.
This commit is contained in:
John Ciolfi 2022-03-11 14:55:04 -05:00
parent c945bf5025
commit 45febb409c
6 changed files with 1851 additions and 487 deletions

View File

@ -1,3 +1,16 @@
2022-03-11 John Ciolfi <ciolfi@mathworks.com>
* matlab-netshell.el, matlab-shell-gud.el, matlab-shell.el, matlab.el, mlgud.el
Fix conflict between matlab-shell debugging and C++ (or other language) debugging.
- matlab-shell debugging previously leveraged gud.el for debugging of *.m files.
- C++ debugging also leverages gud.el for debugging.
- Only one instance of a gud.el debugger can be active. If you run two, say
*.m debugging and C++ debugging. Then you get odd errors such as the
ebbreak not being recognized by gdb.
To fix these issue, I copied gud.el and made a new namespace "mlgud". I also
removed a lot of unused code from mlgud.el, though there's still more that can
be removed. Now one can debug *.m files and *.cpp files in one Emacs session.
2021-11-22 Uwe Brauer <oub@mat.ucm.es>
* company-matlab-shell.el: 677 correct a silly typo

View File

@ -122,7 +122,7 @@ response from some Emacs based request."
;; Interpret the command.
(cond ((string= "init" cmd)
;; Make sure GUD bindings are available, but do so in
;; the netshell buffer so when gud bundings run, they
;; the netshell buffer so when mlgud bundings run, they
;; don't stomp on C-c matlab-mode bindings.
(with-current-buffer (process-buffer proc)
(matlab-shell-mode-gud-enable-bindings))

View File

@ -21,13 +21,13 @@
;;
;; GUD (grand unified debugger) support for MATLAB shell.
;;
;; Includes setting up gud mode in the shell, and all filters, etc specific
;; to supporting gud.
;; Includes setting up mlgud mode in the shell, and all filters, etc specific
;; to supporting mlgud.
(require 'matlab-shell)
(eval-and-compile
(require 'gud)
(require 'mlgud)
(require 'eieio)
)
@ -52,16 +52,16 @@ Disable this option if the tooltips are too slow in your setup."
(defmacro matlab-at-fcn (cmd)
"Define CMD to be a GUD command that works w/ shell or netshell."
;; Note `arg' comes from gud-def declaration
;; Note `arg' comes from mlgud-def declaration
`(if (matlab-shell-active-p)
(gud-call (concat ,cmd "%%") arg)
(mlgud-call (concat ,cmd "%%") arg)
(if (matlab-netshell-active-p)
(matlab-netshell-eval (gud-format-command ,cmd arg))
(matlab-netshell-eval (mlgud-format-command ,cmd arg))
(error "No MATLAB shell active"))))
(defmacro matlab-gud-fcn (cmd)
"Define CMD forms to be sent to a MATLAB shell."
;; Note `arg' comes from gud-def declaration
;; Note `arg' comes from mlgud-def declaration
`(if gud-matlab-debug-active
(matlab-at-fcn ,cmd)
(error "MATLAB debugging not active")))
@ -70,37 +70,37 @@ Disable this option if the tooltips are too slow in your setup."
(defun matlab-shell-mode-gud-enable-bindings ()
"Enable GUD features for `matlab-shell' in the current buffer."
;; Make sure this is safe to use gud to debug MATLAB
(when (not (fboundp 'gud-def))
(error "Your Emacs is missing `gud-def' which means matlab-shell won't work correctly. Stopping"))
;; Make sure this is safe to use mlgud to debug MATLAB
(when (not (fboundp 'mlgud-def))
(error "Your Emacs is missing `mlgud-def' which means matlab-shell won't work correctly. Stopping"))
(gud-def gud-break (matlab-at-fcn "ebstop in %d%f at %l") "\C-b" "Set breakpoint at current line.")
(gud-def gud-remove (matlab-at-fcn "ebclear in %d%f at %l") "\C-x" "Remove breakpoint at current line.")
(gud-def gud-step (matlab-gud-fcn "dbstep in") "\C-s" "Step one source line, possibly into a function.")
(gud-def gud-next (matlab-gud-fcn "dbstep %p") "\C-n" "Step over one source line.")
(gud-def gud-cont (matlab-gud-fcn "dbcont") "\C-r" "Continue with display.")
(gud-def gud-stop-subjob (matlab-gud-fcn "dbquit") "\C-q" "Quit debugging.") ;; gud toolbar stop
(gud-def gud-finish (matlab-gud-fcn "dbstep out") "\C-f" "Finish executing current function.")
(gud-def gud-up (matlab-gud-fcn "dbup") "<" "Up N stack frames (numeric arg).")
(gud-def gud-down (matlab-gud-fcn "dbdown") ">" "Down N stack frames (numeric arg).")
(gud-def gud-list-breakpoints (matlab-at-fcn "ebstatus") "\C-v" "List breakpoints")
(gud-def gud-show-stack (matlab-at-fcn "ebstack") "\C-w" "Show stack")
;; using (gud-def gud-print "%e" "\C-p" "Eval expression at point") fails
;; (gud-def gud-print "% gud-print not available" "\C-p" "gud-print not available.")
(mlgud-def mlgud-break (matlab-at-fcn "ebstop in %d%f at %l") "Set breakpoint at current line.")
(mlgud-def mlgud-remove (matlab-at-fcn "ebclear in %d%f at %l") "Remove breakpoint at current line.")
(mlgud-def mlgud-step (matlab-gud-fcn "dbstep in") "Step one source line, possibly into a function.")
(mlgud-def mlgud-next (matlab-gud-fcn "dbstep %p") "Step over one source line.")
(mlgud-def mlgud-cont (matlab-gud-fcn "dbcont") "Continue execution.")
(mlgud-def mlgud-stop-subjob (matlab-gud-fcn "dbquit") "Quit debugging.") ;; mlgud toolbar stop
(mlgud-def mlgud-finish (matlab-gud-fcn "dbstep out") "Finish executing current function.")
(mlgud-def mlgud-up (matlab-gud-fcn "dbup") "Up N stack frames (numeric arg).")
(mlgud-def mlgud-down (matlab-gud-fcn "dbdown") "Down N stack frames (numeric arg).")
(mlgud-def mlgud-list-breakpoints (matlab-at-fcn "ebstatus") "List breakpoints")
(mlgud-def mlgud-show-stack (matlab-at-fcn "ebstack") "Show stack")
;; using (mlgud-def mlgud-print "%e" "\C-p" "Eval expression at point") fails
;; (mlgud-def mlgud-print "% mlgud-print not available" "\C-p" "mlgud-print not available.")
(when window-system
(setq gud-matlab-tool-bar-map
(let ((map (make-sparse-keymap)))
(dolist (x '((gud-break . "gud/break")
(gud-remove . "gud/remove")
(gud-cont . "gud/cont")
(gud-next . "gud/next")
(gud-step . "gud/step")
(gud-finish . "gud/finish")
(gud-stop-subjob . "gud/stop")
(dolist (x '((mlgud-break . "gud/break")
(mlgud-remove . "gud/remove")
(mlgud-cont . "gud/cont")
(mlgud-next . "gud/next")
(mlgud-step . "gud/step")
(mlgud-finish . "gud/finish")
(mlgud-stop-subjob . "gud/stop")
(mlg-show-stack . "gud/all")
(gud-list-breakpoints . "describe")
(mlgud-list-breakpoints . "describe")
))
(tool-bar-local-item-from-menu
(car x) (cdr x) map matlab-mode-map))
@ -108,8 +108,8 @@ Disable this option if the tooltips are too slow in your setup."
)
(if (fboundp 'gud-make-debug-menu)
(gud-make-debug-menu))
(if (fboundp 'mlgud-make-debug-menu)
(mlgud-make-debug-menu))
(when (boundp 'tool-bar-map) ; not --without-x
(kill-local-variable 'tool-bar-map))
@ -118,27 +118,25 @@ Disable this option if the tooltips are too slow in your setup."
;;;###autoload
(defun matlab-shell-gud-startup ()
"Configure GUD when a new `matlab-shell' is initialized."
(gud-mode)
(mlgud-mode)
;; type of gud mode
(setq gud-minor-mode 'matlab)
;; type of mlgud mode
(setq mlgud-minor-mode 'matlab)
;; This starts us supporting gud tooltips.
(add-to-list 'gud-tooltip-modes 'matlab-mode)
;; This starts us supporting mlgud tooltips.
(add-to-list 'mlgud-tooltip-modes 'matlab-mode)
(make-local-variable 'gud-marker-filter)
(setq gud-marker-filter 'gud-matlab-marker-filter)
(make-local-variable 'gud-find-file)
(setq gud-find-file 'gud-matlab-find-file)
(make-local-variable 'mlgud-marker-filter)
(setq mlgud-marker-filter 'gud-matlab-marker-filter)
(make-local-variable 'mlgud-find-file)
(setq mlgud-find-file 'gud-matlab-find-file)
;; XEmacs doesn't seem to have this concept already. Oh well.
(make-local-variable 'gud-marker-acc)
(setq gud-marker-acc nil)
(global-matlab-shell-inactive-gud-minor-mode 1)
;; Setup our debug tracker.
(add-hook 'matlab-shell-prompt-appears-hook #'gud-matlab-debug-tracker)
(gud-set-buffer))
(mlgud-set-buffer))
;;; GUD Functions
(defun gud-matlab-massage-args (file args)
@ -157,8 +155,8 @@ FILE is ignored, and ARGS is returned."
f))
(buf (find-file-noselect realfname t)))
(set-buffer buf)
(if (fboundp 'gud-make-debug-menu)
(gud-make-debug-menu))
(if (fboundp 'mlgud-make-debug-menu)
(mlgud-make-debug-menu))
buf)))
@ -167,6 +165,10 @@ FILE is ignored, and ARGS is returned."
;; MATLAB's process filter handles output from the MATLAB process and
;; interprets it for formatting text, and for running the debugger.
(defvar matlab-shell-gud--marker-acc "")
(make-variable-buffer-local 'matlab-shell-gud--marker-acc)
(defvar gud-matlab-marker-regexp-plain-prompt "^K?>>"
"Regular expression for finding a prompt.")
@ -182,20 +184,20 @@ FILE is ignored, and ARGS is returned."
(defun gud-matlab-marker-filter (string)
"Filters STRING for the Unified Debugger based on MATLAB output."
(setq gud-marker-acc (concat gud-marker-acc string))
(setq matlab-shell-gud--marker-acc (concat matlab-shell-gud--marker-acc string))
(let ((output "") (frame nil))
;; ERROR DELIMITERS
;; Newer MATLAB's wrap error text in {^H }^H characters.
;; Convert into something COMINT won't delete so we can scan them.
(while (string-match "{" gud-marker-acc)
(setq gud-marker-acc (replace-match matlab-shell-errortext-start-text t t gud-marker-acc 0)))
(while (string-match "{" matlab-shell-gud--marker-acc)
(setq matlab-shell-gud--marker-acc (replace-match matlab-shell-errortext-start-text t t matlab-shell-gud--marker-acc 0)))
(while (string-match "}" gud-marker-acc)
(setq gud-marker-acc (replace-match matlab-shell-errortext-end-text t t gud-marker-acc 0)))
(while (string-match "}" matlab-shell-gud--marker-acc)
(setq matlab-shell-gud--marker-acc (replace-match matlab-shell-errortext-end-text t t matlab-shell-gud--marker-acc 0)))
;; DEBUG PROMPTS
(when (string-match gud-matlab-marker-regexp-K>> gud-marker-acc)
(when (string-match gud-matlab-marker-regexp-K>> matlab-shell-gud--marker-acc)
;; Newer MATLAB's don't print useful info. We'll have to
;; search backward for the previous line to see if a frame was
@ -206,7 +208,7 @@ FILE is ignored, and ARGS is returned."
;; If no echo, force an echo
"disp(['dbhotlink()%%%' newline]);dbhotlink();\n")))
;;(when matlab-shell-io-testing (message "!!> [%s]" dbhlcmd))
(process-send-string (get-buffer-process gud-comint-buffer) dbhlcmd)
(process-send-string (get-buffer-process mlgud-comint-buffer) dbhlcmd)
)
(setq gud-matlab-dbhotlink t)
)
@ -216,26 +218,26 @@ FILE is ignored, and ARGS is returned."
;; process output. Don't output anything until a K prompt is seen after the display
;; of the dbhotlink command.
(when gud-matlab-dbhotlink
(let ((start (string-match "dbhotlink()%%%" gud-marker-acc))
(let ((start (string-match "dbhotlink()%%%" matlab-shell-gud--marker-acc))
(endprompt nil))
(if start
(progn
(setq output (substring gud-marker-acc 0 start)
gud-marker-acc (substring gud-marker-acc start))
(setq output (substring matlab-shell-gud--marker-acc 0 start)
matlab-shell-gud--marker-acc (substring matlab-shell-gud--marker-acc start))
;; The hotlink text will persist until we see the K prompt.
(when (string-match gud-matlab-marker-regexp-plain-prompt gud-marker-acc)
(when (string-match gud-matlab-marker-regexp-plain-prompt matlab-shell-gud--marker-acc)
(setq endprompt (match-end 0))
;; (when matlab-shell-io-testing (message "!!xx [%s]" (substring gud-marker-acc 0 endprompt)))
;; (when matlab-shell-io-testing (message "!!xx [%s]" (substring matlab-shell-gud--marker-acc 0 endprompt)))
;; We're done with the text!
;; Capture the text that describes the new stack frame.
(save-match-data
(let* ((expr-end (match-beginning 0))
(m1 (string-match "dbhotlink()%%%\n" gud-marker-acc))
(m1 (string-match "dbhotlink()%%%\n" matlab-shell-gud--marker-acc))
(expr-start (match-end 0))
(expression (substring gud-marker-acc expr-start expr-end)))
(expression (substring matlab-shell-gud--marker-acc expr-start expr-end)))
(when (> (length expression) 0)
(condition-case ERR
@ -251,17 +253,17 @@ FILE is ignored, and ARGS is returned."
))
;;Remove it from the accumulator.
(setq gud-marker-acc (substring gud-marker-acc endprompt))
(setq matlab-shell-gud--marker-acc (substring matlab-shell-gud--marker-acc endprompt))
;; If we got all this at the same time, push output back onto the accumulator for
;; the next code bit to push it out.
(setq gud-marker-acc (concat output gud-marker-acc)
(setq matlab-shell-gud--marker-acc (concat output matlab-shell-gud--marker-acc)
output ""
gud-matlab-dbhotlink nil)
))
;; Else, waiting for a link, but hasn't shown up yet.
;; TODO - what can I do here to fix var setting if it gets
;; locked?
(when (string-match gud-matlab-marker-regexp->> gud-marker-acc)
(when (string-match gud-matlab-marker-regexp->> matlab-shell-gud--marker-acc)
;; A non-k prompt showed up. We're not going to get out request.
(setq gud-matlab-dbhotlink nil))
)))
@ -281,23 +283,23 @@ FILE is ignored, and ARGS is returned."
nil
;; Finish off this part of the output. None of our special stuff
;; ends with a \n, so display those as they show up...
(while (string-match "^[^\n]*\n" gud-marker-acc)
(setq output (concat output (substring gud-marker-acc 0 (match-end 0)))
gud-marker-acc (substring gud-marker-acc (match-end 0))))
(while (string-match "^[^\n]*\n" matlab-shell-gud--marker-acc)
(setq output (concat output (substring matlab-shell-gud--marker-acc 0 (match-end 0)))
matlab-shell-gud--marker-acc (substring matlab-shell-gud--marker-acc (match-end 0))))
(if (string-match (concat gud-matlab-marker-regexp-plain-prompt "\\s-*$") gud-marker-acc)
(setq output (concat output gud-marker-acc)
gud-marker-acc ""))
(if (string-match (concat gud-matlab-marker-regexp-plain-prompt "\\s-*$") matlab-shell-gud--marker-acc)
(setq output (concat output matlab-shell-gud--marker-acc)
matlab-shell-gud--marker-acc ""))
;; Check our output for a prompt, and existence of a frame.
;; If this is true, throw out the debug arrow stuff.
(if (and (string-match (concat gud-matlab-marker-regexp->> "\\s-*$") output)
gud-last-last-frame)
mlgud-last-last-frame)
(progn
;; Clean up gud stuff.
;; Clean up mlgud stuff.
(setq overlay-arrow-position nil
gud-last-last-frame nil
gud-overlay-arrow-position nil)
mlgud-last-last-frame nil
mlgud-overlay-arrow-position nil)
;; If stack is showing, clean it up.
(let* ((buff (mlg-set-stack nil))
(win (get-buffer-window buff)))
@ -311,19 +313,19 @@ FILE is ignored, and ARGS is returned."
;; Check for any text that would be embarrassing to display partially.
;; If we don't see any, feel free to dump the rest of the accumulation buffer
(unless (or (string-match (regexp-quote "<a href=") gud-marker-acc)
(string-match (regexp-quote "<EMACSCAP") gud-marker-acc)
(string-match (regexp-quote "<ERROR") gud-marker-acc))
(setq output (concat output gud-marker-acc)
gud-marker-acc "")
(unless (or (string-match (regexp-quote "<a href=") matlab-shell-gud--marker-acc)
(string-match (regexp-quote "<EMACSCAP") matlab-shell-gud--marker-acc)
(string-match (regexp-quote "<ERROR") matlab-shell-gud--marker-acc))
(setq output (concat output matlab-shell-gud--marker-acc)
matlab-shell-gud--marker-acc "")
)
)
(if frame (setq gud-last-frame frame))
(if frame (setq mlgud-last-frame frame))
(when matlab-shell-io-testing
(message "-->[%s] [%s]" output gud-marker-acc))
(message "-->[%s] [%s]" output matlab-shell-gud--marker-acc))
;;(message "Looking for prompt in %S" output)
(when (and (not matlab-shell-suppress-prompt-hooks)
@ -395,8 +397,8 @@ LONGESTNAME specifies the how long the longest name we can expect is."
(let ((file (oref (nth (1- newframe) mlg-stack) file))
(line (oref (nth (1- newframe) mlg-stack) line)))
(if (< line 0) (setq line (- line)))
(setq gud-last-frame (cons file line))
;;(message "Gud FRAME set to %S" gud-last-frame)
(setq mlgud-last-frame (cons file line))
;;(message "Gud FRAME set to %S" mlgud-last-frame)
)
)
@ -825,17 +827,21 @@ Call debug activate/deactivate features."
(beginning-of-line)
(cond
((and gud-matlab-debug-active (looking-at gud-matlab-marker-regexp->>))
;; Debugger was active and we are back at prompt
(setq gud-matlab-debug-active nil)
(when (boundp 'tool-bar-map) ; not --without-x
(with-current-buffer (matlab-shell-active-p) (kill-local-variable 'tool-bar-map)))
(global-matlab-shell-gud-minor-mode -1)
(global-matlab-shell-inactive-gud-minor-mode 1)
(run-hooks 'gud-matlab-debug-deactivate-hook))
((and (not gud-matlab-debug-active) (looking-at gud-matlab-marker-regexp-K>>))
;; Debugger was NOT active and we are now in debug prompt
(setq gud-matlab-debug-active t)
(when (boundp 'tool-bar-map) ; not --without-x
(with-current-buffer (matlab-shell-active-p)
(setq-local tool-bar-map gud-matlab-tool-bar-map)))
(global-matlab-shell-gud-minor-mode 1)
(global-matlab-shell-inactive-gud-minor-mode -1)
(run-hooks 'gud-matlab-debug-activate-hook))
(t
;; All clear
@ -855,89 +861,41 @@ Call debug activate/deactivate features."
(setq key (1+ key)))
(define-key km "h" 'matlab-shell-gud-mode-help)
;; gud bindings.
(define-key km "b" 'gud-break)
(define-key km "x" 'gud-remove)
(define-key km "c" 'gud-cont)
(define-key km "s" 'gud-step)
(define-key km " " 'gud-step)
(define-key km "n" 'gud-next)
(define-key km "f" 'gud-finish)
(define-key km "q" 'gud-stop-subjob)
;(define-key km "u" 'gud-up)
;(define-key km "d" 'gud-down)
(define-key km "<" 'gud-up)
(define-key km ">" 'gud-down)
;; mlgud bindings.
(define-key km "b" 'mlgud-break)
(define-key km "x" 'mlgud-remove)
(define-key km "c" 'mlgud-cont)
(define-key km " " 'mlgud-step)
(define-key km "s" 'mlgud-step)
(define-key km "n" 'mlgud-next)
(define-key km "f" 'mlgud-finish)
(define-key km "q" 'mlgud-stop-subjob)
(define-key km "<" 'mlgud-up)
(define-key km ">" 'mlgud-down)
(define-key km "w" 'mlg-show-stack)
(define-key km "v" 'gud-list-breakpoints)
(define-key km "v" 'mlgud-list-breakpoints)
(define-key km "e" 'matlab-shell-gud-show-symbol-value)
;; (define-key km "p" gud-print)
;;(define-key km "" 'matlab-shell-gud-mode-edit)
(define-key km "\C-x\C-q" 'matlab-shell-gud-mode-edit) ; like toggle-read-only
km)
"Keymap used by matlab mode maintainers.")
;;;###autoload
(define-minor-mode matlab-shell-gud-minor-mode
"Minor mode activated when `matlab-shell' K>> prompt is active.
This minor mode makes MATLAB buffers read only so simple keystrokes
activate debug commands. It also enables tooltips to appear when the
mouse hovers over a symbol when debugging.
\\<matlab-shell-gud-minor-mode-map>
Debug commands are:
\\[matlab-shell-gud-mode-edit] - Edit file (toggle read-only)
Allows editing file without causing MATLAB to exit debug mode.
\\[gud-break] - Add breakpoint (ebstop in FILE at point)
\\[gud-remove] - Remove breakpoint (ebclear in FILE at point)
\\[gud-list-breakpoints] - List breakpoints (ebstatus)
\\[gud-step] - Step (dbstep in)
\\[gud-next] - Next (dbstep)
\\[gud-finish] - Finish function (dbstep out)
\\[gud-cont] - Continue (dbcont)
\\[matlab-shell-gud-show-symbol-value] - Evaluate expression
\\[mlg-show-stack] - Where am I (ebstack)
\\[gud-stop-subjob] - Quit (dbquit)"
nil " MGUD" matlab-shell-gud-minor-mode-map
(defun matlab-shell-gud-mode-help-notice ()
"Default binding for most keys in `matlab-shell-gud-minor-mode'.
Shows a help message in the mini buffer."
(interactive)
(error "MATLAB shell GUD minor-mode: Press 'h' for help, 'e' to go back to editing"))
;; Make the buffer read only
(if matlab-shell-gud-minor-mode
(progn
;; Enable
(when (buffer-file-name) (setq buffer-read-only t))
(when matlab-shell-debug-tooltips-p
(gud-tooltip-mode 1)
(add-hook 'tooltip-functions 'gud-matlab-tooltip-tips)
)
;; Replace gud's toolbar which keeps stomping
;; on our toolbar.
(make-local-variable 'gud-tool-bar-map)
(setq gud-tool-bar-map gud-matlab-tool-bar-map)
)
;; Disable
(when (buffer-file-name)
(setq buffer-read-only (not (file-writable-p (buffer-file-name)))))
(defun matlab-shell-gud-mode-help ()
"Show the default binding for most keys in `matlab-shell-gud-minor-mode'."
(interactive)
(describe-minor-mode 'matlab-shell-gud-minor-mode))
;; Always disable tooltips, in case configured while in the mode.
(gud-tooltip-mode -1)
(remove-hook 'tooltip-functions 'gud-matlab-tooltip-tips)
;; Disable the debug toolboar
(when (boundp 'tool-bar-map) ; not --without-x
(kill-local-variable 'tool-bar-map))
)
)
;;;###autoload
(define-global-minor-mode global-matlab-shell-gud-minor-mode
matlab-shell-gud-minor-mode
(lambda ()
"Should we turn on in this buffer? Only if in a MATLAB mode."
(when (eq major-mode 'matlab-mode)
(matlab-shell-gud-minor-mode 1)))
)
(defun matlab-shell-gud-mode-edit ()
"Turn off `matlab-shell-gud-minor-mode' so you can edit again."
(interactive)
(global-matlab-shell-gud-minor-mode -1))
(defun matlab-shell-gud-show-symbol-value (sym)
"Show the value of the symbol SYM under point from MATLAB shell."
@ -954,39 +912,133 @@ Debug commands are:
(matlab-output-to-temp-buffer "*MATLAB Help*" txt)
(message "Error evaluating MATLAB expression"))))
;;;###autoload
(define-minor-mode matlab-shell-gud-minor-mode
"Minor mode activated when `matlab-shell' K>> prompt is active.
This minor mode makes MATLAB buffers read only so simple keystrokes
activate debug commands. It also enables tooltips to appear when the
mouse hovers over a symbol when debugging.
\\<matlab-shell-gud-minor-mode-map>
Debug commands are:
\\[matlab-shell-gud-mode-edit] - Edit file (toggle read-only)
Allows editing file without causing MATLAB to exit debug mode.
\\[mlgud-break] - Add breakpoint (ebstop in FILE at point)
\\[mlgud-remove] - Remove breakpoint (ebclear in FILE at point)
\\[mlgud-list-breakpoints] - List breakpoints (ebstatus)
\\[mlgud-step] - Step (dbstep in)
\\[mlgud-next] - Next (dbstep)
\\[mlgud-finish] - Finish function (dbstep out)
\\[mlgud-cont] - Continue (dbcont)
\\[matlab-shell-gud-show-symbol-value] - Evaluate expression
\\[mlg-show-stack] - Where am I (ebstack)
\\[mlgud-stop-subjob] - Quit (dbquit)"
nil " MGUD" matlab-shell-gud-minor-mode-map
(defun matlab-shell-gud-mode-edit ()
"Turn off `matlab-shell-gud-minor-mode' so you can edit again."
(interactive)
(global-matlab-shell-gud-minor-mode -1))
;; Make the buffer read only
(if matlab-shell-gud-minor-mode
(progn
;; Enable
(when (buffer-file-name) (setq buffer-read-only t))
(when matlab-shell-debug-tooltips-p
(mlgud-tooltip-mode 1)
(add-hook 'tooltip-functions 'gud-matlab-tooltip-tips)
)
;; Replace mlgud's toolbar which keeps stomping
;; on our toolbar.
(make-local-variable 'mlgud-tool-bar-map)
(setq mlgud-tool-bar-map gud-matlab-tool-bar-map)
)
;; Disable
(when (buffer-file-name)
(setq buffer-read-only (not (file-writable-p (buffer-file-name)))))
(defun matlab-shell-gud-mode-help-notice ()
"Default binding for most keys in `matlab-shell-gud-minor-mode'.
Shows a help message in the mini buffer."
(interactive)
(error "MATLAB shell GUD minor-mode: Press 'h' for help, 'e' to go back to editing"))
;; Always disable tooltips, in case configured while in the mode.
(mlgud-tooltip-mode -1)
(remove-hook 'tooltip-functions 'gud-matlab-tooltip-tips)
(defun matlab-shell-gud-mode-help ()
;; Disable the debug toolboar
(when (boundp 'tool-bar-map) ; not --without-x
(kill-local-variable 'tool-bar-map))))
;;;###autoload
(define-global-minor-mode global-matlab-shell-gud-minor-mode
matlab-shell-gud-minor-mode
(lambda ()
"Should we turn on in this buffer? Only if in a MATLAB mode."
(when (eq major-mode 'matlab-mode)
(matlab-shell-gud-minor-mode 1))))
;;; MATLAB SHELL Inactive GUD Minor Mode
(defvar matlab-shell-inactive-gud-minor-mode-map
(let ((km (make-sparse-keymap)))
(define-key km "\C-c\C-d\C-h" 'matlab-shell-inactive-gud-mode-help)
;; mlgud bindings when debugger is inactive. When inactive, only bindings such as mlgud-break
;; make sense. However, we also keep these bindings when the debugger is active for consistency.
(define-key km (kbd "C-c C-d b") 'mlgud-break)
(define-key km (kbd "C-c C-d x") 'mlgud-remove)
(define-key km (kbd "C-c C-d c") 'mlgud-cont)
(define-key km (kbd "C-c C-d SPC") 'mlgud-step)
(define-key km (kbd "C-c C-d s") 'mlgud-step)
(define-key km (kbd "C-c C-d n") 'mlgud-next)
(define-key km (kbd "C-c C-d f") 'mlgud-finish)
(define-key km (kbd "C-c C-d q") 'mlgud-stop-subjob)
(define-key km (kbd "C-c C-d <") 'mlgud-up)
(define-key km (kbd "C-c C-d >") 'mlgud-down)
(define-key km (kbd "C-c C-d w") 'mlg-show-stack)
(define-key km (kbd "C-c C-d v") 'mlgud-list-breakpoints)
(define-key km (kbd "C-c C-d e") 'matlab-shell-gud-show-symbol-value)
km)
"Keymap used by matlab mode maintainers.")
;;;###autoload
(define-minor-mode matlab-shell-inactive-gud-minor-mode
"Minor mode activated when `matlab-shell' K>> prompt is inactive.
\\<matlab-shell-inactive-gud-minor-mode-map>
Debug commands are:
\\[mlgud-break] - Add breakpoint (ebstop in FILE at point)
\\[mlgud-remove] - Remove breakpoint (ebclear in FILE at point)
\\[mlgud-list-breakpoints] - List breakpoints (ebstatus)
"
nil " I-MGUD" matlab-shell-inactive-gud-minor-mode-map
;; Always disable tooltips, in case configured while in the mode.
(mlgud-tooltip-mode -1)
(remove-hook 'tooltip-functions 'gud-matlab-tooltip-tips)
(when (boundp 'tool-bar-map) ; not --without-x
(kill-local-variable 'tool-bar-map)))
(defun matlab-shell-inactive-gud-mode-help ()
"Show the default binding for most keys in `matlab-shell-gud-minor-mode'."
(interactive)
(describe-minor-mode 'matlab-shell-gud-minor-mode)
)
(describe-minor-mode 'matlab-shell-gud-minor-mode))
;;;###autoload
(define-global-minor-mode global-matlab-shell-inactive-gud-minor-mode
matlab-shell-inactive-gud-minor-mode
(lambda ()
"Should we turn on in this buffer? Only if in a MATLAB mode."
(when (eq major-mode 'matlab-mode)
(matlab-shell-inactive-gud-minor-mode 1))))
;;; Tooltips
;;
;; Using the gud tooltip feature for a bunch of setup, but then
;; Using the mlgud tooltip feature for a bunch of setup, but then
;; just override the tooltip fcn (see the mode) with this function
;; as an additional piece.
(defun gud-matlab-tooltip-tips (event)
"Implementation of the tooltip feature for MATLAB.
Much of this was copied from `gud-tooltip-tips'.
Much of this was copied from `mlgud-tooltip-tips'.
This function must return nil if it doesn't handle EVENT."
(when (and (eventp event) (tooltip-event-buffer event))
(with-current-buffer (tooltip-event-buffer event)
(when (and gud-tooltip-mode
(when (and mlgud-tooltip-mode
matlab-shell-gud-minor-mode
(buffer-name gud-comint-buffer) ; might be killed
(buffer-name mlgud-comint-buffer) ; might be killed
)
(let ((expr (matlab-shell-gud-find-tooltip-expression event))
(txt nil))
@ -997,7 +1049,7 @@ This function must return nil if it doesn't handle EVENT."
(when (not (string-match "ERRORTXT" txt))
(tooltip-show (concat expr "=\n" txt)
(or gud-tooltip-echo-area
(or mlgud-tooltip-echo-area
tooltip-use-echo-area
(not tooltip-mode)))
t)))))))
@ -1055,6 +1107,6 @@ if it looks like a function call, it will return nil."
;; LocalWords: COMINT errortext dbhlcmd comint endprompt mello mlg EMACSCAP
;; LocalWords: defclass initarg defmethod longestname namefmt propertize oref
;; LocalWords: newstack nreverse newframe namelen cnt prev MStack BP del NBPS
;; LocalWords: defface bp oset ol eol overlayp MBreakpoints MGUD gud's
;; LocalWords: defface bp oset ol eol overlayp MBreakpoints MGUD mlgud's
;; LocalWords: toolboar minibuffer ERRORTXT eventp emacstipstring posn pstate
;; LocalWords: ppss sexp

View File

@ -31,7 +31,7 @@
(require 'server)
(eval-and-compile
(require 'gud)
(require 'mlgud)
(require 'shell)
)
@ -563,7 +563,7 @@ Try C-h f matlab-shell RET"))
;;; PROCESS FILTERS & SENTINEL
;;
;; These are wrappers around the GUD filters so we can pre and post process
;; decisions by comint and gud.
;; decisions by comint and mlgud.
(defvar matlab-shell-capturetext-start-text "<EMACSCAP>"
"Text used as simple signal for text that should be captured.")
(defvar matlab-shell-capturetext-end-text "</EMACSCAP>"
@ -635,7 +635,7 @@ STRING is the recent output from PROC to be filtered."
matlab-shell-flush-accumulation-buffer nil))
(with-current-buffer buff
(gud-filter proc string))
(mlgud-filter proc string))
;; In case things get switched around on us
(with-current-buffer buff
@ -656,7 +656,7 @@ PROC is the function which experienced a change in state.
STRING is a description of what happened."
(let ((buff (process-buffer proc)))
(with-current-buffer buff
(gud-sentinel proc string))))
(mlgud-sentinel proc string))))
;;; COMINT support fcns
;;
@ -1933,8 +1933,8 @@ If DEBUG is non-nil, then setup GUD debugging features."
(goto-char (point-min))
(forward-line (1- (string-to-number el)))
(when debug
(setq gud-last-frame (cons (buffer-file-name) (string-to-number el)))
(gud-display-frame))
(setq mlgud-last-frame (cons (buffer-file-name) (string-to-number el)))
(mlgud-display-frame))
(setq ec (string-to-number ec))
(if (> ec 0) (forward-char (1- ec)))))
@ -1953,7 +1953,7 @@ If DEBUG is non-nil, then setup GUD debugging features."
(matlab-find-other-window-file-line-column ef el ec debug)))
((string-match "^matlab:*\\(.*\\)$" url)
(process-send-string
(get-buffer-process gud-comint-buffer)
(get-buffer-process mlgud-comint-buffer)
(concat (substring url (match-beginning 1) (match-end 1)) "\n")))))
(defun matlab-shell-last-error ()
@ -2413,12 +2413,13 @@ Return the name of the temporary file."
(goto-char (point-min))
(dolist (F functions)
(save-excursion
;; Copy all local functions to script.
(when (re-search-forward (semantic-tag-name F) nil t)
;; Found, copy it in.
(let ((ft (matlab-semantic-tag-text F orig)))
(goto-char (point-max))
(insert "% Copy of " (semantic-tag-name F) "\n\n")
(insert ft)
(insert "\n%%\n")))
(insert "\n%%\n"))))
)
;; Save buffer, and setup ability to run this new script.
@ -2460,31 +2461,31 @@ Argument FNAME specifies if we should echo the region to the command line."
;;; matlab-shell.el ends here
;; LocalWords: el Ludlam zappo compat comint gud Slience defcustom el cb
;; LocalWords: el Ludlam zappo compat comint mlgud Slience defcustom el cb
;; LocalWords: nodesktop defface autostart netshell emacsclient errorscanning
;; LocalWords: cco defun setq Keymaps keymap kbd featurep fboundp subprocess
;; LocalWords: online EDU postoutput progn subjob eol mlfile emacsinit msbn pc
;; LocalWords: Thx Chappaz windowid dirtrackp dbhot erroexamples Ludlam zappo
;; LocalWords: compat comint gud Slience defcustom nodesktop defface emacscd
;; LocalWords: compat comint mlgud Slience defcustom nodesktop defface emacscd
;; LocalWords: autostart netshell emacsclient errorscanning cco defun setq el
;; LocalWords: Keymaps keymap kbd featurep fboundp subprocess online EDU
;; LocalWords: postoutput progn subjob eol mlfile emacsinit msbn pc Thx Ludlam
;; LocalWords: Chappaz windowid dirtrackp dbhot erroexamples cdr ENDPT dolist
;; LocalWords: overlaystack mref deref errortext ERRORTXT Missmatched zappo
;; LocalWords: shellerror dbhotlink realfname aset buf noselect tcp auth ef
;; LocalWords: dbhotlinks compat comint gud Slience defcustom capturetext
;; LocalWords: shellerror dbhotlink realfname aset buf noselect auth ef
;; LocalWords: dbhotlinks compat comint mlgud Slience defcustom capturetext
;; LocalWords: nodesktop defface autostart netshell emacsclient errorscanning
;; LocalWords: cco defun setq Keymaps keymap kbd featurep fboundp subprocess
;; LocalWords: online EDU postoutput progn subjob eol mlfile emacsinit msbn pc
;; LocalWords: Thx Chappaz windowid dirtrackp dbhot erroexamples cdr ENDPT
;; LocalWords: dolist overlaystack mref deref errortext ERRORTXT Missmatched
;; LocalWords: shellerror dbhotlink realfname aset buf noselect tcp auth ef
;; LocalWords: shellerror dbhotlink realfname aset buf noselect auth ef
;; LocalWords: dbhotlinks dbhlcmd endprompt mello pmark memq promptend
;; LocalWords: numchars integerp emacsdocomplete mycmd ba nreverse EMACSCAP
;; LocalWords: emacsdocompletion subfield fil byteswap stringp cbuff mapcar bw
;; LocalWords: FCN's alist BUILTINFLAG dired bol bobp numberp lattr princ
;; LocalWords: minibuffer fn matlabregex stackexchange doesnt lastcmd Emacsen
;; LocalWords: notimeout stacktop eltest testme localfcn LF mlx meth fileref
;; LocalWords: notimeout stacktop eltest testme localfcn LF meth fileref
;; LocalWords: funcall ec basec sk ignoredups boundp nondirectory edir sexp iq
;; LocalWords: Fixup mapc ltype noshow emacsrunregion cnt commandline elipsis
;; LocalWords: newf bss fname nt initcmd nsa ecc ecca clientcmd buffname

View File

@ -594,25 +594,25 @@ point, but it will be restored for them."
["Edit File (toggle read-only)" matlab-shell-gud-mode-edit
:help "Exit MATLAB debug minor mode to edit without exiting MATLAB's K>> prompt."
:visible gud-matlab-debug-active ]
["Add Breakpoint (ebstop in FILE at point)" gud-break
["Add Breakpoint (ebstop in FILE at point)" mlgud-break
:active (matlab-shell-active-p)
:help "When MATLAB debugger is active, set break point at current M-file point"]
["Remove Breakpoint (ebclear in FILE at point)" gud-remove
["Remove Breakpoint (ebclear in FILE at point)" mlgud-remove
:active (matlab-shell-active-p)
:help "Show all active breakpoints in a separate buffer." ]
["List Breakpoints (ebstatus)" gud-list-breakpoints
:help "When MATLAB debugger is active, remove break point in FILE at point." ]
["List Breakpoints (ebstatus)" mlgud-list-breakpoints
:active (matlab-shell-active-p)
:help "List active breakpoints."]
["Step (dbstep in)" gud-step
["Step (dbstep in)" mlgud-step
:active gud-matlab-debug-active
:help "When MATLAB debugger is active, step into line"]
["Next (dbstep)" gud-next
["Next (dbstep)" mlgud-next
:active gud-matlab-debug-active
:help "When MATLAB debugger is active, step one line"]
["Finish function (dbstep out)" gud-finish
["Finish function (dbstep out)" mlgud-finish
:active gud-matlab-debug-active
:help "When MATLAB debugger is active, run to end of function"]
["Continue (dbcont)" gud-cont
["Continue (dbcont)" mlgud-cont
:active gud-matlab-debug-active
:help "When MATLAB debugger is active, run to next break point or finish"]
["Evaluate Expression" matlab-shell-gud-show-symbol-value
@ -621,14 +621,14 @@ point, but it will be restored for them."
["Show Stack" mlg-show-stack
:active gud-matlab-debug-active
:help "When MATLAB debugger is active, show the stack in a buffer."]
;;; Advertise these more if we can get them working w/ gud's frame show.
;;; ["Up Call Stack (dbup)" gud-up
;;; Advertise these more if we can get them working w/ mlgud's frame show.
;;; ["Up Call Stack (dbup)" mlgud-up
;;; :active gud-matlab-debug-active
;;; :help "When MATLAB debugger is active and at break point, go up a frame"]
;;; ["Down Call Stack (dbdown)" gud-down
;;; ["Down Call Stack (dbdown)" mlgud-down
;;; :active gud-matlab-debug-active
;;; :help "When MATLAB debugger is active and at break point, go down a frame"]
["Quit debugging (dbquit)" gud-stop-subjob
["Quit debugging (dbquit)" mlgud-stop-subjob
:active gud-matlab-debug-active
:help "When MATLAB debugger is active, stop debugging"]
)
@ -3243,10 +3243,10 @@ desired. Optional argument FAST is not used."
;;; matlab.el ends here
;; LocalWords: el Wette mwette caltech edu Ludlam eludlam defconst online mfiles ebstop ebclear
;; LocalWords: compat easymenu defcustom CASEINDENT COMMANDINDENT sexp defun ebstatus mlg gud's
;; LocalWords: compat easymenu defcustom CASEINDENT COMMANDINDENT sexp defun ebstatus mlg mlgud's
;; LocalWords: mmode setq progn sg Fns Alist elipsis vf functionname vers subjob flb fle elisp
;; LocalWords: minibuffer featurep fboundp facep zmacs defface cellbreak bcend lastcompute noblock
;; LocalWords: cellbreaks overline keymap torkel ispell gud allstring strchar decl lcbounds setcar
;; LocalWords: cellbreaks overline keymap torkel ispell mlgud allstring strchar decl lcbounds setcar
;; LocalWords: bs eu bc ec searchlim eol charvec Matchers ltype cdr if'd setcdr bcwrapped
;; LocalWords: uicontext setcolor mld keywordlist mapconcat pragmas Classdefs
;; LocalWords: dem Za Imenu imenu alist prog reindent unindent boundp fn

1298
mlgud.el Normal file

File diff suppressed because it is too large Load Diff