@@ -49,15 +49,37 @@ imap(";", ";<c-g>u")
49
49
50
50
nmap (" Q" , " <Nop>" )
51
51
52
+ local M = {}
53
+ M .reticulate_running = false
54
+ local function send_cell ()
55
+ if vim .b [" quarto_is_" .. " r" .. " _mode" ] == nil then
56
+ vim .cmd [[ call slime#send_cell()]]
57
+ return
58
+ end
59
+ if vim .b [" quarto_is_" .. " r" .. " _mode" ] == true then
60
+ vim .g .slime_python_ipython = 0
61
+ local is_python = require (" otter.tools.functions" ).is_otter_language_context (" python" )
62
+ if is_python and not M .reticulate_running then
63
+ vim .cmd [[ call slime#send("reticulate::repl_python()" . "\r")]]
64
+ M .reticulate_running = true
65
+ end
66
+ if not is_python and M .reticulate_running then
67
+ vim .cmd [[ call slime#send("exit" . "\r")]]
68
+ M .reticulate_running = false
69
+ end
70
+ vim .cmd [[ call slime#send_cell()]]
71
+ end
72
+ end
73
+
52
74
-- send code with ctrl+Enter
53
75
-- just like in e.g. RStudio
54
76
-- needs kitty (or other terminal) config:
55
77
-- map shift+enter send_text all \x1b[13;2u
56
78
-- map ctrl+enter send_text all \x1b[13;5u
57
- nmap (" <c-cr>" , " <Plug>SlimeSendCell " )
58
- nmap (" <s-cr>" , " <Plug>SlimeSendCell " )
59
- imap (" <c-cr>" , " <esc><Plug>SlimeSendCell<cr>i " )
60
- imap (" <s-cr>" , " <esc><Plug>SlimeSendCell<cr>i " )
79
+ nmap (" <c-cr>" , send_cell )
80
+ nmap (" <s-cr>" , send_cell )
81
+ imap (" <c-cr>" , send_cell )
82
+ imap (" <s-cr>" , send_cell )
61
83
62
84
-- send code with Enter and leader Enter
63
85
vmap (" <cr>" , " <Plug>SlimeRegionSend" )
@@ -102,6 +124,7 @@ local function toggle_light_dark_theme()
102
124
end
103
125
end
104
126
127
+ vim .b [" quarto_is_" .. " r" .. " _mode" ] = nil
105
128
-- show kepbindings with whichkey
106
129
-- add your own here if you want them to
107
130
-- show up in the popup as well
@@ -110,7 +133,10 @@ wk.register({
110
133
name = " code" ,
111
134
c = { " :SlimeConfig<cr>" , " slime config" },
112
135
n = { " :vsplit term://$SHELL<cr>" , " new terminal" },
113
- r = { " :vsplit term://R<cr>" , " new R terminal" },
136
+ r = { function ()
137
+ vim .b [" quarto_is_" .. " r" .. " _mode" ] = true
138
+ vim .cmd " vsplit term://R"
139
+ end , " new R terminal" },
114
140
p = { " :vsplit term://python<cr>" , " new python terminal" },
115
141
i = { " :vsplit term://ipython<cr>" , " new ipython terminal" },
116
142
j = { " :vsplit term://julia<cr>" , " new julia terminal" },
0 commit comments