Skip to content

Commit

Permalink
Breaking!: Use gitcommit and gitrebase filetypes instead of custom
Browse files Browse the repository at this point in the history
NeogitCommitMessage -> gitcommit
NeogitBranchDescription -> gitcommit
NeogitMergeMessage -> gitcommit
NeogitTagMessage  -> gitcommit
NeogitRebaseTodo -> gitrebase
  • Loading branch information
CKolkey committed Oct 31, 2024
1 parent 001f43f commit 3e36d02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
29 changes: 2 additions & 27 deletions lua/neogit/buffers/editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ local pad = util.pad_right

local M = {}

local filetypes = {
["COMMIT_EDITMSG"] = "NeogitCommitMessage",
["MERGE_MSG"] = "NeogitMergeMessage",
["TAG_EDITMSG"] = "NeogitTagMessage",
["EDIT_DESCRIPTION"] = "NeogitBranchDescription",
}

---@class EditorBuffer
---@field filename string filename of buffer
---@field on_unload function callback invoked when buffer is unloaded
Expand Down Expand Up @@ -70,12 +63,9 @@ function M:open(kind)
return message
end

local filetype = filetypes[self.filename:match("[%u_]+$")] or "NeogitEditor"
logger.debug("[EDITOR] Filetype " .. filetype)

self.buffer = Buffer.create {
name = self.filename,
filetype = filetype,
filetype = "gitcommit",
load = true,
spell_check = config.values.commit_editor.spell_check,
buftype = "",
Expand All @@ -96,10 +86,8 @@ function M:open(kind)
end
end,
},
on_detach = function(buffer)
on_detach = function()
logger.debug("[EDITOR] Cleaning Up")
pcall(vim.treesitter.stop, buffer.handle)

if self.on_unload then
logger.debug("[EDITOR] Running on_unload callback")
self.on_unload(aborted and 1 or 0)
Expand Down Expand Up @@ -171,19 +159,6 @@ function M:open(kind)
vim.cmd(":startinsert")
end

-- Source runtime ftplugin
vim.cmd.source("$VIMRUNTIME/ftplugin/gitcommit.vim")

-- Apply syntax highlighting
local ok, _ = pcall(vim.treesitter.language.inspect, "gitcommit")
if ok then
logger.debug("[EDITOR] Loading treesitter for gitcommit")
vim.treesitter.start(buffer.handle, "gitcommit")
else
logger.debug("[EDITOR] Loading syntax for gitcommit")
vim.cmd.source("$VIMRUNTIME/syntax/gitcommit.vim")
end

if git.branch.current() then
vim.fn.matchadd("NeogitBranch", git.branch.current(), 100)
end
Expand Down
17 changes: 2 additions & 15 deletions lua/neogit/buffers/rebase_editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,15 @@ function M:open(kind)
self.buffer = Buffer.create {
name = self.filename,
load = true,
filetype = "NeogitRebaseTodo",
filetype = "gitrebase",
buftype = "",
status_column = not config.values.disable_signs and "" or nil,
kind = kind,
modifiable = true,
disable_line_numbers = config.values.disable_line_numbers,
disable_relative_line_numbers = config.values.disable_relative_line_numbers,
readonly = false,
on_detach = function(buffer)
pcall(vim.treesitter.stop, buffer.handle)

on_detach = function()
if self.on_unload then
self.on_unload(aborted and 1 or 0)
end
Expand Down Expand Up @@ -130,17 +128,6 @@ function M:open(kind)
buffer:set_lines(-1, -1, false, help_lines)
buffer:write()
buffer:move_cursor(1)

-- Source runtime ftplugin
vim.cmd.source("$VIMRUNTIME/ftplugin/gitrebase.vim")

-- Apply syntax highlighting
local ok, _ = pcall(vim.treesitter.language.inspect, "git_rebase")
if ok then
vim.treesitter.start(buffer.handle, "git_rebase")
else
vim.cmd.source("$VIMRUNTIME/syntax/gitrebase.vim")
end
end,
mappings = {
i = {
Expand Down

0 comments on commit 3e36d02

Please sign in to comment.