Fork me on GitHub
Yehonathan Sharvit16:08:08

I would like to be able to run cider command while in lisp state like when I am in normal state with , leader key e.g. ,ee to evaluate expression etc… How do I achieve this?


@viebel check evil-lisp-state-commands

Yehonathan Sharvit16:08:55

@ag I tried it but as far as I know, I have to add a line for each keybinding. I am looking for a way to add a binding for ,


I’m not sure what exactly you are trying to achieve, here’s for example how I extended lisp state by adding a command to reindent current sexp:

(with-eval-after-load 'evil-lisp-state
  (defun sp-reindent ()
      (er/expand-region 2)
      (evil-indent (region-beginning) (region-end))))

  (evil-lisp-state-enter-command sp-reindent)
  (spacemacs/set-leader-keys "k=" #'evil-lisp-state-sp-reindent))
so pressing SPC k = would re-indent things.


do you want to eval sexp and stay in lisp state? What’s exactly are you trying to do?

Yehonathan Sharvit17:08:39

@ag I am trying to make all cider functions accessible from lisp state with the same keybindings as in normal state


I get that, but what’s the workflow? How are you getting into the lisp-state to begin with? Anyway, it should be as straightforward as doing something like this:

(add-to-list 'evil-lisp-state-commands '("e e" . cider-eval-last-sexp))


ah, that won’t work because e is bound to sp-splice-sexp-killing-forward


I guess it ain’t so straightforward as I thought

Yehonathan Sharvit19:08:34

My workflow is: 1. Normal state 2. Switch to Insert state 3. Edit some code 4. Switch to lisp state 5. Now I want to evaluate an expression without having to press ESC

Yehonathan Sharvit19:08:04

As I said, I can make it work by rebinding all the cider keys: ee, ef, eb etc…

Yehonathan Sharvit19:08:31

But I think there should be a way to make the “,” key available in lisp state and trigger the cider functions

Yehonathan Sharvit19:08:35

Does it make sense?


@viebel it's not exactly what you are asking, but you can use M-RET as the major mode leader instead of , when in Lisp State.


I consider lisp state to be just like insert state. So if I want to evaluate code then I drop back to Normal state using ESC or fd.


I assume you would need to either modify lisp state elisp or add hooks in your .spacemacs file (or become used to eval code in normal state)

Yehonathan Sharvit20:08:43

Is it possible to make , work like M-RET while in lisp state?


Ok. You confused me because lisp state is something else. Not what you mean


Lisp state is when you press "SPC k" ... In normal mode


@viebel M-RET is the Emacs binding for the major mode menu so its always available in any evil state as well as Emacs (holy mode). I dont know how you would edit evil-lisp-state to have a major-mode menu bound to the key ,. Evil-lisp state is a micro state in Spacemacs so its not configured to have a leader key for a major mode. Even if you did find a way to add , to call the major mode menu within the evil-lisp-state If someone added a , keybinding to the evil-lisp state then I dont know which would take precedence.


I don't really understand you workflow. Why are you switching from insert to lisp state? Are you always structurally editing after adding new code?


My use of multi-modal states is: In normal to evaluate code, navigate around code, maybe code fold, spell check, etc From normal to insert to add code and back to normal (using fd) to demarcate the undo boundary of text changes From normal to lisp to refactor using slurp, barf, raise, transpose, etc and back to normal