Skip to content

Commit d44187d

Browse files
authored
Merge pull request #10 from fidgetingbits/remove-bufonly
refactor: replace BufOnly plugin with two commands
2 parents e285fef + c487944 commit d44187d

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

cursorless.nvim/lua/cursorless/cursorless.lua

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ local M = {}
77
-- window_get_visible_lines
88
-- { [1] = 28, [2] = 74 }
99
function M.window_get_visible_lines()
10-
-- print('window_get_visible_lines()')
11-
return { vim.fn.line("w0"), vim.fn.line("w$") }
10+
-- print('window_get_visible_lines()')
11+
return { vim.fn.line("w0"), vim.fn.line("w$") }
1212
end
1313

1414
-- Get the coordinates of the current selection
@@ -24,27 +24,28 @@ end
2424
-- 1. run in command mode :vmap <c-a> <Cmd>:call CursorlessLoadExtension()<Cr>
2525
-- 2. Select some text and hit ctrl+a
2626
function M.buffer_get_selection()
27-
local start_pos = vim.fn.getpos("v") -- start of visual selection
28-
local start_line, start_col = start_pos[2], start_pos[3]
29-
local end_pos = vim.fn.getpos(".") -- end of visual selection (cursor position)
30-
local end_line, end_col = end_pos[2], end_pos[3]
31-
local reverse = false
32-
local mode = vim.api.nvim_get_mode().mode
27+
local start_pos = vim.fn.getpos("v") -- start of visual selection
28+
local start_line, start_col = start_pos[2], start_pos[3]
29+
local end_pos = vim.fn.getpos(".") -- end of visual selection (cursor position)
30+
local end_line, end_col = end_pos[2], end_pos[3]
31+
local reverse = false
32+
local mode = vim.api.nvim_get_mode().mode
3333

34-
-- Invert the values depending on if the cursor is before the start
35-
if end_line < start_line or end_col < start_col then
36-
start_line, start_col, end_line, end_col = end_line, end_col, start_line, start_col
37-
reverse = true
38-
end
34+
-- Invert the values depending on if the cursor is before the start
35+
if end_line < start_line or end_col < start_col then
36+
start_line, start_col, end_line, end_col =
37+
end_line, end_col, start_line, start_col
38+
reverse = true
39+
end
3940

40-
-- See https://github.com/cursorless-dev/cursorless/issues/2537 if you want to add more modes
41-
if mode == "V" then
42-
-- Line and block-based visual modes are line-based, so we don't need to track the columns
43-
start_col = 1
44-
end_col = nil
45-
end
41+
-- See https://github.com/cursorless-dev/cursorless/issues/2537 if you want to add more modes
42+
if mode == "V" then
43+
-- Line and block-based visual modes are line-based, so we don't need to track the columns
44+
start_col = 1
45+
end_col = nil
46+
end
4647

47-
return { start_line, start_col, end_line, end_col, reverse }
48+
return { start_line, start_col, end_line, end_col, reverse }
4849
end
4950

5051
-- https://github.com/nvim-treesitter/nvim-treesitter/blob/master/lua/nvim-treesitter/ts_utils.lua#L278
@@ -58,10 +59,10 @@ end
5859
-- another example is :tmap <c-b> <Cmd>lua require("talon.cursorless").select_range(4, 0, 4, 38)<Cr>
5960
-- NOTE: works for any mode (n,i,v,nt) except in t mode
6061
function M.select_range(start_line, start_col, end_line, end_col)
61-
vim.cmd([[normal! :noh]])
62-
vim.api.nvim_win_set_cursor(0, { start_line, start_col })
63-
vim.cmd([[normal v]])
64-
vim.api.nvim_win_set_cursor(0, { end_line, end_col })
62+
vim.cmd([[normal! :noh]])
63+
vim.api.nvim_win_set_cursor(0, { start_line, start_col })
64+
vim.cmd([[normal v]])
65+
vim.api.nvim_win_set_cursor(0, { end_line, end_col })
6566
end
6667

6768
return M

packages/cursorless-neovim-e2e/src/suite/recorded.neovim.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ async function openNewTestEditor(
6767
await client.command(":enew");
6868

6969
if (!openBeside) {
70-
// close all the other buffers
71-
// @see: https://stackoverflow.com/questions/4545275/vim-close-all-buffers-but-this-one
72-
await client.command(":BufOnly!");
70+
// close all the other buffers (<C-^> is needed because e# fails on unnamed buffers)
71+
await client.command("execute '%bd!' | execute 'normal! \\<C-^>'");
7372
}
7473

7574
// standardise newlines so we can easily split the lines

packages/test-harness/src/config/init.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
local temp_dir = os.getenv("TEMP_DIR")
22
local repo_root = os.getenv("CURSORLESS_REPO_ROOT")
33

4-
vim.cmd("source " .. temp_dir .. "/BufOnly.vim/plugin/BufOnly.vim")
5-
64
vim.opt.runtimepath:append(temp_dir .. "/talon.nvim")
75
vim.opt.runtimepath:append(repo_root .. "/dist/cursorless.nvim")
86

scripts/install-neovim-dependencies.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ set -euo pipefail
33

44
npm install -g [email protected]
55

6-
git clone https://github.com/vim-scripts/BufOnly.vim ${TEMP_DIR}/BufOnly.vim
76
git clone https://github.com/hands-free-vim/talon.nvim ${TEMP_DIR}/talon.nvim

0 commit comments

Comments
 (0)