Fork me on GitHub
#spacemacs
<
2019-08-22
>
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?

ag16:08:53

@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 ,

ag16:08:42

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 ()
    (interactive)
    (save-excursion
      (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.

ag16:08:24

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

ag17:08:46

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))

ag18:08:44

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

ag18:08:06

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?

practicalli-johnny20:08:36

@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.

practicalli-johnny20:08:29

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.

practicalli-johnny20:08:02

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?

ag20:08:47

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

ag20:08:27

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

practicalli-johnny22:08:23

@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.

practicalli-johnny23:08:25

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?

practicalli-johnny23:08:23

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

4