Skip to content

Commit aedf4b6

Browse files
authored
fix: register scratch buffer after changing cwd (#259)
When starting vim in a project that has a top-level CMakeLists.txt in a subdirectory, then calling :CMakeSelectCwd {subdir} writing to the scratch buffer will fail because it doesn't exist yet. Make sure to register the buffer after changing cwd.
1 parent 0854efb commit aedf4b6

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

lua/cmake-tools/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,7 @@ function cmake.select_cwd(cwd_path)
11891189
config.cwd = vim.fn.resolve(input)
11901190
cmake.register_autocmd()
11911191
cmake.register_autocmd_provided_by_users()
1192+
cmake.register_scratch_buffer(config.executor.name, config.runner.name)
11921193
-- end
11931194
cmake.generate({ bang = false, fargs = {} }, nil)
11941195
end)
@@ -1197,6 +1198,7 @@ function cmake.select_cwd(cwd_path)
11971198
config.cwd = vim.fn.resolve(cwd_path.args)
11981199
cmake.register_autocmd()
11991200
cmake.register_autocmd_provided_by_users()
1201+
cmake.register_scratch_buffer(config.executor.name, config.runner.name)
12001202
cmake.generate({ bang = false, fargs = {} }, nil)
12011203
end
12021204
end

lua/cmake-tools/scratch.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ local scratch = {
44
}
55

66
function scratch.create(executor, runner)
7+
if scratch.buffer ~= nil then
8+
return
9+
end
10+
711
scratch.buffer = vim.api.nvim_create_buf(true, true) -- can be search, and is a scratch buffer
812
vim.api.nvim_buf_set_name(scratch.buffer, scratch.name)
913
vim.api.nvim_buf_set_lines(scratch.buffer, 0, 0, false, {

0 commit comments

Comments
 (0)