Skip to content

Commit

Permalink
Merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyWu20 committed Jan 2, 2025
2 parents 32ccf8a + 22b8452 commit 21c076a
Show file tree
Hide file tree
Showing 20 changed files with 324 additions and 275 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
- uses: actions/checkout@v4
- uses: lunarmodules/luacheck@v1
with:
args: . --std luajit --globals vim _debugging _command_panel _flash_esc_or_noh _telescope_collections _toggle_lazygit --max-line-length 150 --no-config
args: . --std luajit --globals vim _debugging _command_panel _flash_esc_or_noh _telescope_collections _toggle_lazygit _toggle_diagnostic _toggle_inlayhint _async_compile_and_debug --max-line-length 150 --no-config
32 changes: 16 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 68 additions & 68 deletions lazy-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ local leader_map = function()
end

local gui_config = function()
vim.api.nvim_set_option_value("guifont", settings.gui_config.font_name .. ":h" .. settings.gui_config.font_size, {})
if next(settings.gui_config) then
vim.api.nvim_set_option_value(
"guifont",
settings.gui_config.font_name .. ":h" .. settings.gui_config.font_size,
{}
)
end
end

local neovide_config = function()
Expand Down Expand Up @@ -105,7 +111,6 @@ local load_core = function()
shell_config()

require("core.options")
require("core.mapping")
require("core.event")
require("core.pack")
require("keymap")
Expand Down
65 changes: 0 additions & 65 deletions lua/core/mapping.lua

This file was deleted.

13 changes: 13 additions & 0 deletions lua/keymap/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local map_callback = bind.map_callback

local plug_map = {
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("formatter: Toggle format on save"),
["n|<A-S-f>"] = map_cmd("<Cmd>Format<CR>"):with_noremap():with_desc("formatter: Format buffer manually"),
}
bind.nvim_load_mapping(plug_map)

Expand Down Expand Up @@ -62,6 +63,18 @@ function mapping.lsp(buf)
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show outgoing calls"),
["n|<leader>td"] = map_callback(function()
_toggle_diagnostic()
end)
:with_noremap()
:with_silent()
:with_desc("edit: Toggle virtual text display of current buffer"),
["n|<leader>th"] = map_callback(function()
_toggle_inlayhint()
end)
:with_noremap()
:with_silent()
:with_desc("edit: Toggle inlay hints dispaly of current buffer"),
}
bind.nvim_load_mapping(map)

Expand Down
69 changes: 50 additions & 19 deletions lua/keymap/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,60 @@ local map_cmd = bind.map_cmd
local map_callback = bind.map_callback
local et = bind.escape_termcode

local builtin_map = {
-- Builtin: save & quit
["n|<C-s>"] = map_cu("write"):with_noremap():with_silent():with_desc("edit: Save file"),
["n|<C-q>"] = map_cr("wq"):with_desc("edit: Save file and quit"),
["n|<A-S-q>"] = map_cr("q!"):with_desc("edit: Force quit"),

-- Builtin: insert mode
["i|<C-u>"] = map_cmd("<C-G>u<C-U>"):with_noremap():with_desc("edit: Delete previous block"),
["i|<C-b>"] = map_cmd("<Left>"):with_noremap():with_desc("edit: Move cursor to left"),
["i|<C-a>"] = map_cmd("<ESC>^i"):with_noremap():with_desc("edit: Move cursor to line start"),
["i|<C-s>"] = map_cmd("<Esc>:w<CR>"):with_desc("edit: Save file"),
["i|<C-q>"] = map_cmd("<Esc>:wq<CR>"):with_desc("edit: Save file and quit"),

-- Builtin: command mode
["c|<C-b>"] = map_cmd("<Left>"):with_noremap():with_desc("edit: Left"),
["c|<C-f>"] = map_cmd("<Right>"):with_noremap():with_desc("edit: Right"),
["c|<C-a>"] = map_cmd("<Home>"):with_noremap():with_desc("edit: Home"),
["c|<C-e>"] = map_cmd("<End>"):with_noremap():with_desc("edit: End"),
["c|<C-d>"] = map_cmd("<Del>"):with_noremap():with_desc("edit: Delete"),
["c|<C-h>"] = map_cmd("<BS>"):with_noremap():with_desc("edit: Backspace"),
["c|<C-t>"] = map_cmd([[<C-R>=expand("%:p:h") . "/" <CR>]])
:with_noremap()
:with_desc("edit: Complete path of current file"),

-- Builtin: visual mode
["v|J"] = map_cmd(":m '>+1<CR>gv=gv"):with_desc("edit: Move this line down"),
["v|K"] = map_cmd(":m '<-2<CR>gv=gv"):with_desc("edit: Move this line up"),
["v|<"] = map_cmd("<gv"):with_desc("edit: Decrease indent"),
["v|>"] = map_cmd(">gv"):with_desc("edit: Increase indent"),

-- Builtin: suckless
["n|Y"] = map_cmd("y$"):with_desc("edit: Yank text to EOL"),
["n|D"] = map_cmd("d$"):with_desc("edit: Delete text to EOL"),
["n|n"] = map_cmd("nzzzv"):with_noremap():with_desc("edit: Next search result"),
["n|N"] = map_cmd("Nzzzv"):with_noremap():with_desc("edit: Prev search result"),
["n|J"] = map_cmd("mzJ`z"):with_noremap():with_desc("edit: Join next line"),
["n|<S-Tab>"] = map_cr("normal za"):with_noremap():with_silent():with_desc("edit: Toggle code fold"),
["n|<Esc>"] = map_callback(function()
_flash_esc_or_noh()
end)
:with_noremap()
:with_silent()
:with_desc("edit: Clear search highlight"),
["n|<leader>o"] = map_cr("setlocal spell! spelllang=en_us"):with_desc("edit: Toggle spell check"),
}

bind.nvim_load_mapping(builtin_map)

local plug_map = {
-- Plugin persisted.nvim
-- Plugin: persisted.nvim
["n|<leader>ss"] = map_cu("SessionSave"):with_noremap():with_silent():with_desc("session: Save"),
["n|<leader>sl"] = map_cu("SessionLoad"):with_noremap():with_silent():with_desc("session: Load current"),
["n|<leader>sd"] = map_cu("SessionDelete"):with_noremap():with_silent():with_desc("session: Delete"),

-- Plugin: nvim-bufdel
["n|<A-q>"] = map_cr("BufDel"):with_noremap():with_silent():with_desc("buffer: Close current"),

-- Plugin: comment.nvim
["n|gcc"] = map_callback(function()
return vim.v.count == 0 and et("<Plug>(comment_toggle_linewise_current)")
Expand Down Expand Up @@ -59,20 +104,6 @@ local plug_map = {
["nv|<leader>c"] = map_cmd("<Cmd>HopChar1MW<CR>"):with_noremap():with_desc("jump: Goto one char"),
["nv|<leader>C"] = map_cmd("<Cmd>HopChar2MW<CR>"):with_noremap():with_desc("jump: Goto two chars"),

-- Plugin: smart-splits.nvim
["n|<A-h>"] = map_cu("SmartResizeLeft"):with_silent():with_noremap():with_desc("window: Resize -3 horizontally"),
["n|<A-j>"] = map_cu("SmartResizeDown"):with_silent():with_noremap():with_desc("window: Resize -3 vertically"),
["n|<A-k>"] = map_cu("SmartResizeUp"):with_silent():with_noremap():with_desc("window: Resize +3 vertically"),
["n|<A-l>"] = map_cu("SmartResizeRight"):with_silent():with_noremap():with_desc("window: Resize +3 horizontally"),
["n|<C-h>"] = map_cu("SmartCursorMoveLeft"):with_silent():with_noremap():with_desc("window: Focus left"),
["n|<C-j>"] = map_cu("SmartCursorMoveDown"):with_silent():with_noremap():with_desc("window: Focus down"),
["n|<C-k>"] = map_cu("SmartCursorMoveUp"):with_silent():with_noremap():with_desc("window: Focus up"),
["n|<C-l>"] = map_cu("SmartCursorMoveRight"):with_silent():with_noremap():with_desc("window: Focus right"),
["n|<leader>Wh"] = map_cu("SmartSwapLeft"):with_silent():with_noremap():with_desc("window: Move window leftward"),
["n|<leader>Wj"] = map_cu("SmartSwapDown"):with_silent():with_noremap():with_desc("window: Move window downward"),
["n|<leader>Wk"] = map_cu("SmartSwapUp"):with_silent():with_noremap():with_desc("window: Move window upward"),
["n|<leader>Wl"] = map_cu("SmartSwapRight"):with_silent():with_noremap():with_desc("window: Move window rightward"),

-- Plugin: nvim-spectre
["n|<leader>Ss"] = map_callback(function()
require("spectre").toggle()
Expand Down Expand Up @@ -102,7 +133,7 @@ local plug_map = {
-- Plugin: nvim-treehopper
["o|m"] = map_cu("lua require('tsht').nodes()"):with_silent():with_desc("jump: Operate across syntax tree"),

-- Plugin suda.vim
-- Plugin: suda.vim
["n|<A-s>"] = map_cu("SudaWrite"):with_silent():with_noremap():with_desc("editn: Save file using sudo"),
}

Expand Down
62 changes: 62 additions & 0 deletions lua/keymap/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,65 @@ _G._toggle_lazygit = function()
vim.notify("Command [lazygit] not found!", vim.log.levels.ERROR, { title = "toggleterm.nvim" })
end
end

_G._toggle_inlayhint = function()
if vim.lsp.inlay_hint.is_enabled() then
vim.lsp.inlay_hint.enable(false)
vim.notify("Disable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
else
vim.lsp.inlay_hint.enable(true)
vim.notify("Enable inlay hint successfully!", vim.log.levels.INFO, { title = "LSP Inlay Hint" })
end
end

local _diagnostic = 1
_G._toggle_diagnostic = function()
if vim.diagnostic.is_enabled() then
if _diagnostic == 1 then
_diagnostic = 0
vim.diagnostic.hide()
vim.notify("Hide virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
else
_diagnostic = 1
vim.diagnostic.show()
vim.notify("Show virtual text successfully!", vim.log.levels.INFO, { title = "LSP Diagnostic" })
end
end
end

_G._async_compile_and_debug = function()
local file_ext = vim.fn.expand("%:e")
local file_path = vim.fn.expand("%:p")
local out_name = vim.fn.expand("%:p:h") .. "/" .. vim.fn.expand("%:t:r") .. ".out"
local compile_cmd
if file_ext == "cpp" or file_ext == "cc" then
compile_cmd = string.format("g++ -g %s -o %s", file_path, out_name)
elseif file_ext == "c" then
compile_cmd = string.format("gcc -g %s -o %s", file_path, out_name)
elseif file_ext == "go" then
compile_cmd = string.format("go build -o %s %s", out_name, file_path)
else
require("dap").continue()
return
end
local notify_title = "Debug Pre-compile"
vim.fn.jobstart(compile_cmd, {
on_exit = function(_, exit_code, _)
if exit_code == 0 then
vim.notify(
"Compilation succeeded! Executable: " .. out_name,
vim.log.levels.INFO,
{ title = notify_title }
)
require("dap").continue()
return
else
vim.notify(
"Compilation failed with exit code: " .. exit_code,
vim.log.levels.ERROR,
{ title = notify_title }
)
end
end,
})
end
2 changes: 1 addition & 1 deletion lua/keymap/tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ local plug_map = {

-- Plugin: dap
["n|<F6>"] = map_callback(function()
require("dap").continue()
_async_compile_and_debug()
end)
:with_noremap()
:with_silent()
Expand Down
Loading

0 comments on commit 21c076a

Please sign in to comment.