how to check whether the location list for the current window is open
You could try to inspect the 'winid'
property of the location list. If the location window is open, the value of the property should be different than zero:
if get(getloclist(0, {'winid':0}), 'winid', 0)
" the location window is open
...
else
" the location window is closed
...
endif
once a location list window is found, how can I know which window it is associated with?
You could try to inspect the 'filewinid'
property of the location list:
echo get(getloclist(0, {'filewinid':0}), 'filewinid', 0)
This requires the Vim patch 8.1.0345.
If your Vim version doesn't include this patch, or if you use Neovim which doesn't implement this property at the moment, you could try this code instead:
fu! Get_associated_window() abort
let win_ids = get(gettabinfo(tabpagenr())[0], 'windows', {})
let loc_id = win_getid()
return get(filter(win_ids, {i,v -> get(getloclist(v, {'winid': 0}), 'winid', 0) ==# loc_id && v !=# loc_id }) , 0, 0)
endfu
echo Get_associated_window()
For more information, see:
:h getloclist()
:h getqflist()