Add modules/feature/debug
This commit is contained in:
parent
77ce31d8e0
commit
9173d79eb8
3 changed files with 113 additions and 0 deletions
42
modules/feature/debug/autoload.el
Normal file
42
modules/feature/debug/autoload.el
Normal file
|
@ -0,0 +1,42 @@
|
|||
;;; feature/debug/autoload.el
|
||||
|
||||
;;;###autoload
|
||||
(defun +debug/quit ()
|
||||
(interactive)
|
||||
(ignore-errors (call-interactively 'realgud:cmd-quit))
|
||||
(doom/popup-close)
|
||||
(evil-normal-state))
|
||||
|
||||
|
||||
;;;###autoload (autoload '+debug:debug-toggle-breakpoint "feature/debug/autoload" nil t)
|
||||
;;;###autoload (autoload '+debug:run "feature/debug/autoload" nil t)
|
||||
|
||||
(@after evil
|
||||
(evil-define-command +debug:run (&optional path)
|
||||
"Initiate debugger for current major mode"
|
||||
(interactive "<f>")
|
||||
(let ((default-directory (doom-project-root)))
|
||||
(cond ((memq major-mode '(c-mode c++-mode))
|
||||
(realgud:gdb (if path (concat "gdb " path))))
|
||||
((memq major-mode '(ruby-mode enh-ruby-mode))
|
||||
(doom:repl nil (format "run '%s'" (f-filename (or path buffer-file-name)))))
|
||||
((eq major-mode 'sh-mode)
|
||||
(let ((shell sh-shell))
|
||||
(when (string= shell "sh")
|
||||
(setq shell "bash"))
|
||||
(cond ((string= shell "bash")
|
||||
(realgud:bashdb (if path (concat "bashdb " path))))
|
||||
((string= shell "zsh")
|
||||
(realgud:zshdb (if path (concat "zshdb " path))))
|
||||
(t (user-error "No shell debugger for %s" shell)))))
|
||||
;; TODO Add python debugging
|
||||
((memq major-mode '(js-mode js2-mode js3-mode))
|
||||
(realgud:trepanjs))
|
||||
((eq major-mode 'haskell-mode)
|
||||
(haskell-debug))
|
||||
(t (user-error "No debugger for %s" major-mode)))))
|
||||
|
||||
(evil-define-command +debug:debug-toggle-breakpoint (&optional bang)
|
||||
(interactive "<!>")
|
||||
(call-interactively (if bang 'realgud:cmd-clear 'realgud:cmd-break))))
|
||||
|
67
modules/feature/debug/config.el
Normal file
67
modules/feature/debug/config.el
Normal file
|
@ -0,0 +1,67 @@
|
|||
;;; feature/debug/config.el
|
||||
|
||||
(@after debug
|
||||
;; For elisp debugging
|
||||
(@map :map debugger-mode-map
|
||||
:n "RET" 'debug-help-follow
|
||||
:n "n" 'debugger-step-through
|
||||
:n "c" 'debugger-continue))
|
||||
|
||||
|
||||
(@def-package realgud
|
||||
:commands (realgud:gdb realgud:trepanjs realgud:bashdb realgud:zshdb)
|
||||
:config
|
||||
(@map :map realgud:shortkey-mode-map
|
||||
:n "j" 'evil-next-line
|
||||
:n "k" 'evil-previous-line
|
||||
:n "h" 'evil-backward-char
|
||||
:n "l" 'evil-forward-char
|
||||
:m "n" 'realgud:cmd-next
|
||||
:m "b" 'realgud:cmd-break
|
||||
:m "B" 'realgud:cmd-clear
|
||||
:n "c" 'realgud:cmd-continue)
|
||||
|
||||
;; Popup rules
|
||||
(@set :popup
|
||||
'("^\\*\\(g\\|zsh\\|bash\\)db.*?\\*$" :size 20 :regexp t)
|
||||
'("^\\*trepanjs.*?\\*$" :size 20 :regexp t))
|
||||
|
||||
;; TODO Temporary Ex commands for the debugger
|
||||
;; (def-tmp-excmd! doom:def-debug-on doom:def-debug-off
|
||||
;; ("n[ext]" . realgud:cmd-next)
|
||||
;; ("s[tep]" . realgud:cmd-step)
|
||||
;; ("b[reak]" . doom:debug-toggle-breakpoint)
|
||||
;; ("c[ontinue]" . realgud:cmd-continue))
|
||||
;; (advice-add 'realgud-cmdbuf-init :after 'doom:def-debug-on)
|
||||
;; (advice-add 'realgud:cmd-quit :after 'doom:def-debug-off)
|
||||
|
||||
;; Monkey-patch `realgud:run-process' to run in a popup.
|
||||
;; TODO Find a more elegant solution
|
||||
;; FIXME Causes realgud:cmd-* to focus popup on every invocation
|
||||
(defun +debug*realgud-run-process
|
||||
(debugger-name script-filename cmd-args minibuffer-history &optional no-reset)
|
||||
(let ((cmd-buf))
|
||||
(setq cmd-buf
|
||||
(apply 'realgud-exec-shell debugger-name script-filename
|
||||
(car cmd-args) no-reset (cdr cmd-args)))
|
||||
(let ((process (get-buffer-process cmd-buf)))
|
||||
(if (and process (eq 'run (process-status process)))
|
||||
(progn
|
||||
(pop-to-buffer cmd-buf)
|
||||
(define-key evil-emacs-state-local-map (kbd "ESC ESC") '+debug/quit)
|
||||
(realgud:track-set-debugger debugger-name)
|
||||
(realgud-cmdbuf-info-in-debugger?= 't)
|
||||
(realgud-cmdbuf-info-cmd-args= cmd-args)
|
||||
(when cmd-buf
|
||||
(switch-to-buffer cmd-buf)
|
||||
(when realgud-cmdbuf-info
|
||||
(let* ((info realgud-cmdbuf-info)
|
||||
(cmd-args (realgud-cmdbuf-info-cmd-args info))
|
||||
(cmd-str (mapconcat 'identity cmd-args " ")))
|
||||
(set minibuffer-history
|
||||
(list-utils-uniq (cons cmd-str (eval minibuffer-history))))))))
|
||||
(if cmd-buf (switch-to-buffer cmd-buf))
|
||||
(message "Error running command: %s" (mapconcat 'identity cmd-args " "))))
|
||||
cmd-buf))
|
||||
(advice-add 'realgud:run-process :override '+debug*realgud-run-process))
|
||||
|
4
modules/feature/debug/packages.el
Normal file
4
modules/feature/debug/packages.el
Normal file
|
@ -0,0 +1,4 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; feature/debug/packages.el
|
||||
|
||||
(@package realgud)
|
Loading…
Add table
Add a link
Reference in a new issue