mihaifm/bufstop

Add getter functions that returns info table for all lines or current line selected in Bufstop/BufstopPreview window

Closed this issue · 2 comments

  1. getter function that returns information table for current line selected in Bufstop/BufstopPreview window: This will enable so many things inside and outside vim, that sky is the limit! The return value will be a key:value table that has keys like filename, full path, buffer number. This can inturn be used by user to their liking to apply their own custom key bindings to do things they want to with this information.

This will enable doing the following outside Vim:
For instance, if filetype is html, it could be a keybinding that calls a function that opens the file in web browser. If the file type is a certain json, one could run a build with with the config it represents.

And it will enable doing things inside Vim:
Swapping buffer windows, rearranging window, etc Users can easily write such functions.

  1. getter function that returns an array of tables for all lines in Bufstop/BufstopPreview window, with a way to access the position of current line. This will enable batch processing, and users can write useful functions to iterate over the buffers in the list and do tasks to their liking.

Why is this better than doing something like bufdo? Because user need not loose focus from the Bufstop window while executing all these niceties.

Sounds reasonable to do. I think the variables are already there but they're not global.

Hi, I finally managed to implement this.

e373ef7

It "only" took 6 months to change the name of a variable, as the data was already there.

The global variable g:BufstopData contains all the relevant buffer information. To get the current line number, you can use the vim line() function. This displays the buffer information for the current line:

 echo g:BufstopData[line('.')-1]

Based on your suggestion, here's how you can open html files in a browser (on Windows):

 :if g:BufstopData[line('.')-1].ext == 'html' | exe '!start explorer ' . g:BufstopData[line('.')-1].path | endif

It's quite a powerful use case, thanks for suggesting it.

Cheers