Skip to content

Commit a740dd7

Browse files
committed
feat(mini.nvim): sync to 9101b9e
1 parent 94aeee3 commit a740dd7

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

mini.nvim/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ There are following change types:
171171

172172
- Update `zoom()` to return whether current buffer is zoomed in. By @loichyan, PR #1954.
173173

174+
- Add `log_add()` and related functions (`log_get()`, `log_show()`, `log_clear()`) to work with a special in-memory log array. Useful when debugging Lua code (instead of `print()`).
175+
174176
## mini.pick {#v0.17.0-mini.pick}
175177

176178
### Evolve {#v0.17.0-mini.pick-evolve}

mini.nvim/doc/mini-misc.qmd

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Features the following functions:
1818
Useful in combination with `stat_summary()`.
1919

2020

21+
- [MiniMisc.log\_add()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_add\(\)), [MiniMisc.log\_show()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_show\(\)) and other helper functions to work
22+
with a special in-memory log array. Useful when debugging Lua code.
23+
24+
2125
- [MiniMisc.put()](mini-misc.qmd#minimisc.put) and [MiniMisc.put\_text()](mini-misc.qmd#minimisc.put_text) to pretty print its arguments
2226
into command line and current buffer respectively.
2327

@@ -141,6 +145,110 @@ Compute width of gutter (info column on the left of the window)
141145

142146
---
143147

148+
### log_add() {#minimisc.log_add .help-syntax-right-anchor}
149+
150+
<p align="center">`MiniMisc.log_add`(<span class="help-syntax-special">{desc}</span>, <span class="help-syntax-special">{state}</span>, <span class="help-syntax-special">{opts}</span>)</p>
151+
Add an entry to the in-memory log array
152+
153+
Useful when trying to debug a Lua code (like Neovim config or plugin).
154+
Use this instead of ad-hoc `print()` statements.
155+
156+
Each entry is a table with the following fields:
157+
158+
- <span class="help-syntax-keys">\<desc\></span> `(any)` - entry description. Usually a string describing a place
159+
in the code.
160+
161+
- <span class="help-syntax-keys">\<state\></span> `(any)` - data about current state. Usually a table.
162+
163+
- <span class="help-syntax-keys">\<timestamp\></span> `(number)` - a timestamp of when the entry was added. A number of
164+
milliseconds since the in-memory log was initiated (after [MiniMisc.setup()](mini-misc.qmd#minimisc.setup)
165+
or [MiniMisc.log\_clear()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_clear\(\))). Useful during profiling.
166+
167+
#### Parameters {#minimisc.log_add-parameters}
168+
169+
170+
171+
<span class="help-syntax-special">{desc}</span> `(any)` Entry description.
172+
173+
<span class="help-syntax-special">{state}</span> `(any)` Data about current state.
174+
175+
<span class="help-syntax-special">{opts}</span> `(table|nil)` Options. Possible fields:
176+
177+
- <span class="help-syntax-keys">\<deepcopy\></span> - (boolean) Whether to apply [vim.deepcopy](https://neovim.io/doc/user/helptag.html?tag=vim.deepcopy) to the <span class="help-syntax-special">{state}</span>.
178+
Usually helpful to record the exact state during code execution and avoid
179+
side effects of tables being changed in-place. Default `true`.
180+
181+
#### Usage {#minimisc.log_add-usage}
182+
183+
184+
185+
```lua
186+
local t = { a = 1 }
187+
MiniMisc.log_add('before', { t = t }) -- Will show `t = { a = 1 }` state
188+
t.a = t.a + 1
189+
MiniMisc.log_add('after', { t = t }) -- Will show `t = { a = 2 }` state
190+
191+
-- Use `:lua MiniMisc.log_show()` or `:=MiniMisc.log_get()` to see the log
192+
```
193+
194+
#### See also {#minimisc.log_add-seealso}
195+
196+
197+
198+
- [MiniMisc.log\_get()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_get\(\)) to get log array
199+
200+
- [MiniMisc.log\_show()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_show\(\)) to show log array in the dedicated buffer
201+
202+
- [MiniMisc.log\_clear()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_clear\(\)) to clear the log array
203+
204+
---
205+
206+
### log_get() {#minimisc.log_get .help-syntax-right-anchor}
207+
208+
<p align="center">`MiniMisc.log_get`()</p>
209+
Get log array
210+
211+
#### Return {#minimisc.log_get-return}
212+
213+
214+
`(table[])` Log array. Returned as is, without [vim.deepcopy()](https://neovim.io/doc/user/helptag.html?tag=vim.deepcopy\(\)).
215+
216+
#### See also {#minimisc.log_get-seealso}
217+
218+
219+
220+
- [MiniMisc.log\_add()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_add\(\)) to add to the log array
221+
222+
---
223+
224+
### log_show() {#minimisc.log_show .help-syntax-right-anchor}
225+
226+
<p align="center">`MiniMisc.log_show`()</p>
227+
Show log array in a scratch buffer
228+
229+
#### See also {#minimisc.log_show-seealso}
230+
231+
232+
233+
- [MiniMisc.log\_add()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_add\(\)) to add to the log array
234+
235+
---
236+
237+
### log_clear() {#minimisc.log_clear .help-syntax-right-anchor}
238+
239+
<p align="center">`MiniMisc.log_clear`()</p>
240+
Clear log array
241+
242+
This also sets a new starting point for entry timestamps.
243+
244+
#### See also {#minimisc.log_clear-seealso}
245+
246+
247+
248+
- [MiniMisc.log\_add()](https://neovim.io/doc/user/helptag.html?tag=MiniMisc.log_add\(\)) to add to the log array
249+
250+
---
251+
144252
### put() {#minimisc.put .help-syntax-right-anchor}
145253

146254
<p align="center">`MiniMisc.put`(<span class="help-syntax-special">{...}</span>)</p>

mini.nvim/readmes/mini-misc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ If you want to help this project grow but don't know where to start, check out [
3535
## Features
3636

3737
- `bench_time()` executes function several times and timing how long it took.
38+
- `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()`).
3839
- `put()` and `put_text()` print Lua objects in command line and current buffer respectively.
3940
- `resize_window()` resizes current window to its editable width.
4041
- `setup_auto_root()` sets up automated change of current directory.

0 commit comments

Comments
 (0)