Avoiding extra space characters when selecting the first expression

When using Paredit, I often come across the following (pipe char represents the cursor):

(foo |bar baz) 

I want to paredit-wrap-around bar in parens, so I use paredit-wrap-around ( M - ( ) to get this:

 (foo (|bar) baz) 

The same thing happens when I want to put bar inside a string, I can use M - " to get the following:

 (foo "|bar" baz) 

However, Clojure also uses square brackets [] and curly braces {} for vectors, mappings, and sets. They don't seem to have the paredit 'wrap around' command. Thus, in this case, for example, to put a stroke on a vector, I usually use the [ key to create a new vector:

 (foo [|] bar baz) 

followed by paredit-forward-slurp-sexp ( C - ), which results in:

 (foo [| bar] baz) 

I would like to remove the space character that was inserted before bar . Is it possible? Why does paredit preserve char whitespace when moving from an empty expression to one containing one element? Should the first element added to the S-expression always be propped up right before the opening steam?

+6
source share
2 answers

Paredit had paredit-wrap-curly and paredit-wrap-square for quite some time. If you want to use them, just tie them to the key with the likely sound and get it. If you are using such an old version of paredit that these functions do not exist, you should upgrade (but I don't think you are, since the slurp commands work with them). A.

+4
source

The latest version of paredit supports M-[ up to paredit-wrap-square , which does exactly what you want. Emacs already binds M-{ to backward-paragraph , but if you never use it, you can configure paredit to shadow copy it:

 (eval-after-load 'paredit '(progn (define-key paredit-mode-map (kbd "M-{") 'paredit-wrap-curly))) 

If you want to delete all the space around a point, you can always enter M-\ for delete-horizontal-space .

+1
source

Source: https://habr.com/ru/post/948436/


All Articles