Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhuster committed Jan 21, 2025
1 parent 2ff3d37 commit 8fb9930
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/livepreview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ configuration file.
:lua LivePreview.config.port = 8080
<
To get the value of an option, run: >vim
:=LivePreview.config.<option>
:= LivePreview.config.<option>
<
==============================================================================
4. FAQ
Expand Down
6 changes: 3 additions & 3 deletions lua/livepreview/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ M.pickers = {
---@field browser string? browser to open the preview in
---@field dynamic_root boolean? Whether to use the basename of the file as the root
---@field sync_scroll boolean? Whether to sync scroll the preview with the editor
M.default_config = {
picker = "fzf-lua",
M.default = {
picker = nil,
autokill = false,
port = 5500,
browser = "default",
dynamic_root = false,
sync_scroll = true,
}

M.config = vim.deepcopy(M.default_config)
M.config = vim.deepcopy(M.default)

--- Configure live-preview.nvim
--- @param opts Config?
Expand Down
2 changes: 1 addition & 1 deletion lua/livepreview/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end

local function check_config()
local config = require("livepreview.config").config
local default_config = require("livepreview.config").default_config
local default_config = require("livepreview.config").default
local info = vim.health.info
local ok = true
for k, _ in pairs(config) do
Expand Down
17 changes: 11 additions & 6 deletions plugin/livepreview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,29 @@ end, {
end,
})


--- Public API
LivePreview = {
config = require("livepreview.config").default_config,
config = {}
}
local configMetatable = {

for k, _ in pairs(require 'livepreview.config'.default) do
LivePreview.config[k] = nil
end

setmetatable(LivePreview.config, {
__index = function(_, key)
if vim.fn.has_key(LivePreview.config, key) == 0 then
if vim.fn.has_key(require 'livepreview.config'.default, key) == 0 then
vim.notify(("Error: live-preview.nvim has no config option '%s'"):format(key), vim.log.levels.ERROR)
return
end
return require("livepreview.config").config[key]
end,
__newindex = function(_, key, value)
if vim.fn.has_key(LivePreview.config, key) == 0 then
if vim.fn.has_key(require 'livepreview.config'.default, key) == 0 then
vim.notify(("Error: live-preview.nvim has no config option '%s'"):format(key), vim.log.levels.ERROR)
return
end
require("livepreview.config").set({ [key] = value })
end,
}
setmetatable(LivePreview.config, configMetatable)
})

0 comments on commit 8fb9930

Please sign in to comment.