diff --git a/lua/thethethe/config.lua b/lua/thethethe/config.lua deleted file mode 100644 index 1906a51..0000000 --- a/lua/thethethe/config.lua +++ /dev/null @@ -1,6 +0,0 @@ -local M = {} - --- Time (milliseconds) to wait before loading abbreviations -M.delay_ms = 2000 - -return M diff --git a/lua/thethethe/init.lua b/lua/thethethe/init.lua index 13f9a49..74f390e 100644 --- a/lua/thethethe/init.lua +++ b/lua/thethethe/init.lua @@ -1,37 +1,15 @@ local M = {} --- load abbreviations.dict -local function load_abbreviations() - -- load our dictionary string - local s = require("thethethe.dictionary") - - -- split dictionary by lines - for line in s:gmatch("([^\n]*)\n?") do - -- split each line by the colon - local parts = {} - for part in line:gmatch("[^:]+") do - table.insert(parts, part) - end - - if #parts == 2 and parts[1] and parts[2] then - -- Add abbreviation via `iabbrev` (through vim.cmd) - vim.cmd(string.format("iabbrev %s %s", parts[1], parts[2])) - end - end -end - --- create our exported setup() function function M.setup(opts) - -- load our default configuration - local config = require("thethethe.config") - - -- check for default overrides passed in - if opts then - config.delay_ms = opts.delay_ms or config.delay_ms - end - - -- execute the function after config.delay_ms - vim.defer_fn(load_abbreviations, config.delay_ms) + opts = opts or {} + vim.defer_fn(function() + for line in require("thethethe.dictionary"):gmatch("[^\n]+") do + local typo, fix = line:match("^([^:]+):(.+)$") + if typo and fix then + vim.cmd.iabbrev(typo, fix) + end + end + end, opts.delay_ms or 2000) end return M