Search code examples
clojurelighttable

light table paredit surround with parens


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'


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!