Skip to content

Commit fe8a669

Browse files
committed
feat(ALL)!: stop forcing option values behind set_vim_settings
Details: - Instead set them automatically in `setup()` if not set by user/plugin before it (no matter the value). Document this as a new general principle to be followed in the future. The general idea behind this principle is that if user sets the particular option prior to `setup()`, then it is assumed to be intentional and the module should not interfere. For example, setting fuzzy support for 'mini.completion' (with `vim.o.completeopt = 'menuone,noselect,fuzzy'`) should be possible to do independently of `require('mini.completion').setup()`.
1 parent e744b5d commit fe8a669

20 files changed

+82
-109
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
- BREAKING FEATURE: Unify how module-related buffers are named: `mini<module-name>://<buffer-number>/<useful-info>`. This structure allows creating identifiable, reasonably unique, and useful buffer names. This is a user facing change because in some cases the shown buffer's name will change (like in statusline of opened 'mini.starter' buffer or output of `:buffers!`).
1212

13+
- BREAKING FEATURE: stop forcing recommended option values behind `set_vim_settings` config setting. Instead set them automatically in `setup()` if not set by user/plugin before it (no matter the value). Document this as a new general principle to be followed in the future. Affected modules:
14+
- 'mini.bufremove' (do nothing as recommended 'hidden' is on by default)
15+
- 'mini.completion' (set 'completeopt=menuone,noselect' and flags "cC" in 'shortmess')
16+
- 'mini.statusline' (do nothing as recommended 'laststatus=2' is default)
17+
- 'mini.tabline' (set 'showtabline=2')
18+
1319
## mini.ai
1420

1521
- FEATURE: textobject identifier can now be any single character supported by `:h getcharstr()`. This also makes it possible to use characters outside of Latin alphanumeric and punctuation sets as `custom_textobjects` keys. Default textobject is extended to be anything but Latin letters (to fall back to `:h text-objects`).

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ These modules don't quite fit in any of the previous categories.
161161

162162
- Values of `config` which affect runtime activity can be changed on the fly to have effect. For example, `MiniSurround.config.n_lines` can be changed during runtime; but changing `MiniSurround.config.mappings` won't have any effect (as mappings are created once during `setup()`).
163163

164+
- If module works best with some specific non-default option value, it is set during `setup()` but only if it was not explicitly set (by user or another plugin, no matter the value) before that.
165+
164166
- **Buffer local configuration**. Each module can be additionally configured to use certain runtime config settings locally to buffer. See `mini.nvim-buffer-local-config` section in help file for more information.
165167

166168
- **Buffer names**. All module-related buffers are named according to the following format: `mini<module-name>://<buffer-number>/<useful-info>` (forward slashes are used on any platform; `<useful-info>` may be empty). This structure allows creating identifiable, reasonably unique, and useful buffer names. For example, 'mini.files' buffers are created per displayed directory/file with names like `minifiles://10/path/to/displayed/directory`.

doc/mini-bufremove.txt

-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ Module config
6161
Default values:
6262
>lua
6363
MiniBufremove.config = {
64-
-- Whether to set Vim's settings for buffers (allow hidden buffers)
65-
set_vim_settings = true,
66-
6764
-- Whether to disable showing non-error feedback
6865
silent = false,
6966
}

doc/mini-completion.txt

+7-4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ You can override runtime config settings locally to buffer inside
8080
`vim.b.minicompletion_config` which should have same structure as
8181
`MiniCompletion.config`. See |mini.nvim-buffer-local-config| for more details.
8282

83+
# Suggested option values ~
84+
85+
Some options are set automatically (if not set before |MiniCompletion.setup()|):
86+
- 'completeopt' is set to "menuone,noselect" for less intrusive popup.
87+
To enable fuzzy matching, manually set to "menuone,noselect,fuzzy".
88+
- 'shortmess' is appended with "c" flag for silent <C-n> fallback.
89+
8390
# Snippets ~
8491

8592
As per LSP specification, some completion items can be supplied in the form of
@@ -280,10 +287,6 @@ Default values:
280287
scroll_down = '<C-f>',
281288
scroll_up = '<C-b>',
282289
},
283-
284-
-- Whether to set Vim's settings for better experience (modifies
285-
-- `shortmess` and `completeopt`)
286-
set_vim_settings = true,
287290
}
288291
<
289292
------------------------------------------------------------------------------

doc/mini-statusline.txt

-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ Default values:
149149

150150
-- Whether to use icons by default
151151
use_icons = true,
152-
153-
-- Whether to set Vim's settings for statusline (make it always shown)
154-
set_vim_settings = true,
155152
}
156153
<
157154
------------------------------------------------------------------------------

doc/mini-tabline.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ You can override runtime config settings locally to buffer inside
5050
`vim.b.minitabline_config` which should have same structure as
5151
`MiniTabline.config`. See |mini.nvim-buffer-local-config| for more details.
5252

53+
# Suggested option values ~
54+
55+
Some options are set automatically (if not set before |MiniTabline.setup()|):
56+
- 'showtabline' is set to 2 to always show tabline.
57+
5358
# Highlight groups ~
5459

5560
* `MiniTablineCurrent` - buffer is current (has cursor in it).
@@ -101,10 +106,6 @@ Default values:
101106
-- By default surrounds with space and possibly prepends with icon
102107
format = nil,
103108

104-
-- Whether to set Vim's settings for tabline (make it always shown and
105-
-- allow hidden buffers)
106-
set_vim_settings = true,
107-
108109
-- Where to show tabpage section in case of multiple vim tabpages.
109110
-- One of 'left', 'right', 'none'.
110111
tabpage_section = 'left',

doc/mini.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ Table of contents:
9696
`MiniSurround.config.mappings` won't have any effect (as mappings are
9797
created once during `setup()`).
9898

99+
- If module works best with some specific non-default option value, it is
100+
set during `setup()` but only if it was not explicitly set (by user or
101+
another plugin, no matter the value) before that.
102+
99103
- <Buffer local configuration>. Each module can be additionally configured
100104
to use certain runtime config settings locally to buffer.
101105
See |mini.nvim-buffer-local-config| for more information.
@@ -386,9 +390,8 @@ Automated disabling is suggested to be done inside autocommands: >lua
386390
Buffer local config
387391

388392
Each module can be additionally configured locally to buffer by creating
389-
appropriate buffer-scoped variable with values you want to override. It
390-
will affect only runtime options and not those used once during setup (like
391-
`mappings` or `set_vim_settings`).
393+
appropriate buffer-scoped variable with values to override. It affects only
394+
runtime options and not those used once during setup (like most `mappings`).
392395

393396
Variable names have the same structure: `b:mini*_config` where `*` is
394397
module's lowercase name. For example, `b:minianimate_config` can store

lua/mini/bufremove.lua

+1-11
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ end
8484
--- Default values:
8585
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
8686
MiniBufremove.config = {
87-
-- Whether to set Vim's settings for buffers (allow hidden buffers)
88-
set_vim_settings = true,
89-
9087
-- Whether to disable showing non-error feedback
9188
silent = false,
9289
}
@@ -189,19 +186,12 @@ H.setup_config = function(config)
189186
H.check_type('config', config, 'table', true)
190187
config = vim.tbl_deep_extend('force', vim.deepcopy(H.default_config), config or {})
191188

192-
H.check_type('set_vim_settings', config.set_vim_settings, 'boolean')
193189
H.check_type('silent', config.silent, 'boolean')
194190

195191
return config
196192
end
197193

198-
H.apply_config = function(config)
199-
MiniBufremove.config = config
200-
201-
if config.set_vim_settings then
202-
vim.o.hidden = true -- Allow hidden buffers
203-
end
204-
end
194+
H.apply_config = function(config) MiniBufremove.config = config end
205195

206196
H.is_disabled = function() return vim.g.minibufremove_disable == true or vim.b.minibufremove_disable == true end
207197

lua/mini/completion.lua

+16-12
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@
8080
--- `vim.b.minicompletion_config` which should have same structure as
8181
--- `MiniCompletion.config`. See |mini.nvim-buffer-local-config| for more details.
8282
---
83+
--- # Suggested option values ~
84+
---
85+
--- Some options are set automatically (if not set before |MiniCompletion.setup()|):
86+
--- - 'completeopt' is set to "menuone,noselect" for less intrusive popup.
87+
--- To enable fuzzy matching, manually set to "menuone,noselect,fuzzy".
88+
--- - 'shortmess' is appended with "c" flag for silent <C-n> fallback.
89+
---
8390
--- # Snippets ~
8491
---
8592
--- As per LSP specification, some completion items can be supplied in the form of
@@ -342,10 +349,6 @@ MiniCompletion.config = {
342349
scroll_down = '<C-f>',
343350
scroll_up = '<C-b>',
344351
},
345-
346-
-- Whether to set Vim's settings for better experience (modifies
347-
-- `shortmess` and `completeopt`)
348-
set_vim_settings = true,
349352
}
350353
--minidoc_afterlines_end
351354

@@ -711,7 +714,6 @@ H.setup_config = function(config)
711714
H.error('`fallback_action` should be function or string, not ' .. type(config.fallback_action))
712715
end
713716
H.check_type('mappings', config.mappings, 'table')
714-
H.check_type('set_vim_settings', config.set_vim_settings, 'boolean')
715717

716718
H.check_type('delay.completion', config.delay.completion, 'number')
717719
H.check_type('delay.info', config.delay.info, 'number')
@@ -762,14 +764,16 @@ H.apply_config = function(config)
762764
map_scroll(config.mappings.scroll_down, 'down')
763765
map_scroll(config.mappings.scroll_up, 'up')
764766

765-
if config.set_vim_settings then
766-
-- Don't give ins-completion-menu messages
767-
vim.opt.shortmess:append('c')
768-
if vim.fn.has('nvim-0.9') == 1 then vim.opt.shortmess:append('C') end
767+
-- Try setting suggested option values
768+
-- TODO: use `nvim_get_option_info2` after Neovim=0.8 support is dropped
769+
-- - More common completion behavior
770+
local was_set = vim.api.nvim_get_option_info('completeopt').was_set
771+
if not was_set then vim.o.completeopt = 'menuone,noselect' end
769772

770-
-- More common completion behavior
771-
vim.o.completeopt = 'menuone,noselect'
772-
end
773+
-- - Don't show ins-completion-menu messages ("C" is default on Neovim>=0.10)
774+
local shortmess_flags = 'c' .. ((vim.fn.has('nvim-0.9') == 1 and vim.fn.has('nvim-0.10') == 0) and 'C' or '')
775+
was_set = vim.api.nvim_get_option_info('shortmess').was_set
776+
if not was_set then vim.opt.shortmess:append(shortmess_flags) end
773777
end
774778

775779
H.create_autocommands = function(config)

lua/mini/init.lua

+6-3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696
--- `MiniSurround.config.mappings` won't have any effect (as mappings are
9797
--- created once during `setup()`).
9898
---
99+
--- - If module works best with some specific non-default option value, it is
100+
--- set during `setup()` but only if it was not explicitly set (by user or
101+
--- another plugin, no matter the value) before that.
102+
---
99103
--- - <Buffer local configuration>. Each module can be additionally configured
100104
--- to use certain runtime config settings locally to buffer.
101105
--- See |mini.nvim-buffer-local-config| for more information.
@@ -384,9 +388,8 @@
384388
--- Buffer local config
385389
---
386390
--- Each module can be additionally configured locally to buffer by creating
387-
--- appropriate buffer-scoped variable with values you want to override. It
388-
--- will affect only runtime options and not those used once during setup (like
389-
--- `mappings` or `set_vim_settings`).
391+
--- appropriate buffer-scoped variable with values to override. It affects only
392+
--- runtime options and not those used once during setup (like most `mappings`).
390393
---
391394
--- Variable names have the same structure: `b:mini*_config` where `*` is
392395
--- module's lowercase name. For example, `b:minianimate_config` can store

lua/mini/statusline.lua

-7
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ MiniStatusline.config = {
176176

177177
-- Whether to use icons by default
178178
use_icons = true,
179-
180-
-- Whether to set Vim's settings for statusline (make it always shown)
181-
set_vim_settings = true,
182179
}
183180
--minidoc_afterlines_end
184181

@@ -502,7 +499,6 @@ H.setup_config = function(config)
502499
H.check_type('content.active', config.content.active, 'function', true)
503500
H.check_type('content.inactive', config.content.inactive, 'function', true)
504501

505-
H.check_type('set_vim_settings', config.set_vim_settings, 'boolean')
506502
H.check_type('use_icons', config.use_icons, 'boolean')
507503

508504
return config
@@ -511,9 +507,6 @@ end
511507
H.apply_config = function(config)
512508
MiniStatusline.config = config
513509

514-
-- Set settings to ensure statusline is displayed properly
515-
if config.set_vim_settings and (vim.o.laststatus == 0 or vim.o.laststatus == 1) then vim.o.laststatus = 2 end
516-
517510
-- Set statusline globally and dynamically decide which content to use
518511
vim.go.statusline =
519512
'%{%(nvim_get_current_win()==#g:actual_curwin || &laststatus==3) ? v:lua.MiniStatusline.active() : v:lua.MiniStatusline.inactive()%}'

lua/mini/tabline.lua

+9-10
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
--- `vim.b.minitabline_config` which should have same structure as
5151
--- `MiniTabline.config`. See |mini.nvim-buffer-local-config| for more details.
5252
---
53+
--- # Suggested option values ~
54+
---
55+
--- Some options are set automatically (if not set before |MiniTabline.setup()|):
56+
--- - 'showtabline' is set to 2 to always show tabline.
57+
---
5358
--- # Highlight groups ~
5459
---
5560
--- * `MiniTablineCurrent` - buffer is current (has cursor in it).
@@ -146,10 +151,6 @@ MiniTabline.config = {
146151
-- By default surrounds with space and possibly prepends with icon
147152
format = nil,
148153

149-
-- Whether to set Vim's settings for tabline (make it always shown and
150-
-- allow hidden buffers)
151-
set_vim_settings = true,
152-
153154
-- Where to show tabpage section in case of multiple vim tabpages.
154155
-- One of 'left', 'right', 'none'.
155156
tabpage_section = 'left',
@@ -215,7 +216,6 @@ H.setup_config = function(config)
215216

216217
H.check_type('show_icons', config.show_icons, 'boolean')
217218
H.check_type('format', config.format, 'function', true)
218-
H.check_type('set_vim_settings', config.set_vim_settings, 'boolean')
219219
H.check_type('tabpage_section', config.tabpage_section, 'string')
220220

221221
return config
@@ -224,11 +224,10 @@ end
224224
H.apply_config = function(config)
225225
MiniTabline.config = config
226226

227-
-- Set settings to ensure tabline is displayed properly
228-
if config.set_vim_settings then
229-
vim.o.showtabline = 2 -- Always show tabline
230-
vim.o.hidden = true -- Allow switching buffers without saving them
231-
end
227+
-- Try making tabline always visible
228+
-- TODO: use `nvim_get_option_info2` after Neovim=0.8 support is dropped
229+
local was_set = vim.api.nvim_get_option_info('showtabline').was_set
230+
if not was_set then vim.o.showtabline = 2 end
232231

233232
-- Cache truncation characters
234233
H.cache_trunc_chars()

readmes/mini-bufremove.md

-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ Here are code snippets for some common installation methods (use only one):
136136
```lua
137137
-- No need to copy this inside `setup()`. Will be used automatically.
138138
{
139-
-- Whether to set Vim's settings for buffers (allow hidden buffers)
140-
set_vim_settings = true,
141-
142139
-- Whether to disable showing non-error feedback
143140
silent = false,
144141
}

readmes/mini-completion.md

-4
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,6 @@ Here are code snippets for some common installation methods (use only one):
215215
scroll_down = '<C-f>',
216216
scroll_up = '<C-b>',
217217
},
218-
219-
-- Whether to set Vim's settings for better experience (modifies
220-
-- `shortmess` and `completeopt`)
221-
set_vim_settings = true,
222218
}
223219
```
224220

readmes/mini-statusline.md

-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ Here are code snippets for some common installation methods (use only one):
156156

157157
-- Whether to use icons by default
158158
use_icons = true,
159-
160-
-- Whether to set Vim's settings for statusline (make it always shown)
161-
set_vim_settings = true,
162159
}
163160
```
164161

readmes/mini-tabline.md

-4
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ Here are code snippets for some common installation methods (use only one):
152152
-- By default surrounds with space and possibly prepends with icon
153153
format = nil,
154154

155-
-- Whether to set Vim's settings for tabline (make it always shown and
156-
-- allow hidden buffers)
157-
set_vim_settings = true,
158-
159155
-- Where to show tabpage section in case of multiple vim tabpages.
160156
-- One of 'left', 'right', 'none'.
161157
tabpage_section = 'left',

tests/test_bufremove.lua

+2-4
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,13 @@ T['setup()']['creates `config` field'] = function()
212212
eq(child.lua_get('type(_G.MiniBufremove.config)'), 'table')
213213

214214
-- Check default values
215-
eq(child.lua_get('MiniBufremove.config.set_vim_settings'), true)
216215
eq(child.lua_get('MiniBufremove.config.silent'), false)
217216
end
218217

219218
T['setup()']['respects `config` argument'] = function()
220219
unload_module()
221-
load_module({ set_vim_settings = false })
222-
eq(child.lua_get('MiniBufremove.config.set_vim_settings'), false)
220+
load_module({ silent = true })
221+
eq(child.lua_get('MiniBufremove.config.silent'), true)
223222
end
224223

225224
T['setup()']['validates `config` argument'] = function()
@@ -230,7 +229,6 @@ T['setup()']['validates `config` argument'] = function()
230229
end
231230

232231
expect_config_error('a', 'config', 'table')
233-
expect_config_error({ set_vim_settings = 'a' }, 'set_vim_settings', 'boolean')
234232
expect_config_error({ silent = 'a' }, 'silent', 'boolean')
235233
end
236234

0 commit comments

Comments
 (0)