emacs-lisp: add support for debugger and edebug

Make edebug key bindings work in normal state.
Add evilification of debugger stack trace buffers.
This commit is contained in:
syl20bnr 2017-02-11 16:31:56 -05:00
parent 64e0787123
commit 6e713ed89f
3 changed files with 71 additions and 4 deletions

View File

@ -8,8 +8,9 @@
- [[#auto-compile][Auto-compile]]
- [[#working-with-lisp-files-barfage-slurpage--more][Working with lisp files (barfage, slurpage & more)]]
- [[#key-bindings][Key bindings]]
- [[#smartparens][smartparens]]
- [[#srefactor][srefactor]]
- [[#additional-evualation-functions][Additional evualation functions]]
- [[#format-code][Format code]]
- [[#debugging][Debugging]]
* Description
This layer gathers all the configuration related to emacs-lisp. This should
@ -63,7 +64,7 @@ As this state works the same for all files, the documentation is in global
| ~SPC m t q~ | run =ert= |
| ~SPC m d m~ | open [[https://github.com/joddie/macrostep][macrostep]] transient-state |
** smartparens
** Additional evualation functions
If =smartparens= is used the following additional key bindings are available:
| Key Binding | Description |
@ -71,7 +72,7 @@ If =smartparens= is used the following additional key bindings are available:
| ~SPC m e c~ | evaluate sexp around point |
| ~SPC m e s~ | evaluate symbol around point |
** srefactor
** Format code
The [[file:../../semantic/README.org][semantic]] layer should be installed for these key bindings to become active.
| Key Binding | Description |
@ -80,3 +81,11 @@ The [[file:../../semantic/README.org][semantic]] layer should be installed for t
| ~SPC m = f~ | format current function |
| ~SPC m = o~ | format all on one line |
| ~SPC m = s~ | format current sexp |
** Debugging
| Key Binding | Description |
|-------------+------------------------------------------------------------------------|
| ~SPC m d f~ | on a =defun= symbol toggle on the instrumentalisation of the function |
| ~SPC m d F~ | on a =defun= symbol toggle off the instrumentalisation of the function |
| ~SPC m d t~ | insert =(debug)= to print the stack trace and re-evaluate the function |

View File

@ -30,6 +30,40 @@
(find-variable-other-window symb)
(find-function-at-point))))
;; edebug
(defun spacemacs/edebug-instrument-defun-on ()
"Toggle on instrumentalisation for the function under `defun'."
(interactive)
(eval-defun 'edebugit))
(defun spacemacs/edebug-instrument-defun-off ()
"Toggle on instrumentalisation for the function under `defun'."
(interactive)
(eval-defun))
(defun spacemacs/elisp-toggle-debug-expr-and-eval-func ()
"Insert or remove debug expression, evaluate function and save buffer."
(interactive)
(let ((trace "(debug)")
(line (thing-at-point 'line)))
(if (and line (string-match trace line))
(kill-whole-line)
(progn
(back-to-indentation)
(insert trace)
(newline-and-indent))))
(eval-defun nil)
(save-buffer))
(defun spacemacs//edebug-hook ()
"Hook for `edebug-mode'."
(evil-normalize-keymaps)
(when (and (fboundp 'golden-ratio-mode)
golden-ratio-mode)
(golden-ratio)))
;; smartparens integration

View File

@ -13,6 +13,8 @@
'(
auto-compile
company
(debug :location built-in)
(edebug :location built-in)
eldoc
elisp-slime-nav
(emacs-lisp :location built-in)
@ -51,6 +53,28 @@
(spacemacs|add-company-backends :backends (company-files company-capf)
:modes ielm-mode))
(defun emacs-lisp/init-debug ()
(use-package debug
:defer t
:init (dolist (mode '(emacs-lisp-mode lisp-interaction-mode))
(spacemacs/declare-prefix-for-mode mode "md" "debug")
(spacemacs/set-leader-keys-for-major-mode 'emacs-lisp-mode
"dt" 'spacemacs/elisp-toggle-debug-expr-and-eval-func))
:config (evilified-state-evilify-map debugger-mode-map
:mode debugger-mode)))
(defun emacs-lisp/init-edebug ()
(use-package edebug
:defer t
:init
(progn
(dolist (mode '(emacs-lisp-mode lisp-interaction-mode))
(spacemacs/set-leader-keys-for-major-mode 'emacs-lisp-mode
"df" 'spacemacs/edebug-instrument-defun-on
"dF" 'spacemacs/edebug-instrument-defun-off))
;; assure that edebug key bindings are effective
(add-hook 'edebug-mode-hook 'spacemacs//edebug-hook t))))
(defun emacs-lisp/post-init-eldoc ()
(add-hook 'emacs-lisp-mode-hook 'eldoc-mode))