Cider offers very useful debugger for clojure code. Once you enter the debugger, you can step through it with keys like (n)ext, (o)ut, etc., like so. Using evil, the problem is that if I enter this debugger in normal-state, those keypresses will never make it to cider-debug, as evil interprets them according to its own keymap.

One way to reconcile this would be to automatically enter insert state when cider-interactive-eval (how you enter the debugger) is called and cider--debug-mode is active.

Here's how I imagine it would be, but it doesn't work yet. How can I improve this?

(defadvice cider-interactive-eval (after enter-insert-for-dbg activate)
  "When cider-eval takes you to a dbg session, enter insert-state."
  (when (and (bound-and-true-p cider--debug-mode)
             (eq evil-state 'normal))
    (evil-insert 1)))

(ad-activate 'cider-interactive-eval)
  • Have you tried setting the initial mode tho emacs-state (or insert-state)? (add-to-list 'evil-emacs-state-modes 'cider--debug-mode). – Dan Mar 7 '16 at 13:28

You should be able to add cider--debug-mode to the evil-insert-state-modes list so that you automatically enter insert state when the debugger is triggered. I tried the following but it doesn't work.

(add-to-list 'evil-insert-state-modes 'cider--debug-mode)

I haven't dug into why this isn't working, but for the time being I'm using the cider--debug-mode-hook which is called whenever you enter or leave the mode.

(defun my-cider-debug-toggle-insert-state ()
  (if cider--debug-mode    ;; Checks if you're entering the debugger   
      (evil-insert-state)  ;; If so, turn on evil-insert-state
    (evil-normal-state)))  ;; Otherwise, turn on normal-state

(add-hook 'cider--debug-mode-hook 'my-cider-debug-toggle-insert-state)

This assumes you want to be in normal-state whenever you exit the debugger.

| improve this answer | |
  • Thank you, it makes much more sense to add to the specific hook rather than to add an advice around every time cider eval is called. – sooheon Mar 7 '16 at 15:44
  • Adivising SEEMS like something that could be useful but I haven't actually used it because It's more easily implemented with a hook instead. It's also recommended to use hooks over advising when you have the choice between the two. emacswiki.org/emacs/AdviceVsHooks – seanirby Mar 7 '16 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.