From ad0c8c8f6f8f32c642a8f7c2f8a185316d005d94 Mon Sep 17 00:00:00 2001 From: Pocco81 Date: Thu, 15 Jul 2021 11:19:52 -0500 Subject: [PATCH] added doc and fixed small logic issues with debounce_delay --- README.md | 13 +++++++------ doc/autosave.txt | 8 ++++++-- lua/autosave/config.lua | 2 +- lua/autosave/modules/autocmds.lua | 6 ++++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index efeb7b0..06e8378 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ # 📺 Notices Checkout the [CHANGELOG.md](https://github.com/Pocco81/AutoSave.nvim/blob/main/CHANGELOG.md) file for more information on the notices below: ++ **15-07-21**: Implemented debounce_delay setting thanks to #7. + **04-07-21**: Fixed #1. + **01-07-21**: Just released! @@ -131,7 +132,7 @@ conditions = { write_all_buffers = false, on_off_commands = false, clean_command_line_interval = 0, -debounce_delay = 140 +debounce_delay = 135 ``` The way you setup the settings on your config varies on whether you are using vimL for this or Lua. @@ -155,8 +156,8 @@ autosave.setup( }, write_all_buffers = false, on_off_commands = true, - clean_command_line_interval = 2500, - debounce_delay = 140 + clean_command_line_interval = 0, + debounce_delay = 135 } ) ``` @@ -184,8 +185,8 @@ autosave.setup( }, write_all_buffers = false, on_off_commands = true, - clean_command_line_interval = 2500, - debounce_delay = 140 + clean_command_line_interval = 0, + debounce_delay = 135 } ) EOF @@ -221,7 +222,7 @@ Although settings already have self-explanatory names, here is where you can fin + `write_all_buffers`: (Boolean) if true, writes to all modifiable buffers that meet the `conditions`. + `on_off_commands`: (Boolean) if true, enables extra commands for toggling the plugin on and off (`:ASOn` and `:ASOff`). + `clean_command_line_interval` (Integer) if greater than 0, cleans the command line after *x* amount of milliseconds after printing the `execution_message`. -+ `debounce_delay` (Integer) if greater than 0, saves the file at most every `debounce_delay` milliseconds. This can improve editing performance. If 0 then saves are performed immediately on each edit. Default `140`, which is just long enough to reduce unnecessary saves, but short enough that you don't notice the delay. ++ `debounce_delay` (Integer) if greater than 0, saves the file at most every `debounce_delay` milliseconds, vastly improving editing performance. If 0 then saves are performed immediately after `events` occur. It's recommend to leave the default value (`130`), which is just long enough to reduce unnecessary saves, but short enough that you don't notice the delay. ## Conditions These are the conditions that every file must meet so that it can be saved. If every file to be auto-saved doesn't meet all of the conditions it won't be saved. diff --git a/doc/autosave.txt b/doc/autosave.txt index bfd38cf..ba9d12b 100644 --- a/doc/autosave.txt +++ b/doc/autosave.txt @@ -72,6 +72,7 @@ conditions = { write_all_buffers = false, on_off_commands = false, clean_command_line_interval = 0 +debounce_delay = 135 ``` The way you setup the settings on your config varies on whether you are using vimL for this or Lua. @@ -93,7 +94,8 @@ autosave.setup( }, write_all_buffers = false, on_off_commands = true, - clean_command_line_interval = 2500 + clean_command_line_interval = 0 + debounce_delay = 135 } ) ``` @@ -116,7 +118,8 @@ autosave.setup( }, write_all_buffers = false, on_off_commands = true, - clean_command_line_interval = 2500 + clean_command_line_interval = 0 + debounce_delay = 135 } ) EOF @@ -152,6 +155,7 @@ Although settings already have self-explanatory names, here is where you can fin + `write_all_buffers`: (Boolean) if true, writes to all modifiable buffers that meet the `conditions`. + `on_off_commands`: (Boolean) if true, enables extra commands for toggling the plugin on and off (`:ASOn` and `:ASOff`). + `clean_command_line_interval` (Integer) if greater than 0, cleans the command line after *x* amount of milliseconds after printing the `execution_message`. ++ `debounce_delay` (Integer) if greater than 0, saves the file at most every `debounce_delay` milliseconds, vastly improving editing performance. If 0 then saves are performed immediately after `events` occur. It's recommend to leave the default value (`130`), which is just long enough to reduce unnecessary saves, but short enough that you don't notice the delay. ## Conditions These are the conditions that every file must meet so that it can be saved. If every file to be auto-saved doesn't meet all of the conditions it won't be saved. diff --git a/lua/autosave/config.lua b/lua/autosave/config.lua index 9d0ab62..d5215be 100644 --- a/lua/autosave/config.lua +++ b/lua/autosave/config.lua @@ -12,7 +12,7 @@ config.options = { write_all_buffers = false, on_off_commands = false, clean_command_line_interval = 0, - debounce_delay = 140 + debounce_delay = 135 } function config.set_options(opts) diff --git a/lua/autosave/modules/autocmds.lua b/lua/autosave/modules/autocmds.lua index b40247e..6306c57 100644 --- a/lua/autosave/modules/autocmds.lua +++ b/lua/autosave/modules/autocmds.lua @@ -6,6 +6,8 @@ local opts = require("autosave.config").options local autosave = require("autosave") local default_event = "InsertLeave" +local modified + local M = {} local function table_has_value(tbl, value) @@ -27,7 +29,7 @@ local function get_modified() end local function actual_save() - -- might use update, but in that case it can't be checekd if a file was modified and so it will always + -- might use update, but in that case it can't be checked if a file was modified and so it will always -- print opts["execution_message"] if (api.nvim_eval([[&modified]]) == 1) then cmd("silent! write") @@ -148,7 +150,7 @@ local function parse_events() end function M.load_autocommands() - if opts["debounce_delay"] == false then + if opts["debounce_delay"] == 0 then M.debounced_save = actual_save else M.debounced_save = debounce(actual_save, opts["debounce_delay"])