4

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'

shmish111
  • 3,697
  • 5
  • 30
  • 52

2 Answers2

2

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!

Community
  • 1
  • 1
Daniel Neal
  • 4,165
  • 2
  • 20
  • 34
  • Thanks. I can't find a light table cheat sheet was also my question :) – shmish111 Mar 15 '14 at 17:19
  • 1
    Oh yeah - I see that now! I like your Light Table questions - I'm still a newbie to Light Table, and answering questions helps me understand it better e.g. I never thought of trying to do the above before, even though I knew it was theoretically possible. – Daniel Neal Mar 15 '14 at 17:30
1

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.

DavidM
  • 1,417
  • 1
  • 13
  • 16