-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when sending code to the console when there are roxygen2-type comments #106
Comments
Looks like the issue is there: Line 23 in cb65c3b
|
This is a feature, not a bug. Someone in the past asked for this. The goal is to be able to send sample code from the ROxygen comment area, but any change in this behavior will be good for me. We can remove the feature, create an option to disable it, or leave it as is. |
Ok, good to know. I'm happy either way, at least knowing that's the expected behaviour. I'd say it's a bit odd (because it prevents you from doing precisely what I was doing, sending whole blocks). Testing code in the ROxygen comment area seems somewhat niche. However, I'm happy with whatever the consensus is. |
Popping in here to say that I have been using this feature heavily when developing packages (confirming that example code works as written). IIRC, the behaviour in Nvim-R used to be that only code between |
I set this up so that it only strips out the Practically, this was a nice middle-ground - it allows you to send examples to the console, while also letting you send large blocks of code without treating the roxygen headers as code. The little snippet is in my dotfiles, though approach with caution - I'm not particularly proficient in vimscript. Made for use with function SlimeOverride_EscapeText_r(text)
let lines = split(a:text, '\n')
let linesi = range(0, len(lines) - 1)
" strip roxygen comment characters if all lines start with #' and no
" lines continue by starting with a roxygen @tag
let rox_re = '^\s*#\'''
let is_rox = repeat([0], len(lines))
for i in linesi | let is_rox[i] = lines[i] =~ rox_re | endfor
let is_roxtag = repeat([0], len(lines))
for i in linesi | let is_roxtag[i] = lines[i] =~ rox_re . '\s*@' | endfor
if min(is_rox) && !max(is_roxtag)
let rox_lines = map(deepcopy(lines), {_, x -> substitute(x, rox_re, '', "g")})
let n_lead_ws = len(a:text)
for i in linesi
let n_lead_ws = min([
\ n_lead_ws,
\ len(substitute(rox_lines[i], '^\(\s*\).*', '\1', "g"))
\ ])
endfor
return(join(map(rox_lines, {_, x -> x[n_lead_ws:] . "\r"}), ""))
endif
return a:text
endfunction |
That could be a good logic to use here to be implemented in lua. |
Not a solution, but in someway related, I use a custom map/keybinding to execute code after keymap("n", "<A-r>#", "<esc>F#<esc>wv$<localleader>ss", { desc = "R run commented line" }) |
If there are roxygen2-type comments (preceded by
#'
) and these are part of a selection being sent to the R console, there will be an error. E.g., if you haveand you visually select the two functions and send to the R session, I get
Error: unexpected symbol in " Another function."
.The text was updated successfully, but these errors were encountered: