nvim: improve autocmds

This commit is contained in:
chayleaf 2023-03-19 20:40:35 +07:00
parent 3c2e6ab8b9
commit 86243fb78e

View file

@ -118,11 +118,12 @@
lib.mapAttrsToList (k: v: vim.api.nvim_create_autocmd k { inherit group; callback = v; }) { lib.mapAttrsToList (k: v: vim.api.nvim_create_autocmd k { inherit group; callback = v; }) {
BufReadPre = DEFUN (SET vim.o.foldmethod "syntax"); BufReadPre = DEFUN (SET vim.o.foldmethod "syntax");
BufEnter = { buf, ... }: BufEnter = { buf, ... }:
(LET (vim.filetype.match { inherit buf; }) (filetype: L [ LET (vim.filetype.match { inherit buf; }) (filetype: L [
IF (APPLY OR (map (EQ filetype) [ "gitcommit" "markdown" ])) ( IF (APPLY OR (map (EQ filetype) [ "gitcommit" "markdown" ])) (
LET vim.o.colorcolumn (old_colorcolumn: L [ LET vim.o.colorcolumn (old_colorcolumn: L [
SET vim.o.colorcolumn "73" _ SET vim.o.colorcolumn "73" _
vim.api.nvim_create_autocmd "BufLeave" { vim.api.nvim_create_autocmd "BufLeave" {
buffer = buf;
callback = DEFUN (L [ callback = DEFUN (L [
SET vim.o.colorcolumn old_colorcolumn _ SET vim.o.colorcolumn old_colorcolumn _
# return true = delete autocommand # return true = delete autocommand
@ -132,19 +133,11 @@
]) ])
) _ ) _
IF (EQ filetype "markdown") ( IF (EQ filetype "markdown") (
LET vim.o.textwidth (old_textwidth: L [ SET (PROP (IDX vim.bo buf) "textwidth") 72 _
SET vim.o.textwidth 72 _
vim.api.nvim_create_autocmd "BufLeave" {
callback = DEFUN (L [
SET vim.o.textwidth old_textwidth _
true
]);
} _
])
) _ ) _
])); ]);
BufWinEnter = { buf, ... }: BufWinEnter = { buf, ... }:
(LET (vim.filetype.match { inherit buf; }) (filetype: L [ LET (vim.filetype.match { inherit buf; }) (filetype: L [
CALL (PROP vim.cmd "folddoc") "foldopen!" _ CALL (PROP vim.cmd "folddoc") "foldopen!" _
IF (EQ filetype "gitcommit") ( IF (EQ filetype "gitcommit") (
CALL vim.cmd { CALL vim.cmd {
@ -159,7 +152,7 @@
args = [ "g`\"" ]; args = [ "g`\"" ];
} }
) _ ) _
])); ]);
} }
) _ ) _
]); ]);