1
1
local M = {}
2
2
local api = vim .api
3
- local util = require " lspconfig.util "
4
- local tools = require ' quarto.tools '
5
- local otter = require ' otter '
6
- local otterkeeper = require ' otter.keeper '
3
+ local otter = require ( " otter " )
4
+ local otterkeeper = require ( " otter.keeper " )
5
+ local tools = require ( " quarto.tools " )
6
+ local util = require ( " lspconfig.util " )
7
7
8
8
M .defaultConfig = {
9
9
debug = false ,
10
10
closePreviewOnExit = true ,
11
11
lspFeatures = {
12
12
enabled = true ,
13
- chunks = ' curly' ,
14
- languages = { ' r ' , ' python' , ' julia' , ' bash' , ' html' },
13
+ chunks = " curly" ,
14
+ languages = { " r " , " python" , " julia" , " bash" , " html" },
15
15
diagnostics = {
16
16
enabled = true ,
17
- triggers = { " BufWritePost" }
17
+ triggers = { " BufWritePost" },
18
18
},
19
19
completion = {
20
20
enabled = true ,
21
21
},
22
22
},
23
23
keymap = {
24
- hover = ' K ' ,
25
- definition = ' gd ' ,
26
- type_definition = ' gD ' ,
27
- rename = ' <leader>lR' ,
28
- format = ' <leader>lf' ,
29
- references = ' gr ' ,
30
- document_symbols = ' gS ' ,
31
- }
24
+ hover = " K " ,
25
+ definition = " gd " ,
26
+ type_definition = " gD " ,
27
+ rename = " <leader>lR" ,
28
+ format = " <leader>lf" ,
29
+ references = " gr " ,
30
+ document_symbols = " gS " ,
31
+ },
32
32
}
33
33
34
34
-- use defaultConfig if not setup
35
35
M .config = M .defaultConfig
36
36
37
37
function M .quartoPreview (opts )
38
38
opts = opts or {}
39
- local args = opts .args or ' '
39
+ local args = opts .args or " "
40
40
41
41
-- find root directory / check if it is a project
42
42
local buffer_path = api .nvim_buf_get_name (0 )
@@ -45,13 +45,13 @@ function M.quartoPreview(opts)
45
45
local mode
46
46
if root_dir then
47
47
mode = " project"
48
- cmd = ' quarto preview' .. ' ' .. args
48
+ cmd = " quarto preview" .. " " .. args
49
49
else
50
50
mode = " file"
51
51
if vim .loop .os_uname ().sysname == " Windows_NT" then
52
- cmd = ' quarto preview \\ "' .. buffer_path .. ' \\ "' .. ' ' .. args
52
+ cmd = ' quarto preview \\ "' .. buffer_path .. ' \\ "' .. " " .. args
53
53
else
54
- cmd = ' quarto preview \' ' .. buffer_path .. ' \' ' .. ' ' .. args
54
+ cmd = " quarto preview ' " .. buffer_path .. " ' " .. " " .. args
55
55
end
56
56
end
57
57
@@ -68,10 +68,10 @@ function M.quartoPreview(opts)
68
68
69
69
-- run command in embedded terminal
70
70
-- in a new tab and go back to the buffer
71
- vim .cmd (' tabedit term://' .. cmd )
71
+ vim .cmd (" tabedit term://" .. cmd )
72
72
local quartoOutputBuf = vim .api .nvim_get_current_buf ()
73
- vim .cmd (' tabprevious' )
74
- api .nvim_buf_set_var (0 , ' quartoOutputBuf' , quartoOutputBuf )
73
+ vim .cmd (" tabprevious" )
74
+ api .nvim_buf_set_var (0 , " quartoOutputBuf" , quartoOutputBuf )
75
75
76
76
if not M .config then
77
77
return
@@ -86,22 +86,24 @@ function M.quartoPreview(opts)
86
86
if api .nvim_buf_is_loaded (quartoOutputBuf ) then
87
87
api .nvim_buf_delete (quartoOutputBuf , { force = true })
88
88
end
89
- end
89
+ end ,
90
90
})
91
91
end
92
92
end
93
93
94
94
function M .quartoClosePreview ()
95
- local success , quartoOutputBuf = pcall (api .nvim_buf_get_var , 0 , ' quartoOutputBuf' )
96
- if not success then return end
95
+ local success , quartoOutputBuf = pcall (api .nvim_buf_get_var , 0 , " quartoOutputBuf" )
96
+ if not success then
97
+ return
98
+ end
97
99
if api .nvim_buf_is_loaded (quartoOutputBuf ) then
98
100
api .nvim_buf_delete (quartoOutputBuf , { force = true })
99
101
end
100
102
end
101
103
102
104
M .searchHelp = function (cmd_input )
103
105
local topic = cmd_input .args
104
- local url = ' https://quarto.org/?q=' .. topic .. ' &show-results=1'
106
+ local url = " https://quarto.org/?q=" .. topic .. " &show-results=1"
105
107
local sysname = vim .loop .os_uname ().sysname
106
108
local cmd
107
109
if sysname == " Linux" then
@@ -110,15 +112,16 @@ M.searchHelp = function(cmd_input)
110
112
cmd = ' open "' .. url .. ' "'
111
113
else
112
114
print (
113
- ' sorry, I do not know how to make Windows open a url with the default browser. This feature currently only works on linux and mac.' )
115
+ " sorry, I do not know how to make Windows open a url with the default browser. This feature currently only works on linux and mac."
116
+ )
114
117
return
115
118
end
116
119
vim .fn .jobstart (cmd )
117
120
end
118
121
119
122
M .activate = function ()
120
123
local tsquery = nil
121
- if M .config .lspFeatures .chunks == ' curly' then
124
+ if M .config .lspFeatures .chunks == " curly" then
122
125
tsquery = [[
123
126
(fenced_code_block
124
127
(info_string
@@ -134,45 +137,49 @@ M.activate = function()
134
137
135
138
]]
136
139
end
137
- otter .activate (M .config .lspFeatures .languages , M .config .lspFeatures .completion .enabled ,
138
- M .config .lspFeatures .diagnostics .enabled , tsquery )
140
+ otter .activate (
141
+ M .config .lspFeatures .languages ,
142
+ M .config .lspFeatures .completion .enabled ,
143
+ M .config .lspFeatures .diagnostics .enabled ,
144
+ tsquery
145
+ )
139
146
end
140
147
141
-
142
148
-- setup
143
149
M .setup = function (opt )
144
- M .config = vim .tbl_deep_extend (' force' , M .defaultConfig , opt or {})
150
+ M .config = vim .tbl_deep_extend (" force" , M .defaultConfig , opt or {})
145
151
end
146
152
147
153
local function concat (ls )
148
- if not (type (ls ) == " table" ) then return ls .. ' \n\n ' end
149
- local s = ' '
154
+ if not (type (ls ) == " table" ) then
155
+ return ls .. " \n\n "
156
+ end
157
+ local s = " "
150
158
for _ , l in ipairs (ls ) do
151
- if l ~= ' ' then
152
- s = s .. ' \n ' .. l
159
+ if l ~= " " then
160
+ s = s .. " \n " .. l
153
161
end
154
162
end
155
- return s .. ' \n '
163
+ return s .. " \n "
156
164
end
157
165
158
166
local function send (lines )
159
167
lines = concat (lines )
160
- local success , yarepl = pcall (require , ' yarepl' )
168
+ local success , yarepl = pcall (require , " yarepl" )
161
169
if success then
162
170
yarepl ._send_strings (0 )
163
171
else
164
- vim .fn [' slime#send' ](lines )
172
+ vim .fn [" slime#send" ](lines )
165
173
if success then
166
- vim .fn .notify (' Install a REPL code sending plugin to use this feature. Options are yarepl.nvim and vim-slim.' )
174
+ vim .fn .notify (" Install a REPL code sending plugin to use this feature. Options are yarepl.nvim and vim-slim." )
167
175
end
168
176
end
169
177
end
170
178
171
179
M .quartoSend = function ()
172
180
local lines = otterkeeper .get_language_lines_around_cursor ()
173
181
if lines == nil then
174
- print (
175
- ' No code chunk detected around cursor' )
182
+ print (" No code chunk detected around cursor" )
176
183
return
177
184
end
178
185
send (lines )
@@ -182,29 +189,30 @@ M.quartoSendAbove = function()
182
189
local lines = otterkeeper .get_language_lines_to_cursor (true )
183
190
if lines == nil then
184
191
print (
185
- ' No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?' )
192
+ " No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?"
193
+ )
186
194
return
187
195
end
188
196
send (lines )
189
197
end
190
198
191
-
192
199
M .quartoSendBelow = function ()
193
200
local lines = otterkeeper .get_language_lines_from_cursor (true )
194
201
if lines == nil then
195
202
print (
196
- ' No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?' )
203
+ " No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?"
204
+ )
197
205
return
198
206
end
199
207
send (lines )
200
208
end
201
209
202
-
203
210
M .quartoSendAll = function ()
204
211
local lines = otterkeeper .get_language_lines (true )
205
212
if lines == nil then
206
213
print (
207
- ' No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?' )
214
+ " No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?"
215
+ )
208
216
return
209
217
end
210
218
send (lines )
@@ -214,12 +222,11 @@ M.quartoSendRange = function()
214
222
local lines = otterkeeper .get_language_lines_in_visual_selection (true )
215
223
if lines == nil then
216
224
print (
217
- ' No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?' )
225
+ " No code chunks found for the current language, which is detected based on the current code block. Is your cursor in a code block?"
226
+ )
218
227
return
219
228
end
220
229
send (lines )
221
230
end
222
231
223
-
224
-
225
232
return M
0 commit comments