@@ -251,32 +251,37 @@ M.marks = function(opts)
251251 if not opts then return end
252252
253253 local contents = function (cb )
254- local win = utils .CTX ().winid
255254 local buf = utils .CTX ().bufnr
256- win = vim .api .nvim_win_is_valid (win ) and win or 0
257- buf = vim .api .nvim_win_is_valid (buf ) and buf or 0
258- local marks = vim .api .nvim_win_call (win , function ()
259- return vim .api .nvim_buf_call (buf , function () return vim .fn .execute (" marks" ) end )
260- end )
261- marks = vim .split (marks , " \n " )
262255 local entries = {}
263- local pattern = opts .marks and opts .marks or " "
264- for i = # marks , 3 , - 1 do
265- local mark , line , col , text = marks [i ]:match (" (.)%s+(%d+)%s+(%d+)%s+(.*)" )
266- col = tostring (tonumber (col ) + 1 )
267- if path .is_absolute (text ) then
268- text = path .HOME_to_tilde (text )
269- end
270- if not pattern or string.match (mark , pattern ) then
271- table.insert (entries , string.format (" %s %s %s %s" ,
272- utils .ansi_codes [opts .hls .buf_nr ](string.format (" %4s" , mark )),
273- utils .ansi_codes [opts .hls .path_linenr ](string.format (" %4s" , tostring (line ))),
274- utils .ansi_codes [opts .hls .path_colnr ](string.format (" %3s" , tostring (col ))),
275- text ))
256+ local function add_mark (mark , line , col , text )
257+ if opts .marks and string.match (mark , opts .marks ) then return end
258+ table.insert (entries , string.format (" %s %s %s %s" ,
259+ utils .ansi_codes [opts .hls .buf_nr ](string.format (" %4s" , mark )),
260+ utils .ansi_codes [opts .hls .path_linenr ](string.format (" %4s" , tostring (line ))),
261+ utils .ansi_codes [opts .hls .path_colnr ](string.format (" %3s" , tostring (col ))),
262+ text ))
263+ end
264+
265+ -- local buffer marks
266+ for _ , m in ipairs (vim .fn .getmarklist (buf )) do
267+ local mark , lnum , col = m .mark :sub (2 , 2 ), m .pos [2 ], m .pos [3 ]
268+ local text = vim .api .nvim_buf_get_lines (buf , lnum - 1 , lnum , false )[1 ]
269+ add_mark (mark , lnum , col , utils .ansi_from_hl (" Directory" , text or " -invalid-" ))
270+ end
271+
272+ -- global marks
273+ for _ , m in ipairs (vim .fn .getmarklist ()) do
274+ local mark , lnum , col , file = m .mark :sub (2 , 2 ), m .pos [2 ], m .pos [3 ], m .file
275+ file = path .relative_to (file , uv .cwd ())
276+ if path .is_absolute (file ) then
277+ file = path .HOME_to_tilde (file )
276278 end
279+ add_mark (mark , lnum , col , file or " -invalid-" )
277280 end
278281
279- table.sort (entries , function (a , b ) return a < b end )
282+ if opts .sort then
283+ table.sort (entries , function (a , b ) return a < b end )
284+ end
280285 table.insert (entries , 1 ,
281286 string.format (" %-5s %s %s %s" , " mark" , " line" , " col" , " file/text" ))
282287
0 commit comments