You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for this plugin. I was wondering if you could add a feature which can send the block of text to the REPL without the need to visually select.
Consider the code block below.
-- description of function {{{
code
code
code
-- }}}
As long as the cursor is inside the block, calling the function REPLSendBlock would send the code block without having to visually select the block. To make this work, the user would have to provide what an opening and closing regex to mark the beginning and ending of the block. In the example above, opening = "^%-%-[%w%s]+{{{$" and closing = "^%-%-}}}$".
An crude example of how this could be implemented is given below.
localfunctionfind_code_block(start_pattern, end_pattern)
localcur_line=vim.api.nvim_win_get_cursor(0)[1]
localstart_line=nillocalend_line=nil-- Search for starting linefori=cur_line, 1, -1dolocalline_content=vim.api.nvim_buf_get_lines(0, i-1, i, false)[1]
ifline_content:match(start_pattern) thenstart_line=ibreakendend-- Search for ending linelocaltotal_lines=vim.api.nvim_buf_line_count(0)
fori=cur_line, total_linesdolocalline_content=vim.api.nvim_buf_get_lines(0, i-1, i, false)[1]
ifline_content:match(end_pattern) thenend_line=ibreakendend-- Output the resultifstart_lineandend_linethenreturn { start_line, end_line }
elsereturnnilendendapi.nvim_create_user_command('REPLSendBlock', function(opts)
localid=opts.countlocalname=opts.argslocalcurrent_buffer=api.nvim_get_current_buf()
localblock=find_code_block("^#[%w%s]+{{{$", "^#%s+}}}$")
ifblockthenlocalstart_line, end_line=unpack(block)
locallines=api.nvim_buf_get_lines(0, start_line, end_line-1, false)
M._send_strings(id, name, current_buffer, lines)
endend, {
count=true,
nargs='?',
desc=[[Send code block to REPL `i` or the REPL that current buffer is attached to.]],
})
The text was updated successfully, but these errors were encountered:
I don’t think implement this thing into this plugin as a core command is a good idea. Code block is essentially a range of text, or in the vim notion, a text object. And this plug-in already has a command REPLSendMotion which can operate on text object.
By implementing the “code block” as a text objects, you can do whatever operations to the code block, not limited to send them to REPL but many other things like copy, paste, formatting, etc……
I will add a distributional module dist which will include my own function to create code block as text objects (I don’t consider it as part of the core part of this plugin so it be part of the distributional module). You can then register your code block as text object and directly send them to REPL, say:
you bind REPLSendMotion to key sequence <LocalLeader>s, and you register the code block as acand ic,
then you can just use <LocalLeader>sac to send the code block to the REPL.
Thanks for this plugin. I was wondering if you could add a feature which can send the block of text to the REPL without the need to visually select.
Consider the code block below.
As long as the cursor is inside the block, calling the function
REPLSendBlock
would send the code block without having to visually select the block. To make this work, the user would have to provide what an opening and closing regex to mark the beginning and ending of the block. In the example above,opening = "^%-%-[%w%s]+{{{$"
andclosing = "^%-%-}}}$"
.An crude example of how this could be implemented is given below.
The text was updated successfully, but these errors were encountered: