11local M = {}
22local 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 " )
77
88M .defaultConfig = {
99 debug = false ,
1010 closePreviewOnExit = true ,
1111 lspFeatures = {
1212 enabled = true ,
13- chunks = ' curly' ,
14- languages = { ' r ' , ' python' , ' julia' , ' bash' , ' html' },
13+ chunks = " curly" ,
14+ languages = { " r " , " python" , " julia" , " bash" , " html" },
1515 diagnostics = {
1616 enabled = true ,
17- triggers = { " BufWritePost" }
17+ triggers = { " BufWritePost" },
1818 },
1919 completion = {
2020 enabled = true ,
2121 },
2222 },
2323 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+ },
3232}
3333
3434-- use defaultConfig if not setup
3535M .config = M .defaultConfig
3636
3737function M .quartoPreview (opts )
3838 opts = opts or {}
39- local args = opts .args or ' '
39+ local args = opts .args or " "
4040
4141 -- find root directory / check if it is a project
4242 local buffer_path = api .nvim_buf_get_name (0 )
@@ -45,13 +45,13 @@ function M.quartoPreview(opts)
4545 local mode
4646 if root_dir then
4747 mode = " project"
48- cmd = ' quarto preview' .. ' ' .. args
48+ cmd = " quarto preview" .. " " .. args
4949 else
5050 mode = " file"
5151 if vim .loop .os_uname ().sysname == " Windows_NT" then
52- cmd = ' quarto preview \\ "' .. buffer_path .. ' \\ "' .. ' ' .. args
52+ cmd = ' quarto preview \\ "' .. buffer_path .. ' \\ "' .. " " .. args
5353 else
54- cmd = ' quarto preview \' ' .. buffer_path .. ' \' ' .. ' ' .. args
54+ cmd = " quarto preview ' " .. buffer_path .. " ' " .. " " .. args
5555 end
5656 end
5757
@@ -68,10 +68,10 @@ function M.quartoPreview(opts)
6868
6969 -- run command in embedded terminal
7070 -- in a new tab and go back to the buffer
71- vim .cmd (' tabedit term://' .. cmd )
71+ vim .cmd (" tabedit term://" .. cmd )
7272 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 )
7575
7676 if not M .config then
7777 return
@@ -86,22 +86,24 @@ function M.quartoPreview(opts)
8686 if api .nvim_buf_is_loaded (quartoOutputBuf ) then
8787 api .nvim_buf_delete (quartoOutputBuf , { force = true })
8888 end
89- end
89+ end ,
9090 })
9191 end
9292end
9393
9494function 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
9799 if api .nvim_buf_is_loaded (quartoOutputBuf ) then
98100 api .nvim_buf_delete (quartoOutputBuf , { force = true })
99101 end
100102end
101103
102104M .searchHelp = function (cmd_input )
103105 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"
105107 local sysname = vim .loop .os_uname ().sysname
106108 local cmd
107109 if sysname == " Linux" then
@@ -110,15 +112,16 @@ M.searchHelp = function(cmd_input)
110112 cmd = ' open "' .. url .. ' "'
111113 else
112114 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+ )
114117 return
115118 end
116119 vim .fn .jobstart (cmd )
117120end
118121
119122M .activate = function ()
120123 local tsquery = nil
121- if M .config .lspFeatures .chunks == ' curly' then
124+ if M .config .lspFeatures .chunks == " curly" then
122125 tsquery = [[
123126 (fenced_code_block
124127 (info_string
@@ -134,45 +137,49 @@ M.activate = function()
134137
135138 ]]
136139 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+ )
139146end
140147
141-
142148-- setup
143149M .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 {})
145151end
146152
147153local 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 = " "
150158 for _ , l in ipairs (ls ) do
151- if l ~= ' ' then
152- s = s .. ' \n ' .. l
159+ if l ~= " " then
160+ s = s .. " \n " .. l
153161 end
154162 end
155- return s .. ' \n '
163+ return s .. " \n "
156164end
157165
158166local function send (lines )
159167 lines = concat (lines )
160- local success , yarepl = pcall (require , ' yarepl' )
168+ local success , yarepl = pcall (require , " yarepl" )
161169 if success then
162170 yarepl ._send_strings (0 )
163171 else
164- vim .fn [' slime#send' ](lines )
172+ vim .fn [" slime#send" ](lines )
165173 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." )
167175 end
168176 end
169177end
170178
171179M .quartoSend = function ()
172180 local lines = otterkeeper .get_language_lines_around_cursor ()
173181 if lines == nil then
174- print (
175- ' No code chunk detected around cursor' )
182+ print (" No code chunk detected around cursor" )
176183 return
177184 end
178185 send (lines )
@@ -182,29 +189,30 @@ M.quartoSendAbove = function()
182189 local lines = otterkeeper .get_language_lines_to_cursor (true )
183190 if lines == nil then
184191 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+ )
186194 return
187195 end
188196 send (lines )
189197end
190198
191-
192199M .quartoSendBelow = function ()
193200 local lines = otterkeeper .get_language_lines_from_cursor (true )
194201 if lines == nil then
195202 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+ )
197205 return
198206 end
199207 send (lines )
200208end
201209
202-
203210M .quartoSendAll = function ()
204211 local lines = otterkeeper .get_language_lines (true )
205212 if lines == nil then
206213 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+ )
208216 return
209217 end
210218 send (lines )
@@ -214,12 +222,11 @@ M.quartoSendRange = function()
214222 local lines = otterkeeper .get_language_lines_in_visual_selection (true )
215223 if lines == nil then
216224 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+ )
218227 return
219228 end
220229 send (lines )
221230end
222231
223-
224-
225232return M
0 commit comments