Skip to content

Commit

Permalink
feat!: depracate REPLSendMotion, use REPLSendOperator instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
milanglacier committed Nov 9, 2023
1 parent bafe287 commit 9d248ae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
+ [REPLSwap](#replswap)
+ [REPLSendVisual](#replsendvisual)
+ [REPLSendLine](#replsendline)
+ [REPLSendMotion](#replsendmotion)
+ [REPLSendOperator](#replsendoperator)
+ [REPLExec](#replexec)
- [Window configuration](#window-configuration)
- [Add your own REPLs](#add-your-own-repls)
Expand Down Expand Up @@ -344,9 +344,9 @@ Here are examples of how to use this command:
4. `3REPLSendLine ipython` sends the current line to the closest ipython REPL
relative to id `3`.

### REPLSendMotion
### REPLSendOperator

Sends the motion to REPL `i` or the REPL that the current buffer
The opeerator to send the text to REPL `i` or the REPL that the current buffer
is attached to.

If you provide an optional argument, the function will attempt to send to the
Expand All @@ -357,18 +357,19 @@ send to REPL `i`.

Here are examples of how to use this command:

1. `REPLSendMotion` sends the motion to the REPL that the current buffer
is attached to. If the buffer is not attached to any REPL, it uses REPL 1.
1. `REPLSendOperator` acts as the operator to send the text to the REPL that
the current buffer is attached to. If the buffer is not attached to any
REPL, it uses REPL 1.

2. `3REPLSendMotion` sends the motion to REPL 3.
2. `3REPLSendOperator` sends the motion to REPL 3.

3. `REPLSendMotion ipython` sends the motion to the closest ipython REPL
3. `REPLSendOperator ipython` sends the motion to the closest ipython REPL
relative to id `1`.

4. `3REPLSendMotion ipython` sends the motion to the closest ipython REPL
4. `3REPLSendOperator ipython` sends the motion to the closest ipython REPL
relative to id `3`.

`REPLSendMotion` is **dot-repeatable**, you do not need to install
`REPLSendOperator` is **dot-repeatable**, you do not need to install
vim-repeat to make it work.

### REPLExec
Expand Down Expand Up @@ -655,8 +656,8 @@ keymap('n', '<Leader>crr', '', {
-- `2<Leader>crap` will send a paragraph to the second aichat REPL. Note that
-- `ap` is just an example and can be replaced with any text object or motion.
keymap('n', '<Leader>cr', '', {
callback = run_cmd_with_count 'REPLSendMotion aichat',
desc = 'Send motion to Aichat',
callback = run_cmd_with_count 'REPLSendOperator aichat',
desc = 'Operator to Send text to Aichat',
})
keymap('n', '<Leader>cq', '', {
callback = run_cmd_with_count 'REPLClose aichat',
Expand Down Expand Up @@ -718,8 +719,8 @@ autocmd('FileType', {
-- `2<Leader>sap` will send the paragraph to REPL 2. Note that `ap` is
-- just an example and can be replaced with any text object or motion.
bufmap(0, 'n', '<LocalLeader>s', '', {
callback = run_cmd_with_count 'REPLSendMotion',
desc = 'Send motion to REPL',
callback = run_cmd_with_count 'REPLSendOperator',
desc = 'Operator to send to REPL',
})
bufmap(0, 'n', '<LocalLeader>rq', '', {
callback = run_cmd_with_count 'REPLClose',
Expand Down Expand Up @@ -755,7 +756,7 @@ autocmd('FileType', {
The `run_cmd_with_count` function ensures that any numeric prefix given to a
keybinding, such as `3<LocalLeader>rs`, `2<LocalLeader>s`, and `5<Leader>cr`,
is passed to the corresponding command. For instance, `2REPLStart aichat` is
equivalent to `2<Leader>cs`, and `3REPLSendMotion` is equivalent to
equivalent to `2<Leader>cs`, and `3REPLSendOperator` is equivalent to
`3<LocalLeader>s`.

With the keybinding setup, prefixing keybindings with `<Leader>c` ensures that
Expand Down
38 changes: 34 additions & 4 deletions lua/yarepl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ M.formatter.bracketed_pasting_no_final_new_line = M.formatter.factory {
},
}

M._send_motion_internal = function(motion)
M._send_operator_internal = function(motion)
-- hack: allow dot-repeat
if motion == nil then
vim.go.operatorfunc = [[v:lua.require'yarepl'._send_motion_internal]]
vim.go.operatorfunc = [[v:lua.require'yarepl'._send_operator_internal]]
api.nvim_feedkeys('g@', 'ni', false)
end

Expand Down Expand Up @@ -742,7 +742,37 @@ Send current line to REPL `i` or the REPL that current buffer is attached to.
]],
})

api.nvim_create_user_command('REPLSendOperator', function(opts)
local repl_name = opts.args
local id = opts.count

if repl_name ~= '' then
vim.b[0].closest_repl_name = repl_name
else
vim.b[0].closest_repl_name = nil
end

if id ~= 0 then
vim.b[0].repl_id = id
else
vim.b[0].repl_id = nil
end

vim.go.operatorfunc = [[v:lua.require'yarepl'._send_operator_internal]]
-- Those magic letters 'ni' are coming from Vigemus/iron.nvim and I am not
-- quite understand the effect of those magic letters.
api.nvim_feedkeys('g@', 'ni', false)
end, {
count = true,
nargs = '?',
desc = [[
The operator of send text to REPL `i` or the REPL that current buffer is attached to.
]],
})

api.nvim_create_user_command('REPLSendMotion', function(opts)
vim.notify('REPLSendMotion is deprecated, please use the command REPLSendOperator', vim.log.levels.WARN)

local repl_name = opts.args
local id = opts.count

Expand All @@ -758,15 +788,15 @@ api.nvim_create_user_command('REPLSendMotion', function(opts)
vim.b[0].repl_id = nil
end

vim.go.operatorfunc = [[v:lua.require'yarepl'._send_motion_internal]]
vim.go.operatorfunc = [[v:lua.require'yarepl'._send_operator_internal]]
-- Those magic letters 'ni' are coming from Vigemus/iron.nvim and I am not
-- quite understand the effect of those magic letters.
api.nvim_feedkeys('g@', 'ni', false)
end, {
count = true,
nargs = '?',
desc = [[
Send motion to REPL `i` or the REPL that current buffer is attached to.
The operator of send text to REPL `i` or the REPL that current buffer is attached to.
]],
})

Expand Down

0 comments on commit 9d248ae

Please sign in to comment.