summaryrefslogtreecommitdiffstats
path: root/.config/nvim/after/ftplugin
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/after/ftplugin')
-rw-r--r--.config/nvim/after/ftplugin/bash.lua17
-rw-r--r--.config/nvim/after/ftplugin/lua.lua29
-rw-r--r--.config/nvim/after/ftplugin/markdown.lua56
-rw-r--r--.config/nvim/after/ftplugin/python.lua12
-rw-r--r--.config/nvim/after/ftplugin/sh.lua7
5 files changed, 10 insertions, 111 deletions
diff --git a/.config/nvim/after/ftplugin/bash.lua b/.config/nvim/after/ftplugin/bash.lua
deleted file mode 100644
index 6e10433..0000000
--- a/.config/nvim/after/ftplugin/bash.lua
+++ /dev/null
@@ -1,17 +0,0 @@
-vim.opt_local.textwidth = vim.g.dotfiles.textwidth.sh -- gw wraps at this value
-vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth'
-vim.opt_local.complete = {
- "o", -- 'omnifunc'
-}
-
-vim.b.autoformat = true
-vim.b.format_func = function()
- local ret = vim.system({ "shfmt" }, { stdin = vim.api.nvim_buf_get_lines(0, 0, -1, false) }):wait()
- if ret.code ~= 0 then
- vim.notify("shfmt failed (" .. ret.code .. "):\n" .. ret.stderr, vim.log.levels.WARN)
- return
- end
- local view = vim.fn.winsaveview()
- vim.cmd("%!shfmt")
- vim.fn.winrestview(view)
-end
diff --git a/.config/nvim/after/ftplugin/lua.lua b/.config/nvim/after/ftplugin/lua.lua
index b7d29c1..2b2f2c5 100644
--- a/.config/nvim/after/ftplugin/lua.lua
+++ b/.config/nvim/after/ftplugin/lua.lua
@@ -1,29 +1,3 @@
-local function format()
- local view = vim.fn.winsaveview()
- local buf_str = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), "\n") .. "\n"
- local tempname = vim.fn.tempname()
- local tempfile = assert(io.open(tempname, "w"), "Could not open temporary file")
- tempfile:write(buf_str)
- tempfile:close()
- local r_check = vim.system({ "stylua", "--check", tempname }):wait()
- if r_check.code == 0 then
- return
- elseif r_check.code ~= 1 then
- vim.notify("stylua failed (" .. r_check.code .. "):\n" .. r_check.stderr)
- end
- local r_format = vim.system({ "stylua", tempname }):wait()
- if r_format.code ~= 0 then
- vim.notify("stylua failed (" .. r_format.code .. "):\n" .. r_format.stderr)
- end
- local formatted_lines = {}
- for line in io.lines(tempname) do
- formatted_lines[#formatted_lines + 1] = line
- end
- os.remove(tempname)
- vim.api.nvim_buf_set_lines(0, 0, -1, false, formatted_lines)
- vim.fn.winrestview(view)
-end
-
vim.opt_local.textwidth = vim.g.dotfiles.textwidth.lua -- gw wraps at this value
vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth'
vim.opt_local.complete = {
@@ -31,8 +5,7 @@ vim.opt_local.complete = {
"F", -- 'completefunc' (snippet source, see plugin/50-completion.lua)
}
-vim.b.autoformat = true
-vim.b.format_func = format
+vim.b.format = true -- See plugin/50-format.lua
------------------------------------------------------------------------------------------------------------------------
-- Snippets
diff --git a/.config/nvim/after/ftplugin/markdown.lua b/.config/nvim/after/ftplugin/markdown.lua
index d492855..f0f9691 100644
--- a/.config/nvim/after/ftplugin/markdown.lua
+++ b/.config/nvim/after/ftplugin/markdown.lua
@@ -1,56 +1,3 @@
-local function format()
- local view = vim.fn.winsaveview()
- local buf_str = table.concat(vim.api.nvim_buf_get_lines(0, 0, -1, false), "\n") .. "\n"
- local tempname = vim.fn.tempname()
- local tempfile = assert(io.open(tempname, "w"), "Could not open temporary file")
- tempfile:write(buf_str)
- tempfile:close()
-
- local r_check = vim.system({
- "mdformat",
- "--number",
- "--extensions",
- "tables",
- "--extensions",
- "frontmatter",
- "--extensions",
- "wikilink",
- "--wrap",
- tostring(vim.bo.textwidth),
- "--check",
- tempname,
- }):wait()
- if r_check.code == 0 then
- return
- elseif r_check.code ~= 1 then
- vim.notify("mdformat failed (" .. r_check.code .. "):\n" .. r_check.stderr)
- end
- local r_format = vim.system({
- "mdformat",
- "--number",
- "--extensions",
- "tables",
- "--extensions",
- "frontmatter",
- "--extensions",
- "wikilink",
- "--wrap",
- tostring(vim.bo.textwidth),
- tempname,
- }):wait()
- if r_format.code ~= 0 then
- vim.notify("mdformat failed (" .. r_format.code .. "):\n" .. r_format.stderr)
- end
- local formatted_lines = {}
- for line in io.lines(tempname) do
- formatted_lines[#formatted_lines + 1] = line
- end
- os.remove(tempname)
- vim.api.nvim_buf_set_lines(0, 0, -1, false, formatted_lines)
-
- vim.fn.winrestview(view)
-end
-
vim.opt_local.tabstop = 2 -- CommonMark expects two spaces for indentation
vim.opt_local.shiftwidth = 0
vim.opt_local.softtabstop = -1
@@ -74,8 +21,7 @@ vim.opt_local.complete = {
-- Visible link labels
vim.api.nvim_set_hl(0, "@markup.link.label.markdown_inline", { underline = true, update = true })
-vim.b.autoformat = true
-vim.b.format_func = format
+vim.b.format = true -- See plugin/50-format.lua
local function item_range()
local cursor_row = vim.api.nvim_win_get_cursor(0)[1]
diff --git a/.config/nvim/after/ftplugin/python.lua b/.config/nvim/after/ftplugin/python.lua
index fa39ee8..63045ed 100644
--- a/.config/nvim/after/ftplugin/python.lua
+++ b/.config/nvim/after/ftplugin/python.lua
@@ -4,14 +4,4 @@ vim.opt_local.complete = {
"o", -- 'omnifunc'
}
-vim.b.autoformat = true
-vim.b.format_func = function()
- local ret = vim.system({ "black", "--check", "-" }, { stdin = vim.api.nvim_buf_get_lines(0, 0, -1, false) }):wait()
- if ret.code > 1 then
- vim.notify("black failed (" .. ret.code .. "):\n" .. ret.stderr, vim.log.levels.WARN)
- return
- end
- local view = vim.fn.winsaveview()
- vim.cmd("%!black --quiet -")
- vim.fn.winrestview(view)
-end
+vim.b.format = true -- See plugin/50-format.lua
diff --git a/.config/nvim/after/ftplugin/sh.lua b/.config/nvim/after/ftplugin/sh.lua
new file mode 100644
index 0000000..3574ac0
--- /dev/null
+++ b/.config/nvim/after/ftplugin/sh.lua
@@ -0,0 +1,7 @@
+vim.opt_local.textwidth = vim.g.dotfiles.textwidth.sh -- gw wraps at this value
+vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth'
+vim.opt_local.complete = {
+ "o", -- 'omnifunc'
+}
+
+vim.b.format = true -- See plugin/50-format.lua