Browse Source

Add support for per-tab IDs.

This provides a way to track the identity of a tab as tabs are created
and deleted (which can cause tab numbers to change).
Michael Henry 10 months ago
parent
commit
50635f3cc4
1 changed files with 19 additions and 0 deletions
  1. 19 0
      plugin/bufexplorer.vim

+ 19 - 0
plugin/bufexplorer.vim

@@ -185,6 +185,25 @@ function! s:CatalogBuffers()
     silent execute 'normal! ' . ct . 'gt'
 endfunction
 
+" AssignTabId {{{2
+" Assign a `tabId` to the given tab.
+function! s:AssignTabId(tabNbr)
+    " Create a unique `tabId` based on the current time and an incrementing
+    " counter value that helps ensure uniqueness.
+    let tabId = reltimestr(reltime()) . ':' . s:tabIdCounter
+    call settabvar(a:tabNbr, 'bufexp_tabId', tabId)
+    let s:tabIdCounter = (s:tabIdCounter + 1) % 1000000000
+    return tabId
+endfunction
+
+let s:tabIdCounter = 0
+
+" GetTabId {{{2
+" Retrieve the `tabId` for the given tab (or '' if the tab has no `tabId`).
+function! s:GetTabId(tabNbr)
+    return gettabvar(a:tabNbr, 'bufexp_tabId', '')
+endfunction
+
 " AssociatedTab {{{2
 " Return the number of the tab associated with the specified buffer. If the
 " buffer is associated with more than one tab, the first one found is