@@ -144,7 +144,7 @@ M.debounce = function(id, fn, frequency_in_ms, strategy, action)
144144end
145145
146146--- Returns true if the contents of two tables are equal.
147- M .tbl_equals = function (table1 , table2 )
147+ M .tbl_equals = function (table1 , table2 )
148148 -- same object
149149 if table1 == table2 then
150150 return true
@@ -241,18 +241,33 @@ M.get_diagnostic_counts = function()
241241 return lookup
242242end
243243
244+ --- DEPRECATED: This will be removed in v3. Use `get_opened_buffers` instead.
244245--- Gets a lookup of all open buffers keyed by path with the modifed flag as the value
245- --- @return table
246+ --- @return table opened_buffers { [buffer_name] = bool }
246247M .get_modified_buffers = function ()
247- local modified_buffers = {}
248+ local opened_buffers = M .get_opened_buffers ()
249+ for bufname , bufinfo in pairs (opened_buffers ) do
250+ opened_buffers [bufname ] = bufinfo .modified
251+ end
252+ return opened_buffers
253+ end
254+
255+ --- Gets a lookup of all open buffers keyed by path with additional information
256+ --- @return table opened_buffers { [buffer_name] = { modified = bool } }
257+ M .get_opened_buffers = function ()
258+ local opened_buffers = {}
248259 for _ , buffer in ipairs (vim .api .nvim_list_bufs ()) do
249- local buffer_name = vim .api .nvim_buf_get_name (buffer )
250- if buffer_name == nil or buffer_name == " " then
251- buffer_name = " [No Name]#" .. buffer
260+ if vim .api .nvim_buf_is_loaded (buffer ) and vim .fn .buflisted (buffer ) then
261+ local buffer_name = vim .api .nvim_buf_get_name (buffer )
262+ if buffer_name == nil or buffer_name == " " then
263+ buffer_name = " [No Name]#" .. buffer
264+ end
265+ opened_buffers [buffer_name ] = {
266+ [" modified" ] = vim .api .nvim_buf_get_option (buffer , " modified" ),
267+ }
252268 end
253- modified_buffers [buffer_name ] = vim .api .nvim_buf_get_option (buffer , " modified" )
254269 end
255- return modified_buffers
270+ return opened_buffers
256271end
257272
258273--- Resolves some variable to a string. The object can be either a string or a
0 commit comments