Skip to content

Commit 9716266

Browse files
author
Andrew Ferrier
committed
feat: Introduce 'print_tag' - closes #4, #15
1 parent 30a9fb4 commit 9716266

File tree

3 files changed

+75
-68
lines changed

3 files changed

+75
-68
lines changed

README.md

+24-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
# debugprint.nvim
22

3-
## Purpose
3+
## Overview
44

55
The gold standard for debugging a program or script is to use a real debugger.
66
For NeoVim, the 'standard' way to integrate this is to use something like
77
[nvim-dap](https://github.com/mfussenegger/nvim-dap). However, many folks prefer
88
a more low-tech approach; the 'print' statement, or the equivalent in a
99
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.
1823

1924
`debugprint` is inspired by
2025
[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
103108
keymappings by default, but could be. This is all shown in the following table.
104109

105110
| Mode | Keymap | Purpose | Equivalent Lua Function |
106-
| ------ | --------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
111+
| ---------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
107112
| Normal | `g?p` | Insert a 'plain' debug line appropriate to the filetype just below the current line | `require('debugprint').debugprint()` |
108113
| Normal | `g?P` | The same, but above the current line | `require('debugprint').debugprint({above = true})` |
109114
| 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)
147152

148153
`debugprint` supports the following options in its global `opts` object:
149154

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`. |
156162

157163
## Add Custom Filetypes
158164

@@ -215,8 +221,8 @@ configuration.
215221

216222
The keys in the configuration are used like this:
217223

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+
| ------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------- |
220226
| Plain debug line | `g?p`/`g?P` | `my_fileformat.left .. "auto-gen DEBUG string" .. my_fileformat.right` |
221227
| 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` |
222228

lua/debugprint/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GLOBAL_OPTION_DEFAULTS = {
99
move_to_debugline = false,
1010
ignore_treesitter = false,
1111
filetypes = require("debugprint.filetypes"),
12+
print_tag = 'DEBUGPRINT'
1213
}
1314

1415
FUNCTION_OPTION_DEFAULTS = {
@@ -23,7 +24,7 @@ local debuginfo = function(variable_name)
2324
local current_line = vim.api.nvim_win_get_cursor(0)[1]
2425
counter = counter + 1
2526

26-
local line = "DEBUG["
27+
local line = global_opts.print_tag .. "["
2728
.. counter
2829
.. "]: "
2930
.. vim.fn.expand("%:t")

0 commit comments

Comments
 (0)