Guest User

Untitled

a guest
Dec 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. " Cache a possibly filled location list for a hiding buffer.
  2. " Check if there is a non-empty list for the current buffer.
  3. " Stores the list to the cache and empty the original one.
  4. " The location window will be closed.
  5. "
  6. " Arguments:
  7. " buffer - buffer to create the cache for
  8. "
  9. function! utils#location#cache_location_list(buffer) abort
  10. if get(g:, 'dynamic_location_list_disable', v:false) | return | endif
  11.  
  12. let l:location_list = getloclist(0)
  13.  
  14. " Check if something exist to cache.
  15. if len(l:location_list) > 0
  16. let s:map_buffer_location_list[a:buffer] = l:location_list " Cache the location list for the buffer.
  17. call setloclist(0, []) " Remove since else it remains for the next buffer.
  18. lclose " Close the empty window (will be possibly reopened on restore for new buffer).
  19. endif
  20. endfunction
  21.  
  22.  
  23. " Restore a possibly cached location list for a new displayed buffer.
  24. " Check the cache if a location list has been stored for the buffer.
  25. " If so it fills the list with the stored one and opens the window.
  26. " The cache entry will be removed.
  27. "
  28. " Arguments:
  29. " buffer - buffer to restore the cache for
  30. "
  31. function! utils#location#restore_location_list(buffer) abort
  32. if get(g:, 'dynamic_location_list_disable', v:false) | return | endif
  33.  
  34. " Check cache for the entered buffer.
  35. if has_key(s:map_buffer_location_list, a:buffer)
  36. call setloclist(0, s:map_buffer_location_list[a:buffer]) " Restore the location list from cache.
  37. unlet s:map_buffer_location_list[a:buffer] " Remove cache to avoid reloading.
  38. lopen " Open the filled window.
  39. wincmd p " Jump back from location list to actual window.
  40. endif
  41. endfunction
Add Comment
Please, Sign In to add comment