feat(nvim): create custom harpoon commands
This commit is contained in:
153
nvim/.config/nvim/lua/plugins/harpoon.lua
Normal file
153
nvim/.config/nvim/lua/plugins/harpoon.lua
Normal file
@@ -0,0 +1,153 @@
|
||||
-- plugins/h-- plugins/harpoon.lua
|
||||
return {
|
||||
"ThePrimeagen/harpoon",
|
||||
branch = "harpoon2",
|
||||
dependencies = { "nvim-lua/plenary.nvim" },
|
||||
config = function()
|
||||
local harpoon = require("harpoon")
|
||||
|
||||
-- Setup Harpoon pour sessions temporaires (pas de persistence)
|
||||
harpoon:setup({
|
||||
settings = {
|
||||
save_on_toggle = false, -- Pas de sauvegarde automatique
|
||||
sync_on_ui_close = false, -- Pas de sync à la fermeture
|
||||
save_on_change = true, -- Sauvegarde les changements dans la session
|
||||
excluded_filetypes = { "harpoon", "alpha", "dashboard", "gitcommit", "fugitive" },
|
||||
},
|
||||
})
|
||||
|
||||
-- === Fonction helper pour arrêter VimTeX ===
|
||||
local function stop_all_vimtex()
|
||||
-- Récupérer tous les buffers LaTeX ouverts
|
||||
local latex_buffers = {}
|
||||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||
if vim.api.nvim_buf_is_loaded(buf) then
|
||||
local filetype = vim.api.nvim_buf_get_option(buf, "filetype")
|
||||
if filetype == "tex" or filetype == "latex" then
|
||||
table.insert(latex_buffers, buf)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Arrêter VimTeX pour chaque buffer LaTeX
|
||||
for _, buf in ipairs(latex_buffers) do
|
||||
-- Switcher temporairement vers ce buffer pour exécuter VimtexStop
|
||||
local current_buf = vim.api.nvim_get_current_buf()
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
|
||||
if vim.fn.exists(":VimtexStop") == 2 then
|
||||
pcall(vim.cmd, "VimtexStop") -- pcall pour éviter les erreurs
|
||||
end
|
||||
|
||||
-- Revenir au buffer original
|
||||
if vim.api.nvim_buf_is_valid(current_buf) then
|
||||
vim.api.nvim_set_current_buf(current_buf)
|
||||
end
|
||||
end
|
||||
|
||||
-- Alternative plus robuste: tuer directement les processus latexmk
|
||||
local handle = io.popen("pgrep -f latexmk")
|
||||
if handle then
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
if result and result ~= "" then
|
||||
os.execute("pkill -f latexmk")
|
||||
print("Killed background latexmk processes")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Keymaps AZERTY-friendly groupés sous <leader>h
|
||||
local keymap = vim.keymap.set
|
||||
|
||||
-- === Gestion de session ===
|
||||
keymap("n", "<leader>ha", function()
|
||||
harpoon:list():append()
|
||||
print("Added: " .. vim.fn.expand("%:t"))
|
||||
end, { desc = "Harpoon: Add file to session" })
|
||||
|
||||
keymap("n", "<leader>hm", function()
|
||||
harpoon.ui:toggle_quick_menu(harpoon:list())
|
||||
end, { desc = "Harpoon: Toggle menu" })
|
||||
|
||||
keymap("n", "<leader>hc", function()
|
||||
-- Confirmation simple
|
||||
local choice = vim.fn.confirm("Clear session and stop VimTeX?", "&Yes\n&No", 2)
|
||||
|
||||
-- Si No, on fait rien
|
||||
if choice ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
-- Arrêter toutes les compilations VimTeX
|
||||
stop_all_vimtex()
|
||||
|
||||
-- Clear Harpoon
|
||||
harpoon:list():clear()
|
||||
|
||||
-- Fermer tous les buffers
|
||||
vim.cmd("silent! %bdelete")
|
||||
|
||||
print("Session cleared, VimTeX stopped, buffers closed!")
|
||||
end, { desc = "Harpoon: Clear session & stop VimTeX" })
|
||||
|
||||
-- === Navigation directe (rangée de base AZERTY) ===
|
||||
local nav_keys = {
|
||||
{ key = "q", pos = 1 },
|
||||
{ key = "s", pos = 2 },
|
||||
{ key = "d", pos = 3 },
|
||||
{ key = "f", pos = 4 },
|
||||
{ key = "g", pos = 5 },
|
||||
{ key = "h", pos = 6 },
|
||||
}
|
||||
|
||||
for _, mapping in ipairs(nav_keys) do
|
||||
keymap("n", "<leader>h" .. mapping.key, function()
|
||||
harpoon:list():select(mapping.pos)
|
||||
end, { desc = "Harpoon: Go to file " .. mapping.pos })
|
||||
end
|
||||
|
||||
-- === Navigation cyclique ===
|
||||
keymap("n", "<leader>hn", function()
|
||||
harpoon:list():next()
|
||||
end, { desc = "Harpoon: Next file" })
|
||||
|
||||
keymap("n", "<leader>hp", function()
|
||||
harpoon:list():prev()
|
||||
end, { desc = "Harpoon: Previous file" })
|
||||
|
||||
-- === Commandes utiles ===
|
||||
vim.api.nvim_create_user_command("HarpoonClear", function()
|
||||
harpoon:list():clear()
|
||||
print("Harpoon session cleared!")
|
||||
end, { desc = "Clear current Harpoon session" })
|
||||
|
||||
vim.api.nvim_create_user_command("HarpoonList", function()
|
||||
local list = harpoon:list()
|
||||
if #list.items == 0 then
|
||||
print("No files in Harpoon session")
|
||||
return
|
||||
end
|
||||
|
||||
print("Current Harpoon session:")
|
||||
for i, item in ipairs(list.items) do
|
||||
print(string.format(" %d. %s", i, item.value))
|
||||
end
|
||||
end, { desc = "List files in current Harpoon session" })
|
||||
end,
|
||||
|
||||
-- Chargement paresseux: seulement quand on utilise les keymaps
|
||||
keys = {
|
||||
{ "<leader>ha", desc = "Harpoon: Add file" },
|
||||
{ "<leader>hm", desc = "Harpoon: Menu" },
|
||||
{ "<leader>hc", desc = "Harpoon: Clear & stop VimTeX" },
|
||||
{ "<leader>hq", desc = "Harpoon: File 1" },
|
||||
{ "<leader>hs", desc = "Harpoon: File 2" },
|
||||
{ "<leader>hd", desc = "Harpoon: File 3" },
|
||||
{ "<leader>hf", desc = "Harpoon: File 4" },
|
||||
{ "<leader>hg", desc = "Harpoon: File 5" },
|
||||
{ "<leader>hh", desc = "Harpoon: File 6" },
|
||||
{ "<leader>hn", desc = "Harpoon: Next" },
|
||||
{ "<leader>hp", desc = "Harpoon: Previous" },
|
||||
},
|
||||
}
|
||||
15
nvim/.config/nvim/snippets/package.json
Normal file
15
nvim/.config/nvim/snippets/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "custom-latex-snippets",
|
||||
"contributes": {
|
||||
"snippets": [
|
||||
{
|
||||
"language": "tex",
|
||||
"path": "./snippets/latex.json"
|
||||
},
|
||||
{
|
||||
"language": "latex",
|
||||
"path": "./snippets/latex.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
29
nvim/.config/nvim/snippets/snippets/latex.json
Normal file
29
nvim/.config/nvim/snippets/snippets/latex.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"Begin/End environment": {
|
||||
"prefix": "beg",
|
||||
"body": [
|
||||
"\\begin{${1:environment}}",
|
||||
"\t$0",
|
||||
"\\end{$1}"
|
||||
],
|
||||
"description": "Begin/End environment"
|
||||
},
|
||||
"Multicols": {
|
||||
"prefix": "multicols",
|
||||
"body": [
|
||||
"\\begin{multicols}{${1:2}}",
|
||||
"\t$0",
|
||||
"\\end{multicols}"
|
||||
],
|
||||
"description": "Multicols environment"
|
||||
},
|
||||
"Minipage": {
|
||||
"prefix": "minipage",
|
||||
"body": [
|
||||
"\\begin{minipage}{${1:0.5}\\textwidth}",
|
||||
"\t$0",
|
||||
"\\end{minipage}"
|
||||
],
|
||||
"description": "Minipage environment"
|
||||
}
|
||||
}
|
||||
21
nvim/.config/nvim/snippets/tex.lua
Normal file
21
nvim/.config/nvim/snippets/tex.lua
Normal file
@@ -0,0 +1,21 @@
|
||||
local ls = require("luasnip")
|
||||
local s = ls.snippet
|
||||
local t = ls.text_node
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
|
||||
return {
|
||||
-- Auto-expand: tape "beg" + TAB
|
||||
s({ trig = "beg", dscr = "Begin/End environment" }, {
|
||||
t("\\begin{"),
|
||||
i(1, "environment"),
|
||||
t("}"),
|
||||
t({ "", "\t" }),
|
||||
i(0),
|
||||
t({ "", "\\end{" }),
|
||||
f(function(args)
|
||||
return args[1][1]
|
||||
end, { 1 }),
|
||||
t("}"),
|
||||
}),
|
||||
}
|
||||
Reference in New Issue
Block a user