diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..143ec01 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "workspace.library": ["lua"], + "runtime.version": "Lua 5.4", + "hint.enable": false +} + diff --git a/lua/telekasten.lua b/lua/telekasten.lua index f28b8a7..f595fd7 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -1809,9 +1809,9 @@ local function FindAllTags(opts) end --- Setup(cfg) --- Overrides config with elements from cfg. See lua/telekasten/config.lua for defaults. --- @param cfg table Table of configuration values to override defaults --- Maybe fold into _setup? Also used in chdir, though... +--- Overrides config with elements from cfg. See lua/telekasten/config.lua for defaults. +--- Maybe fold into _setup? Also used in chdir, though... +---@param cfg VaultConfig table of configuration values to override defaults local function Setup(cfg) cfg = cfg or {} @@ -1914,7 +1914,7 @@ end --- _setup(cfg) -- Sets the available vaults and passes further configuration options to Setup --- @param cfg table Table of configuration values +---@param cfg MultiVaultConfig | VaultConfig table of configuration values local function _setup(cfg) if cfg.vaults ~= nil and cfg.default_vault ~= nil then M.vaults = cfg.vaults @@ -1927,6 +1927,7 @@ local function _setup(cfg) elseif cfg.home ~= nil then M.vaults = cfg.vaults or {} cfg.vaults = nil + ---@cast cfg VaultConfig M.vaults["default"] = cfg Setup(cfg) end diff --git a/lua/telekasten/config.lua b/lua/telekasten/config.lua index 1afcf1b..9031bbe 100644 --- a/lua/telekasten/config.lua +++ b/lua/telekasten/config.lua @@ -2,43 +2,48 @@ -- local vim = vim +---@class M: Config local M = {} ---The local class instance of the merged user's configuration this includes all ---default values and highlights filled out +---@type Config local config = {} ---The class definition for the user configuration +---@class Config +---@field options VaultConfig +---@field user {options: VaultConfig} local Config = {} +---Merges the user passed opts with defaults on instantiation +---@param opts VaultConfig +---@return Config function Config:new(opts) local o = { options = opts } assert(o, "User options must be passed in") self.__index = self + -- save a copy of the user's preferences so we can reference exactly what they -- wanted after the config and defaults have been merged. Do this using a copy -- so that reference isn't unintentionally mutated self.user = vim.deepcopy(o) setmetatable(o, self) - return o -end - ----Combine user preferences with defaults preferring the user's own settings -function Config:merge(defaults) + local defaults = Config:get_defaults(o.options.home) assert( defaults and type(defaults) == "table", "A valid config table must be passed to merge" ) - self.options = - vim.tbl_deep_extend("force", defaults.options, self.options or {}) - return self + o.options = vim.tbl_deep_extend("force", defaults.options, o.options or {}) + return o end --- --- Default setup. Ideally anyone should be able to start using Telekasten --- directly without fiddling too much with the options. The only one of real --- interest should be the path for the few relevant directories. -local function get_defaults(home) +--- Default setup. Ideally anyone should be able to start using Telekasten +--- directly without fiddling too much with the options. The only one of real +--- interest should be the path for the few relevant directories. +---@param home string | nil +---@return {options: VaultConfig} +function Config:get_defaults(home) local _home = home or vim.fn.expand("~/zettelkasten") -- Default home directory local opts = { home = _home, @@ -96,21 +101,15 @@ local function get_defaults(home) return { options = opts } end ---- Merge user config with defaults -function M.apply() - local defaults = get_defaults(config.options.home) - config:merge(defaults) - return config -end - ---Keep track of a users config for use throughout the plugin as well as ---ensuring defaults are set. +---@param c VaultConfig function M.setup(c) config = Config:new(c or {}) - M.apply() end ----Get the user's configuration or a key from it +---Get the user's configuration +---@return Config | nil function M.get() if config then return config diff --git a/lua/telekasten/utils/definitions.lua b/lua/telekasten/utils/definitions.lua new file mode 100644 index 0000000..b1fffa6 --- /dev/null +++ b/lua/telekasten/utils/definitions.lua @@ -0,0 +1,86 @@ +--luacheck: ignore 211 +---@meta + +---@alias MediaExtensions +---| '".png"' +---| '".jpg"' +---| '".bmp"' +---| '".gif"' +---| '".pdf"' +---| '".mp4"' +---| '".webm"' +---| '".webp"' + +---@class VaultConfig +---@field home string +---@field take_over_my_home boolean +---@field auto_set_filetype boolean +---@field auto_set_syntax boolean +---@field dailies string +---@field weeklies string +---@field templates string +---@field image_subdir string|nil Should be deprecated gracefully and replaced by "images" +---@field extension "md" | string +---@field new_note_filename "title" | "uuid" | "uuid-title" +---@field uuid_type "%Y%m%d%H%M" | string +---@field uuid_sep "-" | string +---@field filename_space_subst string|nil +---@field follow_creates_nonexisting boolean +---@field dailies_create_nonexisting boolean +---@field weeklies_create_nonexisting boolean +---@field journal_auto_open boolean +---@field image_link_style "wiki" | "markdown" +---@field sort "filename" | "modified" +---@field subdirs_in_links boolean +---@field plug_into_calendar boolean +---@field calendar_opts CalendarOpts +---@field close_after_yanking boolean +---@field insert_after_inserting boolean +---@field tag_notation "#tag" | "@tag" | ":tag:" | "yaml-bare" +---@field command_palette_theme "dropdown" | "ivy" +---@field show_tags_theme string +---@field template_handling "smart" | "prefer_new_note" | "always_ask" +---@field new_note_location "smart" |"prefer_home" | "same_as_current" +---@field rename_update_links boolean +---@field media_previewer "telescope-media-files" | "catimg-previewer" | "viu-previewer" +---@field media_extensions MediaExtensions[] +---@field follow_url_fallback string|nil +---@field enable_create_new boolean +---@field clipboard_program string +---@field filter_extensions string[] +---@field template_new_note string|nil +---@field template_new_daily string|nil +---@field template_new_weekly string|nil +---@field find_command string[] +---@field rg_pcre boolean +--- +---For defaults, +---@see Config.get_defaults +local VaultConfig = {} + +---@alias WeekNumberFormat +---| 1 # WK01 +---| 2 # WK 1 +---| 3 # KW01 +---| 4 # KW 1 +---| 5 # 1 + +---@alias CalendarStartDay +---| 0 # weeks start on Sundays +---| 1 # weeks start on Mondays + +---@alias CalendarMarkPosition +---| 'left' # ugly +---| 'right' # right to the day +---| 'left-fit' # left of the day + +---@class CalendarOpts +---@field weeknm WeekNumberFormat +---@field calendar_monday CalendarStartDay +---@field calendar_mark CalendarMarkPosition +local CalendarOpts = {} + +---@class MultiVaultConfig +---@field vaults table +---@field default_vault? string +local MultiVaultConfig = {}