Re: Location list entries for unsaved buffer open a new buffer
On Sat, Oct 21, 2023 at 10:08 AM Lifepillar wrote: > On 2023-10-21, Yegappan Lakshmanan wrote: > > On Sat, Oct 21, 2023 at 7:09 AM Lifepillar > wrote: > >> How do I generate location list entries that refer to the proper unsaved > >> buffer? > >> > >> > > There is a item in the todo list for more than 20 years now for this: > > > > - Add %b to 'errorformat': buffer number. (Yegappan Lakshmanan / Suresh > > Govindachar) > > :-) I have found the following workaround: I pass the buffer number to > I have created the PR https://github.com/vim/vim/pull/13419 to support this. Can you try out the diff in the PR and let me know if you see any issues? - Yegappan > the callback, then I iterate over each parsed line and manually set the > buffer: > > def Callback(channel: channel, msg: string, bufnr: number, ...) > [...] > var what = getqflist({"lines": [msg], "efm": efm}) > > for item in what.items > item["bufnr"] = bufnr > endfor > > setloclist(winid, what.items, "a") > enddef > > Life. > > > -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAAW7x7kU69qOtyy_UYWk_iKeH9pEXfAEPAir7Jf0E8FLyb4wFw%40mail.gmail.com.
Re: Location list entries for unsaved buffer open a new buffer
On 2023-10-21, Yegappan Lakshmanan wrote: > On Sat, Oct 21, 2023 at 7:09 AM Lifepillar wrote: >> How do I generate location list entries that refer to the proper unsaved >> buffer? >> >> > There is a item in the todo list for more than 20 years now for this: > > - Add %b to 'errorformat': buffer number. (Yegappan Lakshmanan / Suresh > Govindachar) :-) I have found the following workaround: I pass the buffer number to the callback, then I iterate over each parsed line and manually set the buffer: def Callback(channel: channel, msg: string, bufnr: number, ...) [...] var what = getqflist({"lines": [msg], "efm": efm}) for item in what.items item["bufnr"] = bufnr endfor setloclist(winid, what.items, "a") enddef Life. -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/uh10ir%24u9l%241%40ciao.gmane.io.
Re: Location list entries for unsaved buffer open a new buffer
Hi, On Sat, Oct 21, 2023 at 7:09 AM Lifepillar wrote: > I have a function that pipes a buffer into an external program, then > parses its output in a callback and adds the parsed results to > a location list. Simplified code for the callback: > > def Callback(channel: job, msg: string, winid: number, efm: string, > cwd: string) > silent execute "lcd" cwd > var what = getqflist({"lines": [msg], "efm": efm}) > silent lcd - > setloclist(winid, what.items, "a") > enddef > > The lines to be parsed have a pretty standard format: > > filename:line:col message > > The program reads from stdin, hence `filename` is passed as an argument > to the program. The program simply puts whatever filename it gets into > its output messages. > > This works fine for buffers backed up by a file: I pass the buffer's > name as the filename argument. My problem is that I don't know how to > create an entry in the location list for an unsaved buffer. Passing > something like '[No Name]', 'unnamed', or similar does not work. The > location list ends up having entries that look like this: > > unnamed|1 col 8 E123| some message > > If the unsaved buffer ia buffer 1, then the message above is parsed as: > > {'items': [{'bufnr': 2, 'lnum': 1, 'col': 8, 'text': 'some message', > ...}]} > > Therefore, selecting such entries causes a new buffer 2 to be created. > > How do I generate location list entries that refer to the proper unsaved > buffer? > > There is a item in the todo list for more than 20 years now for this: - Add %b to 'errorformat': buffer number. (Yegappan Lakshmanan / Suresh Govindachar) - Yegappan -- -- You received this message from the "vim_use" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_use" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAAW7x7nVk9-jZ1f%2B-9hKuHUyBmvNLm56FG4-e02vuxHamvXX0g%40mail.gmail.com.