Comments (4)
@b0o thank you very much, that all works great! 🙇 Adapted in https://github.com/toupeira/dotfiles/blob/39464e381811f7c4386ea409f218167da71c5a53/vim/plugins/incline.lua.
Using nvim_win_call
to run Aerial also fixes the problem I had where unfocused windows would all show the symbol for the current window's cursor, rather than their own. This was the reason I was only showing symbols in the current window 😀 But now I've tweaked it to always show symbols, and hide the filename instead if there isn't more than one listed buffer.
I'll go ahead and close this issue!
from incline.nvim.
This should be possible with the existing render function. If you could share your current configuration, I can try to assist with this.
from incline.nvim.
Thanks! Here's my current setup: https://github.com/toupeira/dotfiles/blob/main/vim/plugins/incline.lua
And a screenshot for reference:
I settled on filename + symbol breadcrumbs for now, and I'll probably keep the diagnostics in the statusline to avoid making the incline too distracting.
The filename is only shown if there's more than one window, and the symbols are only shown for the current buffer. So with only 2 sections it's not really a problem, I just conditionally include the separator before the symbols by repeating the check for number of windows:
return (props.windows > 1 and separator or '') .. symbols
It only becomes tricky if I wanted to add another section, and have to check in each section whether other sections are shown.
BTW I'm also abusing Aerial's Lualine component to generate the content for the symbols, was surprised that this worked! 😀
from incline.nvim.
Here's what I would do. I changed some of the following code:
local function get_filename(props)
if props.windows <= 1 then
return nil
end
local path = vim.api.nvim_buf_get_name(props.buf)
local filename = vim.fn.fnamemodify(path, ':t')
if filename == '' then
filename = '[No Name]'
end
return {
' ' .. filename,
gui = 'bold',
guifg = props.focused and 'white' or comment,
}
end
local aerial
local function get_symbols(props)
if not props.focused then
return nil
end
if not aerial then
aerial = require 'lualine.components.aerial' {
self = { section = 'x' },
icons_enabled = true,
sep = separator,
}
end
local symbols = vim.api.nvim_eval_statusline(aerial:get_status(), { winid = props.win }).str
if symbols == '' then
return nil
end
return symbols
end
opts.render = function(props)
props.windows = get_window_count()
local sections = {
get_filename(props),
get_symbols(props),
}
local result = {}
for _, section in pairs(sections) do
if section and section ~= '' then
if #result > 0 then
table.insert(result, separator)
end
table.insert(result, section)
end
end
return result
end
Now, you can add additional sections to the sections
table in opts.render()
. Then, the loop that builds the result
table will insert separators between sections, skipping empty ones. With this approach, you can still set highlight groups.
P.s seeing your use of vim.api.nvim_eval_statusline
gave me an idea: I created a helper function in incline.helpers
that will evaluate a statusline string and convert it to an incline render result, including support for highlights (see 49cd56c). Here's a version of your get_symbols()
function that uses it:
local helpers = require 'incline.helpers'
local aerial
local function get_symbols(props)
if not props.focused then
return nil
end
if not aerial then
aerial = require 'lualine.components.aerial' {
self = { section = 'x' },
icons_enabled = true,
sep = separator,
sep_highlight = 'InclineNormal',
}
end
local aerial_statusline = vim.api.nvim_win_call(props.win, function()
return aerial:get_status { winid = props.win }
end)
return helpers.eval_statusline(aerial_statusline, { winid = props.win })
end
It looks like this, now supporting highlights:
You could also set a highlight group common to all of the separators if you want:
--- unchanged code omitted ---
local sep = { ' ', group = 'NonText' }
local helpers = require 'incline.helpers'
local aerial
local function get_symbols(props)
if not props.focused then
return nil
end
if not aerial then
aerial = require 'lualine.components.aerial' {
self = { section = 'x' },
icons_enabled = true,
sep = sep[1],
sep_highlight = sep.group,
}
end
local aerial_statusline = vim.api.nvim_win_call(props.win, function()
return aerial:get_status { winid = props.win }
end)
return helpers.eval_statusline(aerial_statusline, { winid = props.win })
end
require('incline').setup {
render = function(props)
props.windows = get_window_count()
local sections = {
get_filename(props),
get_symbols(props),
}
local result = {}
for _, section in pairs(sections) do
if section and section ~= '' and not (type(section) == 'table' and #section == 0) then
if #result > 0 then
table.insert(result, sep)
end
table.insert(result, section)
end
end
return result
end,
window = {
margin = { horizontal = 0, vertical = 0 },
},
}
Which looks like this:
Putting it all together:
return {
'b0o/incline.nvim',
event = 'VeryLazy',
opts = {
window = {
margin = { horizontal = 0, vertical = 0 },
},
},
config = function(_, opts)
local helpers = require 'incline.helpers'
local sep = { ' ', group = 'NonText' }
local comment = require('util').get_color 'Comment'
local function get_window_count()
local windows = vim.api.nvim_tabpage_list_wins(0)
return #vim.tbl_filter(function(win)
return vim.api.nvim_win_get_config(win).relative == ''
end, windows)
end
local function get_filename(props)
local path = vim.api.nvim_buf_get_name(props.buf)
local filename = vim.fn.fnamemodify(path, ':t')
if filename == '' then
filename = '[No Name]'
end
return {
' ' .. filename,
gui = 'bold',
guifg = props.focused and 'white' or comment,
}
end
local aerial
local function get_symbols(props)
if not props.focused then
return nil
end
if not aerial then
aerial = require 'lualine.components.aerial' {
self = { section = 'x' },
icons_enabled = true,
sep = sep[1],
sep_highlight = sep.group,
}
end
local aerial_statusline = vim.api.nvim_win_call(props.win, function()
return aerial:get_status { winid = props.win }
end)
return helpers.eval_statusline(aerial_statusline, { winid = props.win })
end
opts.render = function(props)
local window_count = get_window_count()
local sections = {
window_count > 1 and get_filename(props) or nil,
get_symbols(props),
}
local result = {}
for _, section in pairs(sections) do
if section and section ~= '' and not (type(section) == 'table' and #section == 0) then
if #result > 0 then
table.insert(result, sep)
end
table.insert(result, section)
end
end
return result
end
require('incline').setup(opts)
end,
}
Hopefully this gives you some ideas around what's possible.
from incline.nvim.
Related Issues (20)
- Refresh on FocusLost & FocusGained
- Rotating windows with `CTRL-W_R` doesn't trigger update
- Change indicator support? HOT 2
- Add Option `hide > inactive_window` HOT 11
- Powerline symbols on ends HOT 2
- Incompatible with zen-mode.nvim HOT 4
- Supress overlaping if statement HOT 3
- How to Add rounded Edges ? HOT 1
- Bug: Incline disable doesn't consistently work with tabs HOT 2
- How to trigger a rerender? HOT 2
- feature request: multiple instances of incline.nvim HOT 1
- Unresponsiveness on events HOT 3
- Make updating event configurable HOT 1
- No module called incline.helpers HOT 6
- Hide label if cursor is directly within the label area HOT 2
- Scrolling performance impact when incline is enabled HOT 6
- Compatibility with competitest.nvim
- Winbar isn't displayed after the session loading (persistance.nvim)
- Is there any way to have winblend with ``incline.nvim``? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from incline.nvim.