Rearrange db/debug initfiles
This commit is contained in:
parent
9ee28fda89
commit
8b83c03782
7 changed files with 53 additions and 50 deletions
|
@ -1,4 +1,4 @@
|
|||
;;; module-db.el
|
||||
;;; custom-db.el
|
||||
|
||||
(use-package sql-mode
|
||||
:mode "\\.sql$"
|
||||
|
@ -39,5 +39,5 @@ open comint."
|
|||
(sql-product-interactive product 0)
|
||||
(message "Started new %s connection" product)))))
|
||||
|
||||
(provide 'module-db)
|
||||
;;; module-db.el ends here
|
||||
(provide 'custom-db)
|
||||
;;; custom-db.el ends here
|
41
modules/custom-debug.el
Normal file
41
modules/custom-debug.el
Normal file
|
@ -0,0 +1,41 @@
|
|||
;;; custom-debug.el --- debugging with `realgud'
|
||||
|
||||
(after! debug
|
||||
;; For elisp debugging
|
||||
(map! :map debugger-mode-map
|
||||
:n "RET" 'debug-help-follow
|
||||
:n "n" 'debugger-step-through
|
||||
:n "c" 'debugger-continue))
|
||||
|
||||
(use-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
|
||||
(def-popup! "\\`\\*\\(g\\|zsh\\|bash\\)db.*?\\*\\'" :size 20 :regexp t)
|
||||
(def-popup! "\\`\\*trepanjs.*?\\*\\'" :size 20 :regexp t)
|
||||
|
||||
;; 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))
|
||||
|
||||
;; TODO does this work with shackle?
|
||||
(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.
|
||||
(advice-add 'realgud:run-process :override 'doom*realgud:run-process))
|
||||
|
||||
(provide 'custom-debug)
|
||||
;;; custom-debug.el ends here
|
97
modules/defuns/defuns-quickrun.el
Normal file
97
modules/defuns/defuns-quickrun.el
Normal file
|
@ -0,0 +1,97 @@
|
|||
;;; defuns-quickrun.el
|
||||
|
||||
;;;; Code building ;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;###autoload
|
||||
(defvar doom--build-command '("make %s" . "Makefile"))
|
||||
(make-variable-buffer-local 'doom--build-command)
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/set-build-command (command &optional file)
|
||||
(when (or (null file)
|
||||
(doom/project-has-files file))
|
||||
(setq doom--build-command `(,command . ,file))))
|
||||
|
||||
;;;###autoload (autoload 'doom:build "defuns-quickrun" nil t)
|
||||
(evil-define-command doom:build (arg)
|
||||
"Call a build command in the current directory. If ARG is nil this function calls
|
||||
`recompile', otherwise it calls `compile' passing ARG as build command."
|
||||
(interactive "<sh>")
|
||||
(when (null doom--build-command)
|
||||
(user-error "No build command was set"))
|
||||
(let ((build-file (cdr doom--build-command))
|
||||
(build-cmd (car doom--build-command))
|
||||
(project-dir (doom/project-root)))
|
||||
(if (or (null build-file) (f-exists? (f-expand build-file project-dir)))
|
||||
(if (or (symbolp build-cmd) (functionp build-cmd))
|
||||
(if (commandp build-cmd)
|
||||
(call-interactively build-cmd)
|
||||
(funcall build-cmd))
|
||||
(let ((default-directory project-dir))
|
||||
(compile (format build-cmd (or arg "")))))
|
||||
(error "Could not build!"))))
|
||||
|
||||
;;;; Code running ;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;###autoload (autoload 'doom:eval-buffer "defuns-quickrun" nil t)
|
||||
(evil-define-command doom:eval-buffer ()
|
||||
"Evaluate the whole buffer."
|
||||
:move-point nil :repeat nil
|
||||
(interactive)
|
||||
(cond ((eq major-mode 'emacs-lisp-mode)
|
||||
(doom:eval-region (point-min) (point-max)))
|
||||
(t (quickrun))))
|
||||
|
||||
;;;###autoload (autoload 'doom:eval-region "defuns-quickrun" nil t)
|
||||
(evil-define-operator doom:eval-region (beg end)
|
||||
"Evaluate a region and, if large enough, prints its output to a popup buffer (if an
|
||||
elisp buffer). Otherwise forward the region to Quickrun."
|
||||
:move-point nil :repeat nil
|
||||
(interactive "<r>")
|
||||
(cond ((eq major-mode 'emacs-lisp-mode)
|
||||
(require 'pp)
|
||||
(let ((result (eval (read (buffer-substring-no-properties beg end))))
|
||||
lines)
|
||||
(let ((buf (get-buffer-create "*eval*")))
|
||||
(with-current-buffer buf
|
||||
(read-only-mode -1)
|
||||
(setq-local scroll-margin 0)
|
||||
(erase-buffer)
|
||||
(prin1 result buf)
|
||||
(emacs-lisp-mode)
|
||||
(pp-buffer)
|
||||
(read-only-mode 1)
|
||||
(setq lines (count-lines (point-min) (point-max)))
|
||||
(goto-char (point-min))
|
||||
(when (< lines 5)
|
||||
(message "%s" (buffer-substring (point-min) (point-max)))
|
||||
(kill-buffer buf)))
|
||||
(unless (< lines 5)
|
||||
(doom/popup-buffer buf)))))
|
||||
(t (quickrun-region beg end))))
|
||||
|
||||
;;;###autoload (autoload 'doom:eval-region-and-replace "defuns-quickrun" nil t)
|
||||
(evil-define-operator doom:eval-region-and-replace (beg end)
|
||||
(interactive "<r>")
|
||||
(cond ((eq major-mode 'emacs-lisp-mode)
|
||||
(kill-region beg end)
|
||||
(condition-case nil
|
||||
(prin1 (eval (read (current-kill 0)))
|
||||
(current-buffer))
|
||||
(error (message "Invalid expression")
|
||||
(insert (current-kill 0)))))
|
||||
(t (quickrun-replace-region beg end))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom*quickrun-close-popup (&optional _ _ _ _)
|
||||
"Allows us to re-run quickrun from inside the quickrun buffer."
|
||||
(awhen (get-buffer-window quickrun/buffer-name)
|
||||
(shut-up! (quickrun/kill-running-process))
|
||||
(doom/popup-close it nil t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom|quickrun-after-run ()
|
||||
"Ensures window is scrolled to BOF"
|
||||
(with-selected-window (get-buffer-window quickrun/buffer-name)
|
||||
(goto-char (point-min))))
|
||||
|
||||
(provide 'defuns-quickrun)
|
||||
;;; defuns-quickrun.el ends here
|
73
modules/defuns/defuns-realgud.el
Normal file
73
modules/defuns/defuns-realgud.el
Normal file
|
@ -0,0 +1,73 @@
|
|||
;;; defuns-realgud.el
|
||||
|
||||
;; TODO Find a more elegant solution
|
||||
;; FIXME Causes realgud:cmd-* to focus popup on every invocation
|
||||
;;;###autoload
|
||||
(defun doom*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") 'doom/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))))))))
|
||||
;; else
|
||||
(progn
|
||||
(if cmd-buf (switch-to-buffer cmd-buf))
|
||||
(message "Error running command: %s" (mapconcat 'identity cmd-args " ")))))
|
||||
cmd-buf))
|
||||
|
||||
|
||||
;;;###autoload (autoload 'doom:debug-toggle-breakpoint "defuns-realgud" nil t)
|
||||
(evil-define-command doom:debug-toggle-breakpoint (&optional bang)
|
||||
(interactive "<!>")
|
||||
(call-interactively (if bang 'realgud:cmd-clear 'realgud:cmd-break)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom/debug-quit ()
|
||||
(interactive)
|
||||
(ignore-errors (call-interactively 'realgud:cmd-quit))
|
||||
(doom/popup-close)
|
||||
(evil-normal-state))
|
||||
|
||||
;;;###autoload (autoload 'doom:debug "defuns-realgud" nil t)
|
||||
(evil-define-command doom:debug (&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)))))
|
||||
|
||||
|
||||
(provide 'defuns-realgud)
|
||||
;;; defuns-realgud.el ends here
|
Loading…
Add table
Add a link
Reference in a new issue