Location list entries for unsaved buffer open a new buffer

28 views
Skip to first unread message

Lifepillar

unread,
Oct 21, 2023, 10:09:26 AM10/21/23
to vim...@googlegroups.com
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?

Thanks,
Life.

Yegappan Lakshmanan

unread,
Oct 21, 2023, 10:50:36 AM10/21/23
to vim...@googlegroups.com
Hi,

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

Lifepillar

unread,
Oct 21, 2023, 1:09:04 PM10/21/23
to vim...@googlegroups.com
:-) 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.

Christian Castro

unread,
Oct 23, 2023, 1:53:56 PM10/23/23
to vim...@googlegroups.com
Hello vim_use Group,


I recently upgraded VIM 8.0 to the new 9.0 version that was out at that time for Windows.
I want to know where VIM stores the path for the _vimrc file.

See I'm not sure which copy of the _vimrc file the VIM program is using.
I've looked at the C:\Program Files(x86)\Vim\_vimrc file and that's not it.
The program kept the user customization so it must be using a _vimrc file from somewhere. But where?

Is there a config file in Vim that tells me path it's looking for when it goes to find the _vimrc file?
Please assist.


Thanks
--
--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/uh10ir%24u9l%241%40ciao.gmane.io.

****WARNING**** This email message (including any attachments) are to be treated as confidential/proprietary and may contain copyrighted or other legally protected information. It is intended only for the addressee(s) identified above. If you are not the addressee(s), or an employee or agent of the addressee(s), please note that any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this information in error, please destroy the information and notify the sender of the error. Thank you.

Eike Rathke

unread,
Oct 23, 2023, 7:44:05 PM10/23/23
to vim...@googlegroups.com
Hi,

On Monday, 2023-10-23 17:30:45 +0000, Christian Castro wrote:

> Is there a config file in Vim that tells me path it's looking for when it goes to find the _vimrc file?

:h startup
:version

To display where an option was last defined, e.g. viminfo, use
:verbose set viminfo

:h :verbose-cmd

Eike

--
OpenPGP/GnuPG encrypted mail preferred in all private communication.
GPG key 0x6A6CD5B765632D3A - 2265 D7F3 A7B0 95CC 3918 630B 6A6C D5B7 6563 2D3A
Use LibreOffice! https://www.libreoffice.org/
signature.asc

Tony Mechelynck

unread,
Oct 24, 2023, 12:49:56 AM10/24/23
to Christian Castro, vim...@googlegroups.com
On Mon, Oct 23, 2023 at 7:53 PM Christian Castro
<christia...@dlhcorp.com> wrote:
>
> Hello vim_use Group,
>
>
> I recently upgraded VIM 8.0 to the new 9.0 version that was out at that time for Windows.
> I want to know where VIM stores the path for the _vimrc file.
>
> See I'm not sure which copy of the _vimrc file the VIM program is using.
> I've looked at the C:\Program Files(x86)\Vim\_vimrc file and that's not it.
> The program kept the user customization so it must be using a _vimrc file from somewhere. But where?
>
> Is there a config file in Vim that tells me path it's looking for when it goes to find the _vimrc file?
> Please assist.
>
>
> Thanks

In any Vim version, the :scriptnames command will tell you the
pathfilenames of all the Vim scripts actually sourced in this instance
of Vim since it started. The vimrc should be at (or very near) the top
of the list, unless either it was not found, or it was disabled by
means of -u NONE on the command-line.

Also, in the middle part of the :version command, the config files
(vimrc etc.) which were defined at compile-time are listed, but they
can be suppressed, or other files can be used instead, by means of
command-line parameters.

Best regards,
Tony.

Yegappan Lakshmanan

unread,
Oct 25, 2023, 12:33:37 AM10/25/23
to vim...@googlegroups.com
On Sat, Oct 21, 2023 at 10:08 AM Lifepillar <lifep...@lifepillar.me> wrote:
On 2023-10-21, Yegappan Lakshmanan <yega...@gmail.com> wrote:
> On Sat, Oct 21, 2023 at 7:09 AM Lifepillar <lifep...@lifepillar.me> 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
Reply all
Reply to author
Forward
0 new messages