lualine.nvim/lua/lualine/components/special/vim_var_component.lua
Daemon b61afc44e6
docs: cleanup formatting and comment typos (#696)
* docs: fix typo in component notice

* refactor: rename typo param 'pattern'

* docs: fix comments typos across project files

Cleanup misspellings and wording in comment lines.

* docs: improve readability of `CONTRIBUTING.md`

* docs: improve readability of `README.md`

- Minor typos
- Clarify information
- Separate sections from paragraphs

* docs: add newline below headers in `THEMES.md`

Aim's to be consistent with other documents.

* docs: fix unname tabpage command reference

* docs: reword 'directly bused' for `setup_theme()`

* docs: fix extra indent in contribution list

* docs: more separation in readme/tabs, remove extra backtick

* docs: further improve wording for `setup_theme`

* docs: improve wording for `setup` function

* docs: missing underscore in lualine/config
2022-05-30 20:25:05 +06:00

36 lines
1.0 KiB
Lua

-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local M = require('lualine.component'):extend()
function M:update_status()
local component = self.options[1]
-- vim variable component
-- accepts g:, v:, t:, w:, b:, o, go:, vo:, to:, wo:, bo:
-- filters g portion from g:var
local scope = component:match('[gvtwb]?o?')
-- filters var portion from g:var
local var_name = component:sub(#scope + 2, #component)
-- Displays nothing when variable aren't present
if not (scope and var_name) then
return ''
end
-- Support accessing keys within dictionary
-- https://github.com/nvim-lualine/lualine.nvim/issues/25#issuecomment-907374548
local name_chunks = vim.split(var_name, '%.')
local return_val = vim[scope][name_chunks[1]]
for i = 2, #name_chunks do
if return_val == nil then
break
end
return_val = return_val[name_chunks[i]]
end
if return_val == nil then
return ''
end
local ok
ok, return_val = pcall(tostring, return_val)
return ok and return_val or ''
end
return M