@@ -87,15 +87,15 @@ require("nvim-paredit").setup({
87
87
[" <localleader>o" ] = { paredit .api .raise_form , " Raise form" },
88
88
[" <localleader>O" ] = { paredit .api .raise_element , " Raise element" },
89
89
90
- [" E" ] = {
90
+ [" E" ] = {
91
91
paredit .api .move_to_next_element ,
92
92
" Jump to next element tail" ,
93
93
-- by default all keybindings are dot repeatable
94
94
repeatable = false ,
95
95
mode = { " n" , " x" , " o" , " v" },
96
96
},
97
97
[" B" ] = {
98
- paredit .api .move_to_prev_element ,
98
+ paredit .api .move_to_prev_element ,
99
99
" Jump to previous element head" ,
100
100
repeatable = false ,
101
101
mode = { " n" , " x" , " o" , " v" },
@@ -198,6 +198,73 @@ paredit.api.slurp_forwards()
198
198
- ** ` move_to_next_element ` **
199
199
- ** ` move_to_prev_element ` **
200
200
201
+ Form/element wrap api is in ` paredit.wrap ` module:
202
+
203
+ - ** ` wrap_element_under_cursor ` ** - accepts prefix and suffix, returns wrapped ` TSNode `
204
+ - ** ` wrap_enclosing_form_under_cursor ` ** - accepts prefix and suffix, returns wrapped ` TSNode `
205
+
206
+ Cursor api ` paredit.cursor `
207
+
208
+ - ** ` place_cursor ` ** - accepts ` TSNode ` , and following options:
209
+ - ` placement ` - enumeration ` left_edge ` ,` inner_start ` ,` inner_end ` ,` right_edge `
210
+ - ` mode ` - currently only ` insert ` is supported, defaults to ` normal `
211
+
212
+ ## API usage recipes
213
+
214
+ ### ` vim-sexp ` wrap form (head/tail) replication
215
+
216
+ Require api module:
217
+ ``` lua
218
+ local paredit = require (" nvim-paredit.api" )
219
+ ```
220
+ Add following keybindings to config:
221
+ ``` lua
222
+ [" <localleader>w" ] = {
223
+ function ()
224
+ -- place cursor and set mode to `insert`
225
+ paredit .cursor .place_cursor (
226
+ -- wrap element under cursor with `( ` and `)`
227
+ paredit .wrap .wrap_element_under_cursor (" ( " , " )" ),
228
+ -- cursor placement opts
229
+ { placement = " inner_start" , mode = " insert" }
230
+ )
231
+ end ,
232
+ " Wrap element insert head" ,
233
+ },
234
+
235
+ [" <localleader>W" ] = {
236
+ function ()
237
+ paredit .cursor .place_cursor (
238
+ paredit .wrap .wrap_element_under_cursor (" (" , " )" ),
239
+ { placement = " inner_end" , mode = " insert" }
240
+ )
241
+ end ,
242
+ " Wrap element insert tail" ,
243
+ },
244
+
245
+ -- same as above but for enclosing form
246
+ [" <localleader>i" ] = {
247
+ function ()
248
+ paredit .cursor .place_cursor (
249
+ paredit .wrap .wrap_enclosing_form_under_cursor (" ( " , " )" ),
250
+ { placement = " inner_start" , mode = " insert" }
251
+ )
252
+ end ,
253
+ " Wrap form insert head" ,
254
+ },
255
+
256
+ [" <localleader>I" ] = {
257
+ function ()
258
+ paredit .cursor .place_cursor (
259
+ paredit .wrap .wrap_enclosing_form_under_cursor (" (" , " )" ),
260
+ { placement = " inner_end" , mode = " insert" }
261
+ )
262
+ end ,
263
+ " Wrap form insert tail" ,
264
+ }
265
+ ```
266
+ Same approach can be used for other ` vim-sexp ` keybindings (e.g. ` <localleader>e[ ` ) with cursor placement or without.
267
+
201
268
## Prior Art
202
269
203
270
### [ vim-sexp] ( https://github.com/guns/vim-sexp )
@@ -206,10 +273,10 @@ Currently the de-facto s-expression editing plugin with the most extensive set o
206
273
207
274
The main reasons you might want to consider ` nvim-paredit ` instead are:
208
275
209
- + Easier configuration and an exposed lua API
210
- + Control over how the cursor is moved during slurp/barf. (For example if you don't want the cursor to always be moved)
211
- + Recursive slurp/barf operations. If your cursor is in a nested form you can still slurp from the forms parent(s)
212
- + Subjectively better out-of-the-box keybindings
276
+ - Easier configuration and an exposed lua API
277
+ - Control over how the cursor is moved during slurp/barf. (For example if you don't want the cursor to always be moved)
278
+ - Recursive slurp/barf operations. If your cursor is in a nested form you can still slurp from the forms parent(s)
279
+ - Subjectively better out-of-the-box keybindings
213
280
214
281
### [ vim-sexp-mappings-for-regular-people] ( https://github.com/tpope/vim-sexp-mappings-for-regular-people )
215
282
0 commit comments