Fork me on GitHub
#spacemacs
<
2017-12-20
>
justinlee00:12:32

is it possible to specify a different wrap character (SPC k w)? In clojure I often want to wrap with square brackets, and right now that means inserting a [] pair, deleting the second one, moving to the end of the expression, then adding a ]

andre.stylianos11:12:54

Why not insert [] and then slurping what you want to be inside, instead of deleting and adding ] to the end

chris12:12:14

slurping or using evil surround (what I would suggest most of the time)

chris12:12:27

you can also just bind a new function

chris12:12:46

(defun lisp-state-wrap (&optional arg)
  "Wrap a symbol with parenthesis."
  (interactive "P")
  (sp-wrap-with-pair "("))

chris12:12:58

that's the entire function

ag15:12:49

@lee.justin.m a) if you have an expression (foo) and you want to replace parens with square brakets you can do cs([ - while cursor is on the paren b) if you just want to surround (foo) with square brackets, you can first select it either by doing v% - while cursor on the paren, or by va(; and then simply do s[, that will surround the expression with square brackets c) if you just want to insert a single bracket, without causing automatic insertion of the second one - you can always "insert literally" - press C-v (while in insert mode) and then press [ - that will force Emacs to ignore smartparens and simply insert the character

justinlee17:12:56

@U0G75ARHC @U050AFD41 @U485ZRA58 those are all great options. I don’t know why I didn’t think of insert+slurping. Thanks for the help. Lots of great tips that I didn’t know about here.

Scot20:12:10

Others may find this kinda gross, but I rebind wrap as follows:

(define-key evil-lisp-state-map (kbd "w") nil)
  (define-key evil-lisp-state-map (kbd "ww") (evil-lisp-state-enter-command evil-lisp-state-wrap))
  (define-key evil-lisp-state-map (kbd "wW") (evil-lisp-state-enter-command sp-unwrap-sexp))
  (define-key evil-lisp-state-map (kbd "w(") (evil-lisp-state-enter-command evil-cp-wrap-next-round))
  (define-key evil-lisp-state-map (kbd "w)") (evil-lisp-state-enter-command evil-cp-wrap-previous-round))
  (define-key evil-lisp-state-map (kbd "w[") (evil-lisp-state-enter-command evil-cp-wrap-next-square))
  (define-key evil-lisp-state-map (kbd "w]") (evil-lisp-state-enter-command evil-cp-wrap-previous-square))
  (define-key evil-lisp-state-map (kbd "w{") (evil-lisp-state-enter-command evil-cp-wrap-next-curly))
  (define-key evil-lisp-state-map (kbd "w}") (evil-lisp-state-enter-command evil-cp-wrap-previous-curly))

Scot20:12:10

such that 'w' in lisp state (i.e. SPC k w) is a prefix, and 'w (', 'w {', and 'w [' wrap with their respective parens. Also evil-cleverparens allows a numeric argument (e.g. "4 SPC k w {" to wrap the next sexps in a pair of braces) which is quite nice for working with nested maps.

ag15:12:49

@lee.justin.m a) if you have an expression (foo) and you want to replace parens with square brakets you can do cs([ - while cursor is on the paren b) if you just want to surround (foo) with square brackets, you can first select it either by doing v% - while cursor on the paren, or by va(; and then simply do s[, that will surround the expression with square brackets c) if you just want to insert a single bracket, without causing automatic insertion of the second one - you can always "insert literally" - press C-v (while in insert mode) and then press [ - that will force Emacs to ignore smartparens and simply insert the character

ag15:12:57

I do understand when Vim-style feels daunting to learn, it has many versatile ways to achieve something, even in this simple example I demonstrated a few concepts: - selecting text from one delimiter to another delimiter v% - selecting text "in between" - vi(, compare it with va(. These would also work for other delimiters, paragraph p, word w, sentence s, tag t (in HTML) - literal insertion C-v (while in Insert) mode - vim-surround: sc, then delimiter that needs to be replaced and char that it should be replaced with and it may feel you have to think all the time what needs to be pressed to achieve a result, which is only true in the beginning. Once you grasp the concepts, the muscle memory does the rest.

justinlee17:12:39

The biggest problem I have is just that I haven’t found a comprehensive reference. It seems like all of the documentation is either a cheatsheet or an introduction. Like the vi( and va( commands--most references just seem to talk about visual mode without actually explaining what you can do in visual mode.

eggsyntax19:12:45

@lee.justin.m the vim user manual is actually pretty comprehensive, seems like probably the thing you're looking for. Manual: http://vimdoc.sourceforge.net/htmldoc/usr_toc.html Visual mode section (covers the specific questions you're asking): http://vimdoc.sourceforge.net/htmldoc/visual.html Note that, like everything else in vim and spacemacs, it's customizable -- here's a list of visual-mode operators, but you can add your own operators and text objects: http://vimdoc.sourceforge.net/htmldoc/visual.html#visual-operators Of course when it gets to customizing stuff like that, that's pretty much the moment where you have to switch from vim documentation to spacemacs documentation (which is also pretty comprehensive).

justinlee19:12:06

Thanks. I guess I was looking for spacemacs documentation but I forget that really it’s vim underneath and that’s what I should be learning

eggsyntax19:12:22

Yeah, for evil-mode documentation, spacemacs pretty consistently defers to vim docs (although it's worth reading the concepts section of the SM docs to get an overview of the evil-mode implementation and differences from vim (mostly just the evil-surround case)): http://spacemacs.org/doc/DOCUMENTATION.html#concepts

jeff.terrell19:12:00

Good question and great discussion here. I'll only add one nitpick that can save a keystroke. va(s[ can be shortened to ys%[. ys is an operator defined by vim-surround/evil-surround. Give it a motion (`%`) and a character (`[`) and it will surround the delineated text by the character [pair].