Skip to content

Commit

Permalink
feat(sources): path: add opts to change file symbol when modified is …
Browse files Browse the repository at this point in the history
…set (#14)
  • Loading branch information
bekaboo committed Jun 3, 2023
1 parent 85d6e39 commit 6c568de
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ https://github.com/Bekaboo/dropbar.nvim/assets/76579810/e8c1ac26-0321-4762-9975-
filter = function(_)
return true
end,
---Symbol of current buf is modified
---@param sym dropbar_symbol_t
---@return dropbar_symbol_t
modified = function(sym)
return sym
end
},
treesitter = {
-- Lua pattern used to extract a short name from the node text
Expand Down Expand Up @@ -779,6 +785,32 @@ each sources.
return true
end
```
- `opts.sources.path.modified`: `function(sym: dropbar_symbol_t): dropbar_symbol_t`
- A function that takes the last
symbol<sub>[`dropbar_symbol_t`](#dropbar_symbol_t)</sub> in the result got
from the path source and returns an alternative
symbol<sub>[`dropbar_symbol_t`](#dropbar_symbol_t)</sub> to show if the
current buffer is modified
- Default:
```lua
function(sym)
return sym
end
```
- To set a different icon, name, or highlights when the buffer is modified,
you can change the corresponding fields in the returned
symbol<sub>[`dropbar_symbol_t`](#dropbar_symbol_t)</sub>
```lua
function(sym)
return sym:merge({
name = sym.name .. '[+]',
icon = '',
name_hl = 'DiffAdded',
icon_hl = 'DiffAdded',
-- ...
})
end
```

##### Treesitter

Expand Down
23 changes: 23 additions & 0 deletions doc/dropbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,29 @@ PATH *dropbar-configuration-options-sources-path*
return true
end
<
- `opts.sources.path.modified`: `function(sym: dropbar_symbol_t): dropbar_symbol_t`
- A function that takes the last symbol in the result got from the path
source and returns an alternative symbol to show if the current buffer is
modified, for information about dropbar symbols see
|dropbar-developers-classes-dropbar_symbol_t|
- Default: >lua

function(sym)
return sym
end
<
- To set a different icon, name, or highlights when the buffer is modified,
you can change the corresponding fields in the returned symbol: >lua

function(sym)
return sym:merge({
name = sym.name .. ' [+]',
icon = ' ',
name_hl = 'DiffAdded',
icon_hl = 'DiffAdded',
-- ...
})
end

TREESITTER *dropbar-configuration-options-sources-treesitter*

Expand Down
6 changes: 6 additions & 0 deletions lua/dropbar/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ M.opts = {
filter = function(_)
return true
end,
---Symbol of current buf is modified
---@param sym dropbar_symbol_t
---@return dropbar_symbol_t
modified = function(sym)
return sym
end,
},
treesitter = {
-- Lua pattern used to extract a short name from the node text
Expand Down
3 changes: 3 additions & 0 deletions lua/dropbar/sources/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ local function get_symbols(buf, _)
table.insert(symbols, 1, convert(current_path))
current_path = vim.fs.dirname(current_path)
end
if vim.bo[buf].mod then
symbols[#symbols] = configs.opts.sources.path.modified(symbols[#symbols])
end
return symbols
end

Expand Down

0 comments on commit 6c568de

Please sign in to comment.