Skip to content

Commit

Permalink
feat(zen-mode-nvim): add integration with vim-matchup if enabled (#485)
Browse files Browse the repository at this point in the history
* feat(zen-mode-nvim): add integration with vim-matchup if enabled

* docs(zen-mode-nvim): update README
  • Loading branch information
Subjective authored Jul 30, 2023
1 parent 299fe33 commit 4671c39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lua/astrocommunity/editing-support/zen-mode-nvim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

🧘 Distraction-free coding for Neovim

Disables diagnostics, indentation, and winbar when entering Zen Mode.

Optionally disables [mini.indentscope](https://github.com/echasnovski/mini.indentscope) and offscreen matchups for [vim-matchup](https://github.com/andymass/vim-matchup), if installed.

**Repository:** <https://github.com/folke/zen-mode.nvim>
18 changes: 16 additions & 2 deletions lua/astrocommunity/editing-support/zen-mode-nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local utils = require "astronvim.utils"

return {
"folke/zen-mode.nvim",
cmd = "ZenMode",
Expand All @@ -21,7 +23,7 @@ return {
laststatus = 0,
},
},
on_open = function() -- disable diagnostics, indent blankline, and winbar
on_open = function() -- disable diagnostics, indent blankline, winbar, and offscreen matchup
vim.g.diagnostics_mode_old = vim.g.diagnostics_mode
vim.g.diagnostics_mode = 0
vim.diagnostic.config(require("astronvim.utils.lsp").diagnostics[vim.g.diagnostics_mode])
Expand All @@ -38,8 +40,15 @@ return {
group = vim.api.nvim_create_augroup("disable_winbar", { clear = true }),
desc = "Ensure winbar stays disabled when writing to file, switching buffers, opening floating windows, etc.",
})

if utils.is_available "vim-matchup" then
vim.cmd.NoMatchParen()
vim.g.matchup_matchparen_offscreen_old = vim.g.matchup_matchparen_offscreen
vim.g.matchup_matchparen_offscreen = {}
vim.cmd.DoMatchParen()
end
end,
on_close = function() -- restore diagnostics, indent blankline, and winbar
on_close = function() -- restore diagnostics, indent blankline, winbar, and offscreen matchup
vim.g.diagnostics_mode = vim.g.diagnostics_mode_old
vim.diagnostic.config(require("astronvim.utils.lsp").diagnostics[vim.g.diagnostics_mode])

Expand All @@ -49,6 +58,11 @@ return {

vim.api.nvim_clear_autocmds { group = "disable_winbar" }
vim.wo.winbar = vim.g.winbar_old

if utils.is_available "vim-matchup" then
vim.g.matchup_matchparen_offscreen = vim.g.matchup_matchparen_offscreen_old
vim.cmd.DoMatchParen()
end
end,
},
}

0 comments on commit 4671c39

Please sign in to comment.