-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Refactor: Move dashboard plugin to core
- Loading branch information
1 parent
19e0be5
commit a4dbcbf
Showing
10 changed files
with
239 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
-- Credit https://github.com/glepnir/dashboard-nvim/blob/master/lua/dashboard/init.lua | ||
local api = vim.api | ||
|
||
local autogroup = api.nvim_create_augroup("Dashboard", {}) | ||
|
||
api.nvim_create_autocmd("Vimenter", { | ||
group = autogroup, | ||
pattern = "*", | ||
nested = true, | ||
callback = function() | ||
if vim.fn.argc() == 0 and vim.api.nvim_buf_get_name(0) == "" then | ||
require("dashboard").instance() | ||
end | ||
end, | ||
}) | ||
|
||
api.nvim_create_autocmd({ "BufLeave" }, { | ||
group = autogroup, | ||
pattern = "*", | ||
callback = function() | ||
local pos = api.nvim_win_get_cursor(0) | ||
api.nvim_win_set_var(0, "dashboard_prev_pos", pos) | ||
end, | ||
}) | ||
|
||
api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, { | ||
group = autogroup, | ||
pattern = "*", | ||
callback = function() | ||
if vim.bo.filetype == "dashboard" then | ||
return | ||
end | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local augroup = vim.api.nvim_exec | ||
local cmd = vim.api.nvim_command | ||
local utils = require("utils.core") | ||
|
||
-- Auto format | ||
utils.autocommand_by_filetypes( | ||
require("settings").autoformat.filetypes, | ||
"BufWritePre", | ||
[[lua require('format').format()]] | ||
) | ||
|
||
-- Code action | ||
utils.autocommand_by_filetypes( | ||
require("settings").codeaction.filetypes, | ||
"CursorHold,CursorHoldI", | ||
[[lua require('utils.lightbulb').code_action()]] | ||
) | ||
|
||
-- Toggle comment | ||
cmd("command! -range CommentToggle lua require('utils.comment').comment_toggle(<line1>, <line2>)") | ||
|
||
augroup( | ||
[[ | ||
augroup Config | ||
autocmd! | ||
autocmd InsertEnter * set nocursorline | ||
autocmd InsertLeave * set cursorline | ||
autocmd! BufEnter * if &ft ==# 'help' | wincmd L | endif | ||
autocmd bufenter * if (winnr("$") == 2 && &filetype == "Yanil") | q | endif | ||
autocmd BufNewFile,BufRead *.sol set filetype=solidity | ||
augroup END | ||
]], | ||
true | ||
) | ||
|
||
augroup( | ||
[[ | ||
augroup Highlight | ||
autocmd! | ||
autocmd FileType dapui* setlocal winhighlight=Normal:DapUINormal | ||
autocmd FileType aerial setlocal winhighlight=Normal:AerialNormal | ||
autocmd FileType DiffviewFiles setlocal winhighlight=Normal:DiffviewFilesNormal | ||
augroup END | ||
]], | ||
true | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
local api = vim.api | ||
local autogroup = api.nvim_create_augroup("StatusLine", {}) | ||
|
||
api.nvim_create_autocmd({ "Bufenter", "BufWritePost" }, { | ||
group = autogroup, | ||
pattern = "*", | ||
callback = function() | ||
require("statusline").load() | ||
end, | ||
}) | ||
|
||
api.nvim_create_autocmd("FileType", { | ||
group = autogroup, | ||
pattern = "dapui*,dap-repl,aerial,sqls_output", | ||
callback = function() | ||
require("statusline").load() | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
local api = vim.api | ||
local autogroup = api.nvim_create_augroup("Winbar", {}) | ||
|
||
api.nvim_create_autocmd({ "Bufenter", "BufWritePost" }, { | ||
group = autogroup, | ||
pattern = "*", | ||
callback = function() | ||
require("winbar").load() | ||
end, | ||
}) | ||
|
||
api.nvim_create_autocmd("FileType", { | ||
group = autogroup, | ||
pattern = "dapui*,dap-repl,aerial,sqls_output", | ||
callback = function() | ||
require("statusline").load() | ||
end, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
-- Credit https://github.com/glepnir/dashboard-nvim/blob/master/lua/dashboard/init.lua | ||
local api, fn = vim.api, vim.fn | ||
local opt_local = vim.opt_local | ||
local M = {} | ||
|
||
local dashboard_loaded = false | ||
|
||
local default_banner = { | ||
"⠀⠀⠀⠀⠀⠀⠀⢀⣴⣷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣦⡀⠀⠀⠀⠀⠀⠀⠀", | ||
"⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣦⡀⠀⠀⠀⠀⠀", | ||
"⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣦⡀⠀⠀⠀", | ||
"⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣦⡀⠀", | ||
"⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣦", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⡀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠙⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", | ||
"⠻⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟", | ||
"⠀⠈⠻⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀", | ||
"⠀⠀⠀⠈⠻⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⠀", | ||
"⠀⠀⠀⠀⠀⠈⠻⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀", | ||
"⠀⠀⠀⠀⠀⠀⠀⠈⠻⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⠟⠁⠀⠀⠀⠀⠀⠀⠀", | ||
} | ||
|
||
local set_line_with_highlight = function(bufnr, tbl) | ||
api.nvim_buf_set_lines(bufnr, 1, #tbl, false, tbl) | ||
|
||
local dashboard_namespace = api.nvim_create_namespace("Dashboard") | ||
for i = 1, #tbl do | ||
api.nvim_buf_add_highlight(bufnr, dashboard_namespace, "DashboardHeader", i, 1, -1) | ||
end | ||
end | ||
|
||
local cache_header = {} | ||
|
||
local render_header = coroutine.create(function(bufnr) | ||
local centered_lines = {} | ||
|
||
local top = math.floor((fn.winheight(0) - #default_banner) / 2) | ||
for _ = 1, top do | ||
table.insert(centered_lines, "") | ||
end | ||
|
||
local width = math.floor((fn.winwidth(0) - fn.strwidth(default_banner[1])) / 2) | ||
local space = vim.fn["repeat"](" ", width) | ||
for i = 1, #default_banner do | ||
table.insert(centered_lines, space .. default_banner[i]) | ||
end | ||
|
||
cache_header = centered_lines | ||
set_line_with_highlight(bufnr, centered_lines) | ||
end) | ||
|
||
function M.instance() | ||
if api.nvim_get_mode().mode == "i" or not vim.bo.modifiable then | ||
return | ||
end | ||
|
||
if not vim.o.hidden and vim.bo.modfied then | ||
return | ||
end | ||
|
||
local bufnr | ||
|
||
if vim.fn.line2byte("$") ~= -1 then | ||
vim.cmd("noautocmd") | ||
bufnr = api.nvim_create_buf(false, true) | ||
else | ||
bufnr = api.nvim_get_current_buf() | ||
end | ||
|
||
local window = api.nvim_get_current_win() | ||
api.nvim_win_set_buf(window, bufnr) | ||
|
||
opt_local.wrap = false | ||
opt_local.signcolumn = "no" | ||
opt_local.buftype = "nofile" | ||
opt_local.swapfile = false | ||
opt_local.spell = false | ||
opt_local.relativenumber = false | ||
opt_local.filetype = "dashboard" | ||
opt_local.number = false | ||
opt_local.list = false | ||
opt_local.cursorline = false | ||
opt_local.cursorcolumn = false | ||
opt_local.buflisted = false | ||
opt_local.matchpairs = "" | ||
opt_local.foldcolumn = "0" | ||
opt_local.colorcolumn = "" | ||
opt_local.bufhidden = "wipe" | ||
|
||
if dashboard_loaded then | ||
set_line_with_highlight(bufnr, cache_header) | ||
else | ||
coroutine.resume(render_header, bufnr) | ||
dashboard_loaded = true | ||
end | ||
|
||
local opts = { noremap = true, silent = true, nowait = true } | ||
api.nvim_buf_set_keymap(bufnr, "n", "h", "", opts) | ||
api.nvim_buf_set_keymap(bufnr, "n", "l", "", opts) | ||
api.nvim_buf_set_keymap(bufnr, "n", "w", "", opts) | ||
api.nvim_buf_set_keymap(bufnr, "n", "b", "", opts) | ||
api.nvim_buf_set_keymap(bufnr, "n", "<BS>", "", opts) | ||
|
||
api.nvim_exec_autocmds("User DashboardReady", { | ||
modeline = false, | ||
}) | ||
end | ||
|
||
return M |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters