Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow layout sections to be functions #105

Open
bennypowers opened this issue Apr 24, 2022 · 1 comment
Open

Allow layout sections to be functions #105

bennypowers opened this issue Apr 24, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@bennypowers
Copy link
Contributor

Alternative / additional to #34

With the current API, layouts are computed up-front in the setup function, whether or not the user is actually requesting a render. For example, via something like #104, a user would disable autostart until their conditions are met (e.g. "when there is no existing session, or when all windows are closed")

In that case, if the user's alpha setup function is expensive, it will still affect nvim startup time, as the layouts will all be computed up-front. To solve this, layout sections should be allowed to be functions:

local function header()
  -- do some expensive / slow stuff here
end

-- relatively cheap to compute
local buttons = {
  type = "group",
  val = {
    { type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } },
    { type = "padding", val = 1 },
    dashboard.button("spc /",  "  File Explorer",   ":NeoTreeFloatToggle<CR>"),
    dashboard.button("spc p",  "  Find file",       ":Telescope find_files <CR>"),
    dashboard.button("spc fg", "  Find text",       ":Telescope live_grep <CR>"),
    dashboard.button("n",      "  New file",        ":ene <BAR> startinsert <CR>"),
    dashboard.button("c",      "  Configuration",   ":e ~/.config/nvim/init.lua <CR>"),
    dashboard.button("u",      "  Update plugins" , ":PackerSync<CR>"),
    dashboard.button("G",      "  Git",             "gG"),
    dashboard.button("q",      "  Quit" ,           ":qa<CR>"),
  },
  position = "center",
}

alpha.setup {
    layout = {
        { type = "padding", val = 2 },
        header,
        { type = "padding", val = 2 },
        section_mru,
        { type = "padding", val = 2 },
        buttons,
    },
    opts = {
        margin = 5,
        autostart = false,
    },
}
@goolord
Copy link
Owner

goolord commented Feb 11, 2023

most layout types alreadyaccept a function in val which gets resolved on each draw (you can just mutate a variable in your config and check it in the function or something)

@goolord goolord added the enhancement New feature or request label Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants