|
1 | 1 | # debugprint.nvim
|
2 | 2 |
|
3 |
| -## Purpose |
| 3 | +## Overview |
4 | 4 |
|
5 | 5 | The gold standard for debugging a program or script is to use a real debugger.
|
6 | 6 | For NeoVim, the 'standard' way to integrate this is to use something like
|
7 | 7 | [nvim-dap](https://github.com/mfussenegger/nvim-dap). However, many folks prefer
|
8 | 8 | a more low-tech approach; the 'print' statement, or the equivalent in a
|
9 | 9 | particular language, to trace the output of a program during execution.
|
10 |
| -`debugprint` is a NeoVim plugin for them, as it can generate 'print' statements |
11 |
| -appropriate to the language being edited, which include the filename/line number |
12 |
| -they are being inserted on, a counter which increases over the duration of a |
13 |
| -NeoVim session each time a statement is generated, as well as optionally |
14 |
| -printing out a variable, including automatically picking up an |
15 |
| -identifier/variable name under the cursor. `debugprint` comes with the |
16 |
| -generation logic built in for many common programming languages, and can be |
17 |
| -extended to support more. |
| 10 | +`debugprint` is a NeoVim plugin for them, as it can easily generate 'print' |
| 11 | +statements appropriate to the language being edited, which include: |
| 12 | + |
| 13 | +* A tag string unique to `debugprint`. |
| 14 | + |
| 15 | +* The filename/line number they are being inserted on. |
| 16 | + |
| 17 | +* A counter which increases over the duration of a NeoVim session each time a statement is generated. |
| 18 | + |
| 19 | +* (optionally) A variable (which may be automatically picked up from an identifier/variable name under the cursor). |
| 20 | + |
| 21 | +`debugprint` comes with the generation logic built in for many common |
| 22 | +programming languages, and can be extended to support more. |
18 | 23 |
|
19 | 24 | `debugprint` is inspired by
|
20 | 25 | [vim-debugstring](https://github.com/bergercookie/vim-debugstring), which I've
|
@@ -103,7 +108,7 @@ to use it. There are also some function invocations which are not mapped to any
|
103 | 108 | keymappings by default, but could be. This is all shown in the following table.
|
104 | 109 |
|
105 | 110 | | Mode | Keymap | Purpose | Equivalent Lua Function |
|
106 |
| -| ------ | --------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | |
| 111 | +| ---------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | |
107 | 112 | | Normal | `g?p` | Insert a 'plain' debug line appropriate to the filetype just below the current line | `require('debugprint').debugprint()` |
|
108 | 113 | | Normal | `g?P` | The same, but above the current line | `require('debugprint').debugprint({above = true})` |
|
109 | 114 | | Normal | `g?v` | Insert a variable debugging line below the current line. If the cursor is on a variable name, use that, otherwise prompt for one. | `require('debugprint').debugprint({variable = true})` |
|
@@ -147,12 +152,13 @@ end)
|
147 | 152 |
|
148 | 153 | `debugprint` supports the following options in its global `opts` object:
|
149 | 154 |
|
150 |
| -| Option | Default | Purpose | |
151 |
| -| - | - | - | |
152 |
| -| `create_keymaps` | `true` | Creates default keymappings - see above | |
153 |
| -| `move_to_debugline` | `false` | When adding a debug line, moves the cursor to that line | |
154 |
| -| `filetypes` | See below | Custom filetypes - see below | |
155 |
| -| `ignore_treesitter` | `false` | Never use treesitter to find a variable under the cursor, always prompt for it - overrides the same setting on `debugprint()` if set to true | |
| 155 | +| Option | Default | Purpose | |
| 156 | +| ------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | |
| 157 | +| `create_keymaps` | `true` | Creates default keymappings - see above | |
| 158 | +| `move_to_debugline` | `false` | When adding a debug line, moves the cursor to that line | |
| 159 | +| `filetypes` | See below | Custom filetypes - see below | |
| 160 | +| `ignore_treesitter` | `false` | Never use treesitter to find a variable under the cursor, always prompt for it - overrides the same setting on `debugprint()` if set to true | |
| 161 | +| `print_tag` | `DEBUGPRINT` | The string inserted into each print statement, which can be used to uniquely identify statements inserted by `debugprint`. | |
156 | 162 |
|
157 | 163 | ## Add Custom Filetypes
|
158 | 164 |
|
@@ -215,8 +221,8 @@ configuration.
|
215 | 221 |
|
216 | 222 | The keys in the configuration are used like this:
|
217 | 223 |
|
218 |
| -| Type of debug line | Default keys | How debug line is constructed |
219 |
| -| - | - | - | |
| 224 | +| Type of debug line | Default keys | How debug line is constructed | |
| 225 | +| ------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------- | |
220 | 226 | | Plain debug line | `g?p`/`g?P` | `my_fileformat.left .. "auto-gen DEBUG string" .. my_fileformat.right` |
|
221 | 227 | | Variable debug line | `g?v`/`g?V`/`g?o`/`g?O` | `my_fileformat.left .. "auto-gen DEBUG string, variable=" .. my_file_format.mid_var .. variable .. my_fileformat.right_var` |
|
222 | 228 |
|
|
0 commit comments