Skip to content

Commit a87a550

Browse files
Merge pull request #72 from julienvincent/jv/fennel-support
Add fennel support
2 parents 31d91d3 + 5581660 commit a87a550

File tree

7 files changed

+302
-2
lines changed

7 files changed

+302
-2
lines changed

lua/nvim-paredit/defaults.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,14 @@ M.defaults = {
119119
enabled = false,
120120
indentor = require("nvim-paredit.indentation.native").indentor,
121121
},
122-
filetypes = { "clojure" },
122+
filetypes = { "clojure", "fennel" },
123123
languages = {
124124
clojure = {
125125
whitespace_chars = { " ", "," },
126126
},
127+
fennel = {
128+
whitespace_chars = { " ", "," },
129+
},
127130
},
128131
keys = {},
129132
}

queries/fennel/paredit/forms.scm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(list) @form
2+
(sequence) @form
3+
(table) @form

tests/config.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ vim.bo.swapfile = false
1111

1212
require("nvim-treesitter.configs").setup({
1313
parser_install_dir = vim.fn.getcwd() .. "/.build/parsers",
14-
ensure_installed = { "clojure" },
14+
ensure_installed = { "clojure", "fennel" },
1515
sync_install = true,
1616
})
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
local paredit = require("nvim-paredit.api")
2+
3+
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer
4+
local expect = require("tests.nvim-paredit.utils").expect
5+
6+
describe("element raising", function()
7+
vim.api.nvim_set_option_value("filetype", "fennel", {
8+
buf = 0,
9+
})
10+
11+
it("should raise the element", function()
12+
prepare_buffer({
13+
content = "(a (b))",
14+
cursor = { 1, 4 },
15+
})
16+
paredit.raise_element()
17+
expect({
18+
content = "(a b)",
19+
cursor = { 1, 3 },
20+
})
21+
end)
22+
23+
it("should raise form elements when cursor is placed on edge", function()
24+
prepare_buffer({
25+
content = "(a (b))",
26+
cursor = { 1, 3 },
27+
})
28+
29+
paredit.raise_element()
30+
expect({
31+
content = "(b)",
32+
cursor = { 1, 0 },
33+
})
34+
35+
prepare_buffer({
36+
content = "(a #(b))",
37+
cursor = { 1, 3 },
38+
})
39+
40+
paredit.raise_element()
41+
expect({
42+
content = "#(b)",
43+
cursor = { 1, 0 },
44+
})
45+
end)
46+
47+
it("should raise a multi-line element", function()
48+
prepare_buffer({
49+
content = { "(a (b", " c))" },
50+
cursor = { 1, 3 },
51+
})
52+
53+
paredit.raise_element()
54+
expect({
55+
content = { "(b", " c)" },
56+
cursor = { 1, 0 },
57+
})
58+
end)
59+
60+
it("should do nothing if it is a direct child of the document root", function()
61+
prepare_buffer({
62+
content = { "a", "b" },
63+
cursor = { 1, 0 },
64+
})
65+
paredit.raise_form()
66+
expect({
67+
content = { "a", "b" },
68+
cursor = { 1, 0 },
69+
})
70+
end)
71+
end)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
local paredit = require("nvim-paredit.api")
2+
3+
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer
4+
local expect_all = require("tests.nvim-paredit.utils").expect_all
5+
local expect = require("tests.nvim-paredit.utils").expect
6+
7+
describe("form raising", function()
8+
vim.api.nvim_set_option_value("filetype", "fennel", {
9+
buf = 0,
10+
})
11+
12+
it("should raise the form", function()
13+
expect_all(paredit.raise_form, {
14+
{
15+
"list",
16+
before_content = "(a (b c))",
17+
before_cursor = { 1, 6 },
18+
after_content = "(b c)",
19+
after_cursor = { 1, 0 },
20+
},
21+
{
22+
"list with reader",
23+
before_content = "(a #(b c))",
24+
before_cursor = { 1, 5 },
25+
after_content = "#(b c)",
26+
after_cursor = { 1, 0 },
27+
},
28+
})
29+
end)
30+
31+
it("should raise a multi-line form", function()
32+
prepare_buffer({
33+
content = { "(a (b ", "c))" },
34+
cursor = { 1, 4 },
35+
})
36+
37+
paredit.raise_form()
38+
expect({
39+
content = { "(b ", "c)" },
40+
cursor = { 1, 0 },
41+
})
42+
end)
43+
44+
it("should do nothing if it is a direct child of the document root", function()
45+
prepare_buffer({
46+
content = { "(a)", "b" },
47+
cursor = { 1, 1 },
48+
})
49+
paredit.raise_form()
50+
expect({
51+
content = { "(a)", "b" },
52+
cursor = { 1, 1 },
53+
})
54+
end)
55+
56+
it("should do nothing if it is outside of a form", function()
57+
prepare_buffer({
58+
content = { "a", "b" },
59+
cursor = { 1, 0 },
60+
})
61+
paredit.raise_form()
62+
expect({
63+
content = { "a", "b" },
64+
cursor = { 1, 0 },
65+
})
66+
end)
67+
end)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
local paredit = require("nvim-paredit.api")
2+
3+
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer
4+
local expect = require("tests.nvim-paredit.utils").expect
5+
6+
describe("motions", function()
7+
vim.api.nvim_set_option_value("filetype", "fennel", {
8+
buf = 0,
9+
})
10+
11+
it("should jump to next element in form (tail)", function()
12+
prepare_buffer({
13+
content = "(aa (bb) #(cc))",
14+
cursor = { 1, 2 },
15+
})
16+
17+
paredit.move_to_next_element_tail()
18+
expect({
19+
cursor = { 1, 7 },
20+
})
21+
22+
paredit.move_to_next_element_tail()
23+
expect({
24+
cursor = { 1, 13 },
25+
})
26+
27+
paredit.move_to_next_element_tail()
28+
expect({
29+
cursor = { 1, 13 },
30+
})
31+
end)
32+
33+
it("should jump to next element in form (head)", function()
34+
prepare_buffer({
35+
content = "(aa (bb) #(cc))",
36+
cursor = { 1, 2 },
37+
})
38+
39+
paredit.move_to_next_element_head()
40+
expect({
41+
cursor = { 1, 4 },
42+
})
43+
44+
paredit.move_to_next_element_head()
45+
expect({
46+
cursor = { 1, 9 },
47+
})
48+
end)
49+
end)
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
local paredit = require("nvim-paredit.api")
2+
3+
local prepare_buffer = require("tests.nvim-paredit.utils").prepare_buffer
4+
local expect_all = require("tests.nvim-paredit.utils").expect_all
5+
local expect = require("tests.nvim-paredit.utils").expect
6+
7+
describe("slurping forward", function()
8+
vim.api.nvim_set_option_value("filetype", "fennel", {
9+
buf = 0,
10+
})
11+
local parser = vim.treesitter.get_parser(0)
12+
if not parser then
13+
return error("Failed to get parser for fennel")
14+
end
15+
16+
it("should slurp forward different form types", function()
17+
expect_all(paredit.slurp_forwards, {
18+
{
19+
"list",
20+
before_content = "() a",
21+
before_cursor = { 1, 1 },
22+
after_content = "( a)",
23+
after_cursor = { 1, 1 },
24+
},
25+
{
26+
"vector",
27+
before_content = "[] a",
28+
before_cursor = { 1, 1 },
29+
after_content = "[ a]",
30+
after_cursor = { 1, 1 },
31+
},
32+
{
33+
"quoted list",
34+
before_content = "`() a",
35+
before_cursor = { 1, 2 },
36+
after_content = "`( a)",
37+
after_cursor = { 1, 2 },
38+
},
39+
})
40+
end)
41+
42+
it("should skip comments", function()
43+
prepare_buffer({
44+
content = { "()", ";; comment", "a" },
45+
cursor = { 1, 1 },
46+
})
47+
paredit.slurp_forwards()
48+
expect({
49+
content = { "(", ";; comment", "a)" },
50+
cursor = { 1, 0 },
51+
})
52+
end)
53+
54+
it("should recursively slurp the next sibling", function()
55+
prepare_buffer({
56+
content = "(()) 1 2",
57+
cursor = { 1, 2 },
58+
})
59+
60+
paredit.slurp_forwards()
61+
expect({
62+
content = "(() 1) 2",
63+
cursor = { 1, 2 },
64+
})
65+
66+
parser:parse()
67+
68+
paredit.slurp_forwards()
69+
expect({
70+
content = "(( 1)) 2",
71+
cursor = { 1, 2 },
72+
})
73+
74+
parser:parse()
75+
76+
prepare_buffer({
77+
content = "(( 1)) 2",
78+
cursor = { 1, 2 },
79+
})
80+
81+
paredit.slurp_forwards()
82+
expect({
83+
content = "(( 1) 2)",
84+
cursor = { 1, 2 },
85+
})
86+
87+
parser:parse()
88+
89+
paredit.slurp_forwards()
90+
expect({
91+
content = "(( 1 2))",
92+
cursor = { 1, 2 },
93+
})
94+
end)
95+
96+
it("should follow the bracket with cursor", function()
97+
prepare_buffer({
98+
content = "() 1 2",
99+
cursor = { 1, 1 },
100+
})
101+
paredit.slurp_forwards({ cursor_behaviour = "follow" })
102+
expect({
103+
content = "( 1) 2",
104+
cursor = { 1, 3 },
105+
})
106+
end)
107+
end)

0 commit comments

Comments
 (0)