Skip to content

Commit

Permalink
(mini.align) Implement silencing of non-error feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski committed Feb 24, 2023
1 parent 99d49d7 commit 9a2d1f9
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/mini-align.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ and customization intentions, writing exact rules for disabling module's
functionality is left to user. See |mini.nvim-disabling-recipes| for common
recipes.

# Silencing ~

To stop module from giving non-error feedback, set `vim.g.minialign_silence`
(globally) or `vim.b.minialign_silence` (for a buffer) to `true`.

------------------------------------------------------------------------------
*MiniAlign-glossary*
Glossary
Expand Down
9 changes: 9 additions & 0 deletions lua/mini/align.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
--- and customization intentions, writing exact rules for disabling module's
--- functionality is left to user. See |mini.nvim-disabling-recipes| for common
--- recipes.
---
--- # Silencing ~
---
--- To stop module from giving non-error feedback, set `vim.g.minialign_silence`
--- (globally) or `vim.b.minialign_silence` (for a buffer) to `true`.
---@tag mini.align
---@tag MiniAlign

Expand Down Expand Up @@ -1351,6 +1356,8 @@ end

H.is_disabled = function() return vim.g.minialign_disable == true or vim.b.minialign_disable == true end

H.is_silenced = function() return vim.g.minialign_silence == true or vim.b.minialign_silence == true end

H.get_config =
function(config) return vim.tbl_deep_extend('force', MiniAlign.config, vim.b.minialign_config or {}, config or {}) end

Expand Down Expand Up @@ -1923,6 +1930,8 @@ end

-- Utilities ------------------------------------------------------------------
H.echo = function(msg, add_to_history)
if H.is_silenced() then return end

-- Construct message chunks
msg = type(msg) == 'string' and { { msg } } or msg
table.insert(msg, 1, { '(mini.align) ', 'WarningMsg' })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--|---------|---------|
01|a_b
02|aa_b
03|~
04|~
05|~
06|~
07|~
08|~
09|~
10|~
11|<ame] [+] 2,1 All
12|-- VISUAL2

--|---------|---------|
01|00011111111111111111
02|10001111111111111111
03|22222222222222222222
04|22222222222222222222
05|22222222222222222222
06|22222222222222222222
07|22222222222222222222
08|22222222222222222222
09|22222222222222222222
10|22222222222222222222
11|33333333333333333333
12|44444444455555555555
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--|---------|---------|
01|a_b
02|aa_b
03|~
04|~
05|~
06|~
07|~
08|~
09|~
10|~
11|<ame] [+] 2,1 All
12|-- VISUAL2

--|---------|---------|
01|00011111111111111111
02|10001111111111111111
03|22222222222222222222
04|22222222222222222222
05|22222222222222222222
06|22222222222222222222
07|22222222222222222222
08|22222222222222222222
09|22222222222222222222
10|22222222222222222222
11|33333333333333333333
12|44444444455555555555
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--|---------|---------|
01|a_b_c
02|aaa_bbb_ccc
03|~
04|~
05|~
06|~
07|<ame] [+] 2,1 All
08|
09|
10|
11|
12|-- VISUAL2

--|---------|---------|
01|00000111111111111111
02|10000000000111111111
03|22222222222222222222
04|22222222222222222222
05|22222222222222222222
06|22222222222222222222
07|33333333333333333333
08|44444444444444444444
09|44444444444444444444
10|44444444444444444444
11|44444444444444444444
12|55555555544444444444
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--|---------|---------|
01|a_b_c
02|aaa_bbb_ccc
03|~
04|~
05|~
06|~
07|<ame] [+] 2,1 All
08|
09|
10|
11|
12|-- VISUAL2

--|---------|---------|
01|00000111111111111111
02|10000000000111111111
03|22222222222222222222
04|22222222222222222222
05|22222222222222222222
06|22222222222222222222
07|33333333333333333333
08|44444444444444444444
09|44444444444444444444
10|44444444444444444444
11|44444444444444444444
12|55555555544444444444
33 changes: 33 additions & 0 deletions tests/test_align.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,23 @@ T['Align']['respects `vim.{g,b}.minialign_disable`'] = new_set({
end,
})

T['Align']['respects `vim.{g,b}.minialign_silence`'] = new_set({
parametrize = { { 'g' }, { 'b' } },
}, {
test = function(var_type)
child.set_size(12, 20)
child[var_type].minialign_silence = true

-- Should not prompt message after idle second
set_lines({ 'a_b', 'aa_b' })
set_cursor(1, 0)
type_keys('Vip', 'ga')

sleep(1000 + 15)
child.expect_screenshot()
end,
})

-- Test mostly "preview" part. Hope that other is covered in 'Align' tests.
T['Align with preview'] =
new_set({ hooks = {
Expand Down Expand Up @@ -1608,6 +1625,22 @@ T['Align with preview']['respects `vim.{g,b}.minialign_disable`'] = new_set({
end,
})

T['Align with preview']['respects `vim.{g,b}.minialign_silence`'] = new_set({
parametrize = { { 'g' }, { 'b' } },
}, {
test = function(var_type)
child.set_size(12, 20)
child[var_type].minialign_silence = true

set_lines({ 'a_b_c', 'aaa_bbb_ccc' })
set_cursor(1, 0)
type_keys('V', 'j', 'gA')

-- Should not show helper message
child.expect_screenshot()
end,
})

local init_preview_align = function(lines, keys)
child.ensure_normal_mode()
set_lines(lines or { 'a_b', 'aaa_b' })
Expand Down

0 comments on commit 9a2d1f9

Please sign in to comment.