Search code examples
emacslispslime

wrap s-expression in slime (emacs)


Is there a short way to wrap an s-expression using slime?

Suppose i have finished some piece of code and I realize I need a variable (e.g. for efficiency reasons) and therefore want to wrap it with let or want to make it tail recursive and need to wrap it with labels, what is the fastest way to do this? Is there a shortcut?

IntelliJ (a Java IDE) allows things like:
x > 3.if + TAB
yielding

if (x > 3) {

    }

So are there any "sexp-wrapping" shortcuts (postfix or prefix) in slime/emacs?


Solution

  • The bar represents the cursor.

    With paredit

    There is a wrap-round command, bound to M-(. But when adding context to an expression, I generally do as follows:

    |code
    

    Open the parenthesis (the closing one is added automatically):

    (|)code
    

    ... type ...

    (let |)code
    

    Call paredit-forward-slurp-sexp (C-right)

    (let | code)
    

    See also the The Animated Guide to Paredit.

    Without paredit

    |code
    

    Call mark-sexp (C-M-Space), then kill the region; type and yank (paste) the text where you need it.

    See also Expressions with Balanced Parentheses (e.g. forward-sexp), available in Emacs.