Question

How can I take a form and in order to make it an argument of another function surround it with parentheses with one command?

For the example below, assume the cursor starts at the beginning and I do not move it throughout.

(max 1 2 3) -> ((max 1 2 3)) -> (= 3 (max 1 2 3))

So my commands would be: 'magic-key-combination' -> '=' -> ' ' -> '3'

Was it helpful?

Solution

There is no single built-in command that does all of that, however, you can bind a key to multiple commands.

Try putting the following in your user.keymap file (just replace "ctrl-m" with your preferred magic-key-combination).

{:+ {...
     :editor {...
              "ctrl-m" [:paredit.select.parent 
                        (:editor.open-pair "(")
                         :paredit.move.down.backward 
                         :paredit.move.up.backward  
                         :editor.char-right]
              ...}}}

See I can't find a light table cheat sheet for details of the what each individual paredit command does, and tweak as required!

OTHER TIPS

Here is another option that I use constantly. Starting with "(max 1 2 3)", I would type "= 3 " before the opening paren, resulting in this:

= 3 (max 1 2 3)

Then, I select the entire expression and type an opening paren. LightTable automatically inserts the closing paren at the end of the selection:

(= 3 (max 1 2 3))

You may still decide to use a key binding, but this trick is good to know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top