-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add command
:SosBufToggle
to toggle buffers
This command allows for ignoring individual buffers so that they do not get autosaved. It accepts an optional `[bufname]` argument to specify a buffer other than the current one. Deleting a buffer (e.g. `:bdelete`) resets its ignored status. Ignore status is stored in the buffer variable `b:sos_ignore`. Also add dedicated API functions for this, as well as functions to enable or disable the entire plugin. These can all be found in the `require('sos')` module table. Also do some refactoring/cleanup: - Rename `lua/bufevents.lua` -> `lua/observer.lua` - Remove `lua/plugin.lua` (require main module instead) - Main module `require('sos')` is now the entry point (incl. when the plugin is sourced by nvim at startup) and also holds most of the plugin's state - Make all config fields optional (in the class/type) - Update `init.lua` to handle module reloading (UNFINISHED) - Update `util.lua` with new utility functions and error handling - Improve benchmark interface
- Loading branch information
Showing
20 changed files
with
889 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
local asrt = require 'sos._test.assert' | ||
local util = require 'sos._test.util' | ||
local api = vim.api | ||
local M = { buf = {} } | ||
|
||
function M.input(keys) | ||
api.nvim_feedkeys( | ||
api.nvim_replace_termcodes(keys, true, true, true), | ||
-- 'mtx', | ||
'L', | ||
false | ||
) | ||
|
||
util.await_schedule() | ||
end | ||
|
||
function M.cmd(cmd) | ||
asrt.normal_mode_nonblocking() | ||
M.input(':' .. cmd .. '<CR>') | ||
asrt.normal_mode_nonblocking() | ||
end | ||
|
||
---NOTE: May change the current buffer! | ||
function M.trigger_save(buf) | ||
if buf and buf ~= 0 and buf ~= api.nvim_get_current_buf() then | ||
assert(api.nvim_buf_is_valid(buf), 'invalid buffer number: ' .. buf) | ||
local ei = vim.o.ei | ||
vim.o.ei = 'all' | ||
api.nvim_set_current_buf(buf) | ||
vim.o.ei = ei | ||
end | ||
|
||
M.cmd 'tabnew' | ||
end | ||
|
||
function M.buf.modify() | ||
assert.is_false(vim.bo.mod, 'buffer is already modified') | ||
M.input 'ochanges<Esc>' | ||
assert.is_true(vim.bo.mod, 'modification unsuccessful') | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
local api = vim.api | ||
local M = {} | ||
|
||
function M.normal_mode_nonblocking() | ||
local m = api.nvim_get_mode() | ||
assert.equals('n', m.mode, 'not in regular normal mode') | ||
assert.is_false(api.nvim_get_mode().blocking, 'mode is blocking') | ||
end | ||
|
||
-- function M.all_bufs_saved() | ||
-- assert.same( | ||
-- {}, | ||
-- vim.fn.getbufinfo { bufmodified = 1 }, | ||
-- 'all buffers should be saved, and none modified' | ||
-- ) | ||
-- end | ||
|
||
---@param buf number | ||
function M.saved(buf) | ||
vim.validate { buf = { buf, { 'number' }, false } } | ||
local file = api.nvim_buf_get_name(buf) | ||
assert.is_false(vim.bo[buf].mod, 'buffer is still modified') | ||
assert.same( | ||
api.nvim_buf_get_lines(buf, 0, -1, true), | ||
vim.fn.readfile(file), | ||
"buffer wasn't saved" | ||
) | ||
end | ||
|
||
---@param buf number | ||
function M.unsaved(buf) | ||
vim.validate { buf = { buf, { 'number' }, false } } | ||
local file = api.nvim_buf_get_name(buf) | ||
assert.is_true(vim.bo[buf].mod, "buffer shouldn't have been saved") | ||
local ok, content = pcall(vim.fn.readfile, file) | ||
if not ok then return end | ||
assert.not_same( | ||
api.nvim_buf_get_lines(buf, 0, -1, true), | ||
content, | ||
"buffer shouldn't have been saved" | ||
) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.