diff --git a/README.md b/README.md index 3e85634..da5f3cf 100644 --- a/README.md +++ b/README.md @@ -71,5 +71,3 @@ require('preview').setup({ typst = { open = { 'sioyek', '--new-instance' } }, }) ``` - -See `:h preview.nvim` for more information. diff --git a/doc/preview.nvim.txt b/doc/preview.nvim.txt index 753fefc..0b44a91 100644 --- a/doc/preview.nvim.txt +++ b/doc/preview.nvim.txt @@ -1,6 +1,6 @@ *preview.nvim.txt* Async document compilation for Neovim -Author: Raphael +Author: Barrett Ruth License: MIT ============================================================================== @@ -20,19 +20,14 @@ REQUIREMENTS *preview.nvim-requirements - A compiler binary for each configured provider (e.g. `typst`, `latexmk`) ============================================================================== -INSTALLATION *preview.nvim-installation* +SETUP *preview.nvim-setup* -With luarocks (recommended): -> - :Rocks install preview.nvim -< - -With lazy.nvim: ->lua +Load preview.nvim with your package manager. For example, with lazy.nvim: >lua { 'barrettruth/preview.nvim', } < +Call |preview.setup()| to configure providers before use. ============================================================================== CONFIGURATION *preview.nvim-configuration* @@ -161,7 +156,7 @@ COMMANDS *preview.nvim-commands* `stop` Kill active compilation for the current buffer. `clean` Run the provider's clean command. `toggle` Toggle auto-compile on save for the current buffer. - `status` Echo compilation status (idle, compiling, watching). + `status` Echo compilation status (idle, compiling, toggled). ============================================================================== API *preview.nvim-api* @@ -176,9 +171,9 @@ preview.clean({bufnr?}) *preview.clean()* Run the provider's clean command for the buffer. preview.toggle({bufnr?}) *preview.toggle()* - Toggle watch mode for the buffer. When enabled, the buffer is + Toggle auto-compile for the buffer. When enabled, the buffer is immediately compiled and automatically recompiled on each save - (`BufWritePost`). Call again to stop watching. + (`BufWritePost`). Call again to stop. preview.status({bufnr?}) *preview.status()* Returns a |preview.Status| table. @@ -187,7 +182,7 @@ preview.status({bufnr?}) *preview.status()* Status fields:~ `compiling` boolean Whether compilation is active. - `watching` boolean Whether watch mode is active. + `watching` boolean Whether auto-compile is active. `provider` string? Name of the active provider. `output_file` string? Path to the output file. @@ -208,12 +203,6 @@ preview.nvim fires User autocmds with structured data: `PreviewCompileFailed` Compilation failed (non-zero exit). data: `{ bufnr, provider, code, stderr }` -`PreviewWatchStarted` Watch mode enabled for a buffer. - data: `{ bufnr, provider }` - -`PreviewWatchStopped` Watch mode disabled for a buffer. - data: `{ bufnr }` - Example:~ >lua vim.api.nvim_create_autocmd('User', { diff --git a/lua/preview/compiler.lua b/lua/preview/compiler.lua index 6907524..b0c7402 100644 --- a/lua/preview/compiler.lua +++ b/lua/preview/compiler.lua @@ -188,11 +188,6 @@ function M.toggle(bufnr, name, provider, ctx_builder) end, }) - vim.api.nvim_exec_autocmds('User', { - pattern = 'PreviewWatchStarted', - data = { bufnr = bufnr, provider = name }, - }) - M.compile(bufnr, name, provider, ctx_builder(bufnr)) end @@ -205,11 +200,6 @@ function M.unwatch(bufnr) vim.api.nvim_del_autocmd(au_id) watching[bufnr] = nil log.dbg('unwatched buffer %d', bufnr) - - vim.api.nvim_exec_autocmds('User', { - pattern = 'PreviewWatchStopped', - data = { bufnr = bufnr }, - }) end ---@param bufnr integer diff --git a/spec/compiler_spec.lua b/spec/compiler_spec.lua index 7360ceb..6802dee 100644 --- a/spec/compiler_spec.lua +++ b/spec/compiler_spec.lua @@ -190,31 +190,6 @@ describe('compiler', function() helpers.delete_buffer(bufnr) end) - it('fires PreviewWatchStarted event', function() - local bufnr = helpers.create_buffer({ 'hello' }, 'text') - vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_event.txt') - - local fired = false - vim.api.nvim_create_autocmd('User', { - pattern = 'PreviewWatchStarted', - once = true, - callback = function() - fired = true - end, - }) - - local provider = { cmd = { 'echo', 'ok' } } - local ctx_builder = function(b) - return { bufnr = b, file = '/tmp/preview_test_watch_event.txt', root = '/tmp', ft = 'text' } - end - - compiler.toggle(bufnr, 'echo', provider, ctx_builder) - assert.is_true(fired) - - compiler.unwatch(bufnr) - helpers.delete_buffer(bufnr) - end) - it('toggles off when called again', function() local bufnr = helpers.create_buffer({ 'hello' }, 'text') vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_toggle.txt') @@ -233,32 +208,6 @@ describe('compiler', function() helpers.delete_buffer(bufnr) end) - it('fires PreviewWatchStopped on unwatch', function() - local bufnr = helpers.create_buffer({ 'hello' }, 'text') - vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_stop.txt') - - local stopped = false - vim.api.nvim_create_autocmd('User', { - pattern = 'PreviewWatchStopped', - once = true, - callback = function() - stopped = true - end, - }) - - local provider = { cmd = { 'echo', 'ok' } } - local ctx_builder = function(b) - return { bufnr = b, file = '/tmp/preview_test_watch_stop.txt', root = '/tmp', ft = 'text' } - end - - compiler.toggle(bufnr, 'echo', provider, ctx_builder) - compiler.unwatch(bufnr) - assert.is_true(stopped) - assert.is_nil(compiler._test.watching[bufnr]) - - helpers.delete_buffer(bufnr) - end) - it('stop_all clears watches', function() local bufnr = helpers.create_buffer({ 'hello' }, 'text') vim.api.nvim_buf_set_name(bufnr, '/tmp/preview_test_watch_stopall.txt')