-
-
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
17 changed files
with
863 additions
and
398 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
local util = require 'sos._test.util' | ||
local api = vim.api | ||
local M = { buf = {} } | ||
|
||
-- api.nvim_feedkeys( | ||
-- api.nvim_replace_termcodes(':new<CR>', true, true, true), | ||
-- 'L', | ||
-- -- 'mtx', | ||
-- false | ||
-- ) | ||
|
||
function M.input(keys) | ||
assert.equals('n', api.nvim_get_mode().mode, 'not in normal mode') | ||
assert.is_false(api.nvim_get_mode().blocking) | ||
api.nvim_feedkeys( | ||
api.nvim_replace_termcodes(keys, true, true, true), | ||
-- 'L', | ||
'mtx', | ||
false | ||
) | ||
|
||
util.await_schedule() | ||
end | ||
|
||
function M.cmd(cmd) | ||
assert.equals('n', api.nvim_get_mode().mode, 'not in normal mode') | ||
assert.is_false(api.nvim_get_mode().blocking) | ||
M.input(':' .. cmd .. '<CR>') | ||
assert.equals('n', api.nvim_get_mode().mode, 'not in normal mode') | ||
assert.is_false(api.nvim_get_mode().blocking) | ||
end | ||
|
||
---NOTE: May change the current buffer! | ||
function M.trigger_save(buf) | ||
assert.equals('n', api.nvim_get_mode().mode, 'not in normal mode') | ||
assert.is_false(api.nvim_get_mode().blocking) | ||
|
||
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' | ||
-- util.await_schedule() | ||
end | ||
|
||
function M.buf.modify() | ||
assert.is_false(vim.bo.mod, 'buffer is modified prior to modification') | ||
M.input 'ochanges<Esc>' | ||
assert.is_true(vim.bo.mod, 'unable to modify buffer') | ||
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,38 @@ | ||
local api = vim.api | ||
local M = {} | ||
|
||
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(file, 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(file, 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.