Fork me on GitHub
#spacemacs
<
2016-11-10
>
lvh15:11:39

In spacemacs, how do I wrap an expr in [] or {} or #{}

lvh15:11:57

SPC k w seems to only be about parens

lvh15:11:49

I know I can do it with [ SPC k s

lvh15:11:52

but that seems weird

eggsyntax15:11:14

There may be a more standard way, but I highlight it in visual mode and then do s ] or s } or...you can use the left-bracket equivalents, but that'll add a space.

lvh15:11:54

that seems to do it on a letter, not a sexp

eggsyntax15:11:19

It'll do it with anything, whatever you've got highlighted in visual mode.

lvh15:11:31

ah, right, ok

eggsyntax15:11:51

You can do eg v a ( to highlight a sexp

eggsyntax15:11:03

Is it obvious I come from vi-world here? 😉

lvh15:11:29

hm, is there a way to get actually-a-sexp

lvh15:11:38

specifically, in the sp hybrid style, which would include, say, symbols

lvh15:11:08

I know I can get o to get a symbol; I’m just not used to thinking of the exact thing I’m selecting

lvh15:11:23

but rather used to being good at traveling to it

eggsyntax15:11:26

Probably 🙂. I just don't bother for wrapping.

eggsyntax15:11:44

Except, as you say, SPC k w to wrap in another sexp

lvh15:11:23

[ and ] seem natural extensions givne that ( and ) exist

eggsyntax15:11:09

Agreed -- but since they're less important in non-clj lisps, maybe the authors didn't think about them? Purely guessing there.

eggsyntax15:11:38

I didn't know about [ SPC k s, I may try to start using that.

eggsyntax15:11:19

Oh, one handy tip -- there's a way to get SM to recognize that, eg foo-bar-baz is a single word in lisp-land. I can dig that up if you'd like to add it.

lvh15:11:43

oh, I hadn’t even ntoiced that yet

lvh15:11:44

but yeah

lvh15:11:48

I typed cw today

eggsyntax15:11:54

;; Use clojure-based definition of words
  (with-eval-after-load 'clojure-mode
    (dolist (c (string-to-list ":_-?!#*"))
      (modify-syntax-entry c "w" clojure-mode-syntax-table )))

eggsyntax15:11:36

That's a variation on the lisp one because of minor differences -- if you use other lisps you may want that one too (but I don't have it)

eggsyntax15:11:18

Huh, [ SPC k s isn't valid for me...is there a typo in there?

lvh15:11:58

yeah it’s more like

lvh15:11:14

which is why it’s so annoying 🙂

kasuko15:11:22

I know this doesn’t directly solve your problem, but for the exact purpose of wrapping stuff easier is why I installed the evil-cleverparans layer and haven’t looked back. Now to wrap I just use M-( to wrap a single sexp or 2 M-( to wrap 2 sexps etc. This also works with M-[ and M-{ I also like the other keybindings too.

malch16:11:00

@lvh also use evil-cleverparens layer, very nice

lvh16:11:44

awesome 🙂

eggsyntax16:11:13

Ooooh, didn't know about that one -- @malch no problems/conflicts with SM's built-in layer? (smartparens IIRC)

malch16:11:49

well, I turned off paredit and lispy completely (used them before)

malch16:11:48

evil-cleverparens supports most of the paredit functionality (same about smartparens, I guess)

malch16:11:06

and by most I mean all that I need simple_smile

eggsyntax16:11:18

Gotcha, so it's an alternative rather than a supplement. Thx!

malch16:11:37

anyway, should be really easy to try

kasuko16:11:11

@eggsyntax I haven’t disabled any smartparens settings and I haven’t had any issues.

bja17:11:46

I use this for wrapping:

;; make wrapping friendly to Clojure/Pixie/Hy
(with-eval-after-load "evil-lisp-state"
  ;; undef SPC k w so we can generalize it
  (evil-leader/set-key "kw" nil)
  ;; wrap using SPC k w ([{
  (evil-leader/set-key "kw("
    (lambda (&optional arg) (interactive "P") (sp-wrap-with-pair "(")))
  (evil-leader/set-key "kw["
    (lambda (&optional arg) (interactive "P") (sp-wrap-with-pair "[")))
  (evil-leader/set-key "kw{"
    (lambda (&optional arg) (interactive "P") (sp-wrap-with-pair "{")))
  (evil-leader/set-key "kw\""
    (lambda (&optional arg) (interactive "P") (sp-wrap-with-pair "\""))))

bja17:11:10

I also define SPC m e o as a generic eval operator and SPC m s o as a generic send operator and then hook into the mode-specific eval-region (cider's is cider-eval-region). This lets me eval motions. Then I redefined all of the SPC m s and SPC m e eval and send stuff in terms of the generic eval and send so that they are consistent across emacs lisp, python, and clojure

bja17:11:11

it's a bit verbose, but for one-off evals it's much easier to SPC m e o % on an opening or closing paren, while keeping the ability to eval a buffer, a line, etc and not think about shortcuts, just the normal evil building blocks

bja17:11:05

I think it's a bit crazy that every spacemacs language layer has a slightly different set of eval/send functionality and at different keybindings

bja17:11:43

then you get to say stuff like

;; Enable highlighting of the area to be eval'd
(define-eval-sexp-fu-flash-command emidln//generic-eval-region
  (eval-sexp-fu-flash (cons beg end)))

bja17:11:03

and suddenly all of your languages get fancy results overlays

eggsyntax20:11:44

re: evil-cleverparens which is so cool it makes my jaw drop (because of course the way to handle sexps for vimmers is to make them ordinary text objects), there's a pre-existing spacemacs layer for it: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bvim/evil-cleverparens

jasonjckn21:11:05

love evil-cleverparens

jasonjckn21:11:54

@eggsyntax is your dot spacemacs posted anywhere?

eggsyntax21:11:32

@jasonjckn Not at the moment -- it's a mess for sure, & includes some stuff that I haven't been able to get to work. I'm still a semi-noob at emacs & emacs lisp. But I'd be happy to share it with you if you'd like.

eggsyntax21:11:48

It's at least fairly well commented.

jasonjckn21:11:01

sure, if you have any interesting hacks, maybe I could learn from it

jasonjckn21:11:29

(with-eval-after-load 'clojure-mode
    (dolist (c (string-to-list ":_-?!#*"))
      (modify-syntax-entry c "w" clojure-mode-syntax-table )))
seems to not work quite right, when I hold "w" in normal mode the cursor sometimes gets stuck at a closing parens and makes no more forward movements.

eggsyntax21:11:03

Weird. I didn't write that, I stole it. Lemme see if I can find a link.

eggsyntax22:11:48

@jasonjckn here's my .spacemacs -- for anyone who looks at it, please be aware that a) it's a mess, b) there's broken stuff in there, and c) I'm still an emacs & emacs lisp noob. But it's at least commented.

jasonjckn22:11:23

@eggsyntax many great hacks in there thatkns

jasonjckn22:11:28

@eggsyntax i'm also dvorakian 😉

eggsyntax23:11:56

@jasonjckn if it’s obvious to you why any of the broken things are broken, let me know 🙂