@@ -3,85 +3,99 @@ local M = {}
33
44-- remove program code from lua cache, reload
55M .RELOAD = function (...)
6- return require (" plenary.reload" ).reload_module (... )
6+ return require (" plenary.reload" ).reload_module (... )
77end
88
99-- modified 'require'; use to flush entire program from top level for plugin development.
1010M .R = function (name )
11- M .RELOAD (name )
12- return require (name )
11+ M .RELOAD (name )
12+ return require (name )
1313end
1414
1515-- print tables contents
1616M .P = function (v )
17- print (vim .inspect (v ))
18- return v
17+ print (vim .inspect (v ))
18+ return v
1919end
2020
2121-- Log to the file debug.log in the plugin's data dir. File can be watched for easier debugging.
22- M .log = function (...)
23- local args = { ... }
24-
25- -- Canonical log dir
26- local data_path = vim .fn .stdpath (" data" ) .. " /treewalker"
27-
28- -- If no dir on fs, make it
29- if vim .fn .isdirectory (data_path ) == 0 then
30- vim .fn .mkdir (data_path , " p" )
31- end
32-
33- local log_file = io.open (data_path .. " /debug.log" , " a" )
34-
35- -- Guard against no log file by making one
36- if not log_file then
37- log_file = io.open (data_path .. " /debug.log" , " w+" )
38- end
39-
40- -- Swallow further errors
41- -- This is a utility for development, it should never cause issues
42- -- during real use.
43- if not log_file then return end
44-
45- -- Write each arg to disk
46- for _ , arg in ipairs (args ) do
47- if type (arg ) == " table" then
48- arg = vim .inspect (arg )
49- end
50-
51- log_file :write (tostring (arg ) .. " \n " )
52- end
22+ M .log_file = function (...)
23+ local args = { ... }
24+
25+ -- Canonical log dir
26+ local data_path = vim .fn .stdpath (" data" ) .. " /treewalker"
27+
28+ -- If no dir on fs, make it
29+ if vim .fn .isdirectory (data_path ) == 0 then
30+ vim .fn .mkdir (data_path , " p" )
31+ end
32+
33+ local log_file = io.open (data_path .. " /debug.log" , " a" )
34+
35+ -- Guard against no log file by making one
36+ if not log_file then
37+ log_file = io.open (data_path .. " /debug.log" , " w+" )
38+ end
39+
40+ -- Swallow further errors
41+ -- This is a utility for development, it should never cause issues
42+ -- during real use.
43+ if not log_file then
44+ return
45+ end
46+
47+ -- Write each arg to disk
48+ for _ , arg in ipairs (args ) do
49+ if type (arg ) == " table" then
50+ arg = vim .inspect (arg )
51+ end
52+
53+ log_file :write (tostring (arg ) .. " \n " )
54+ end
55+
56+ log_file :flush () -- Ensure the output is written immediately
57+ log_file :close ()
58+ end
5359
54- log_file :flush () -- Ensure the output is written immediately
55- log_file :close ()
60+ M .log = function (...)
61+ local args = { ... }
62+ for _ , arg in ipairs (args ) do
63+ if type (arg ) == " table" then
64+ arg = vim .inspect (arg )
65+ end
66+
67+ -- Use vim.api.nvim_echo to print without waiting for keypress
68+ vim .api .nvim_echo ({ { tostring (arg ) } }, true , {})
69+ end
5670end
5771
5872M .guid = function ()
59- local template = ' xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
60- return string.gsub (template , ' [xy]' , function (c )
61- local v = (c == ' x ' ) and math.random (0 , 0xf ) or math.random (8 , 0xb )
62- return string.format (' %x ' , v )
63- end )
73+ local template = " xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
74+ return string.gsub (template , " [xy]" , function (c )
75+ local v = (c == " x " ) and math.random (0 , 0xf ) or math.random (8 , 0xb )
76+ return string.format (" %x " , v )
77+ end )
6478end
6579
6680--- reverse an array table
6781--- @param t table
68- M .reverse = function (t )
69- local reversed = {}
70- for _ , el in ipairs (t ) do
71- table.insert (reversed , 1 , el )
72- end
73- return reversed
82+ M .reverse = function (t )
83+ local reversed = {}
84+ for _ , el in ipairs (t ) do
85+ table.insert (reversed , 1 , el )
86+ end
87+ return reversed
7488end
7589
7690--- Returns true if current buffer's filetype is markdown
7791--- @return boolean
7892M .is_markdown_file = function ()
79- local ft = (
80- vim .bo and vim .bo .ft
81- or (vim .api and vim .api .nvim_buf_get_option and vim .api .nvim_buf_get_option (0 , ' filetype' ))
82- or ' '
83- )
84- return ft == " markdown" or ft == " md"
93+ local ft = (
94+ vim .bo and vim .bo .ft
95+ or (vim .api and vim .api .nvim_buf_get_option and vim .api .nvim_buf_get_option (0 , " filetype" ))
96+ or " "
97+ )
98+ return ft == " markdown" or ft == " md"
8599end
86100
87101return M
0 commit comments