Skip to content

Commit

Permalink
add backlinks config opts
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Aug 14, 2023
1 parent 8f1c896 commit 7f9b9db
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added option `prepend_note_id` to allow disabling id generation for new notes.
- Added `mappings` configuration field.
- Added `open_notes_in` configuration field
- Added `backlinks` options to the config. The default is
```lua
backlinks = {
-- The default height of the backlinks pane.
height = 10,
-- Whether or not to wrap lines.
wrap = true,
},
```

### Changed

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ This is a complete list of all of the options that can be passed to `require("ob
time_format = "%H:%M",
},

-- Optional, customize the backlinks interface.
backlinks = {
-- The default height of the backlinks pane.
height = 10,
-- Whether or not to wrap lines.
wrap = true,
},

-- Optional, by default when you use `:ObsidianFollowLink` on a link to an external
-- URL it will be ignored but you can customize this behavior here.
follow_url_func = function(url)
Expand Down
4 changes: 2 additions & 2 deletions lua/obsidian/backlinks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ backlinks.view = function(self)
-- Clear any existing backlinks buffer.
wipe_rogue_buffer()

vim.api.nvim_command "botright 10split ObsidianBacklinks"
vim.api.nvim_command("botright " .. tostring(self.client.opts.backlinks.height) .. "split ObsidianBacklinks")

-- Configure buffer.
vim.cmd "setlocal nonu"
Expand All @@ -137,7 +137,7 @@ backlinks.view = function(self)
vim.api.nvim_buf_set_option(0, "buflisted", false)
vim.api.nvim_buf_set_var(0, "obsidian_vault_dir", tostring(self.client.dir))
vim.api.nvim_buf_set_var(0, "obsidian_parent_win", self.winnr)
vim.api.nvim_win_set_option(0, "wrap", false)
vim.api.nvim_win_set_option(0, "wrap", self.client.opts.backlinks.wrap)
vim.api.nvim_win_set_option(0, "spell", false)
vim.api.nvim_win_set_option(0, "list", false)
vim.api.nvim_win_set_option(0, "signcolumn", "no")
Expand Down
17 changes: 17 additions & 0 deletions lua/obsidian/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local config = {}
---@field follow_url_func function|?
---@field note_frontmatter_func function|?
---@field disable_frontmatter boolean|?
---@field backlinks obsidian.config.BacklinksOpts
---@field completion obsidian.config.CompletionOpts
---@field mappings obsidian.config.MappingOpts
---@field daily_notes obsidian.config.DailyNotesOpts
Expand All @@ -35,6 +36,7 @@ config.ClientOpts.default = function()
follow_url_func = nil,
note_frontmatter_func = nil,
disable_frontmatter = false,
backlinks = config.BacklinksOpts.default(),
completion = config.CompletionOpts.default(),
mappings = config.MappingOpts.default(),
daily_notes = config.DailyNotesOpts.default(),
Expand All @@ -51,13 +53,28 @@ end
---@return obsidian.config.ClientOpts
config.ClientOpts.normalize = function(opts)
opts = vim.tbl_extend("force", config.ClientOpts.default(), opts)
opts.backlinks = vim.tbl_extend("force", config.BacklinksOpts.default(), opts.backlinks)
opts.completion = vim.tbl_extend("force", config.CompletionOpts.default(), opts.completion)
opts.mappings = opts.mappings and opts.mappings or config.MappingOpts.default()
opts.daily_notes = vim.tbl_extend("force", config.DailyNotesOpts.default(), opts.daily_notes)
opts.dir = vim.fs.normalize(tostring(opts.dir))
return opts
end

---@class obsidian.config.BacklinksOpts
---@field height integer
---@field wrap boolean
config.BacklinksOpts = {}

---Get defaults.
---@return obsidian.config.BacklinksOpts
config.BacklinksOpts.default = function()
return {
height = 10,
wrap = true,
}
end

---@class obsidian.config.CompletionOpts
---@field nvim_cmp boolean
---@field min_chars integer
Expand Down

0 comments on commit 7f9b9db

Please sign in to comment.