diff --git a/README.md b/README.md index 0e8c492..bc2019c 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,7 @@ In either case, the format is the same. For example, if adding via `setup()`: ```lua local my_fileformat = { left = 'print "', + left_var = 'print "', -- `left_var` is optional, for 'variable' lines only; `left` will be used if it's not present right = '"', mid_var = "${", right_var = '}"', @@ -274,10 +275,10 @@ configuration. The keys in the configuration are used like this: -| Debug line type | Default keys | How debug line is constructed | -| ------------------- | ----------------------- | --------------------------------------------------------------------------------------------------------------------------- | -| Plain debug line | `g?p`/`g?P` | `my_fileformat.left .. "auto-gen DEBUG string" .. my_fileformat.right` | -| 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` | +| Debug line type | Default keys | How debug line is constructed | +| ------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Plain debug line | `g?p`/`g?P` | `my_fileformat.left .. "auto-gen DEBUG string" .. my_fileformat.right` | +| Variable debug line | `g?v`/`g?V`/`g?o`/`g?O` | `my_fileformat.left_var (or my_fileformat.left) .. "auto-gen DEBUG string, variable=" .. my_file_format.mid_var .. variable .. my_fileformat.right_var` | If it helps to understand these, you can look at the built-in configurations in [filetypes.lua](lua/debugprint/filetypes.lua). diff --git a/lua/debugprint/filetypes.lua b/lua/debugprint/filetypes.lua index 2a80026..6ed38a9 100644 --- a/lua/debugprint/filetypes.lua +++ b/lua/debugprint/filetypes.lua @@ -145,7 +145,8 @@ return { }, -- Don't print to stderr by default, because it requires 'import sys' ["python"] = { - left = 'print(f"', + left = 'print("', + left_var = 'print(f"', right = '")', mid_var = "{", right_var = '}")', diff --git a/lua/debugprint/init.lua b/lua/debugprint/init.lua index 1d4e218..201d2e2 100644 --- a/lua/debugprint/init.lua +++ b/lua/debugprint/init.lua @@ -171,7 +171,15 @@ local addline = function(opts) local line_to_insert_linenr if opts.variable_name then - line_to_insert_content = fileconfig.left + local left + + if fileconfig["left_var"] ~= nil then + left = fileconfig["left_var"] + else + left = fileconfig["left"] + end + + line_to_insert_content = left .. debuginfo(opts) .. fileconfig.mid_var .. opts.variable_name diff --git a/tests/debugprint.lua b/tests/debugprint.lua index 2707a14..cb2a16c 100644 --- a/tests/debugprint.lua +++ b/tests/debugprint.lua @@ -1391,7 +1391,7 @@ describe("check python indenting", function() check_lines({ "x = 1", - 'print(f"DEBUGPRINT[1]: ' .. filename .. ':1 (after x = 1)")', + 'print("DEBUGPRINT[1]: ' .. filename .. ':1 (after x = 1)")', "y = 2", }) end) @@ -1406,7 +1406,7 @@ describe("check python indenting", function() check_lines({ "def xyz():", - ' print(f"DEBUGPRINT[1]: ' + ' print("DEBUGPRINT[1]: ' .. filename .. ':1 (after def xyz():)")', " pass", @@ -1418,14 +1418,31 @@ describe("check python indenting", function() "def xyz():", " x = 1", " y = 2", - }, "python", 2, 0) + }, "python", 2, 5) feedkeys("g?p") check_lines({ "def xyz():", " x = 1", - ' print(f"DEBUGPRINT[1]: ' .. filename .. ':2 (after x = 1)")', + ' print("DEBUGPRINT[1]: ' .. filename .. ':2 (after x = 1)")', + " y = 2", + }) + end) + + it("variable", function() + local filename = init_file({ + "def xyz():", + " x = 1", + " y = 2", + }, "python", 2, 4) + + feedkeys("g?v") + + check_lines({ + "def xyz():", + " x = 1", + ' print(f"DEBUGPRINT[1]: ' .. filename .. ':2: x={x}")', " y = 2", }) end)