Skip to content

Commit 0bbf9b4

Browse files
committed
feat(mini.nvim): sync to 4e61631
1 parent f806f51 commit 0bbf9b4

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

mini.nvim/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ There are following change types:
4444

4545
The previous "reset by explicitly setting initial background color" behavior is available by setting the new `opts.explicit_reset` option to `true`.
4646

47+
### Expand {#v0.18.0-mini.misc-expand}
48+
49+
- Add `safely()` to execute a function reporting its possible error as warning. It can also postpone execution until certain condition (like event, fixed delay, etc.).
50+
51+
It is intended to be a future replacement for `MiniDeps.now()` and `MiniDeps.later()`.
52+
4753
## mini.pairs {#v0.18.0-mini.pairs}
4854

4955
### Refine {#v0.18.0-mini.pairs-refine}

mini.nvim/doc/mini-misc.qmd

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Features the following functions:
2929
- [MiniMisc.resize\_window()](mini-misc.qmd#minimisc.resize_window) to resize current window to its editable width.
3030

3131

32+
- [MiniMisc.safely()](mini-misc.qmd#minimisc.safely) to execute a function on a condition and warn on error.
33+
Useful to organize [init.lua](https://neovim.io/doc/user/helptag.html?tag=init.lua) in fail-safe sections with simple lazy loading.
34+
35+
3236
- [MiniMisc.setup\_auto\_root()](mini-misc.qmd#minimisc.setup_auto_root) to set up automated change of current directory.
3337

3438

@@ -293,6 +297,65 @@ Resize window to have exact number of editable columns
293297

294298
---
295299

300+
### safely() {#minimisc.safely .help-syntax-right-anchor}
301+
302+
<p align="center">`MiniMisc.safely`(<span class="help-syntax-special">{when}</span>, <span class="help-syntax-special">{f}</span>)</p>
303+
Execute a function on a condition and warn on error
304+
305+
Input function is executed exactly once. Its possible error is captured and is
306+
shown as a [vim.notify()](https://neovim.io/doc/user/helptag.html?tag=vim.notify\(\)) warning.
307+
308+
Useful to organize [init.lua](https://neovim.io/doc/user/helptag.html?tag=init.lua) in fail-safe sections with simple lazy loading.
309+
310+
#### Parameters {#minimisc.safely-parameters}
311+
312+
313+
314+
<span class="help-syntax-special">{when}</span> `(string)` When to execute a function. One of:
315+
316+
- `'now'` - immediately.
317+
318+
- `'later'` - queue to be executed soon without blocking the execution of next
319+
code in file. Queued functions are executed in order they are added.
320+
321+
- `'delay:<number>'` - after a specified delay with [vim.defer\_fn()](https://neovim.io/doc/user/helptag.html?tag=vim.defer_fn\(\)).
322+
323+
- `'event:<events>'` - on whichever specified event is triggered first.
324+
325+
- `'event:<events>~<patterns>` - same as above, but events must match
326+
specified [autocmd-pattern](https://neovim.io/doc/user/helptag.html?tag=autocmd-pattern).
327+
328+
- `'filetype:<filetypes>'` - same as `'event:FileType~<filetypes>'`, but follow
329+
successful function execution with [filetype-detect](https://neovim.io/doc/user/helptag.html?tag=filetype-detect) for all normal buffers
330+
(if new [ftdetect](https://neovim.io/doc/user/helptag.html?tag=ftdetect) scripts were added) and sourcing [ftplugin](https://neovim.io/doc/user/helptag.html?tag=ftplugin) (for buffers
331+
matching `<filetypes>`). Intended to be used for loading "language plugins".
332+
333+
<span class="help-syntax-special">{f}</span> `(function)` Function to execute (without arguments).
334+
335+
#### Usage {#minimisc.safely-usage}
336+
337+
338+
339+
```lua
340+
MiniMisc.safely('later', function()
341+
vim.notify('This will be executed after the next "now" call')
342+
end)
343+
MiniMisc.safely('now', function() error('This will be a warning') end)
344+
345+
MiniMisc.safely('event:InsertEnter', function()
346+
require('mini.completion').setup()
347+
end)
348+
MiniMisc.safely('event:CmdlineEnter~/', function()
349+
vim.notify('Start searching for the first time')
350+
end)
351+
352+
MiniMisc.safely('filetype:tex,plaintex', function()
353+
-- Load plugin to improve writing LaTeX
354+
end)
355+
```
356+
357+
---
358+
296359
### setup_auto_root() {#minimisc.setup_auto_root .help-syntax-right-anchor}
297360

298361
<p align="center">`MiniMisc.setup_auto_root`(<span class="help-syntax-special">{names}</span>, <span class="help-syntax-special">{fallback}</span>)</p>

mini.nvim/readmes/mini-misc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ If you want to help this project grow but don't know where to start, check out [
3838
- `log_add()` / `log_show()` and other helper functions to work with a special in-memory log array. Useful when debugging Lua code (instead of `print()`).
3939
- `put()` and `put_text()` print Lua objects in command line and current buffer respectively.
4040
- `resize_window()` resizes current window to its editable width.
41+
- `safely()` to execute a function on a condition and warn on error. Useful to organize 'init.lua' in fail-safe sections with simple lazy loading.
4142
- `setup_auto_root()` sets up automated change of current directory.
4243
- `setup_termbg_sync()` to set up terminal background synchronization (removes possible "frame" around current Neovim instance).
4344
- `setup_restore_cursor()` sets up automated restoration of cursor position on file reopen.

0 commit comments

Comments
 (0)