kristijanhusak / vim-dadbod-ui

Simple UI for https://github.com/tpope/vim-dadbod
MIT License
1.54k stars 94 forks source link

Add more flexible way to format saved buffer filenames #94

Closed przepompownia closed 3 years ago

przepompownia commented 3 years ago

With #80 we have saved buffer filenames with human readable date inside.

After some months of working with this plugin I figured I needed another filename format.

We would provide user callback to change the default behavior, e.g.

 let g:Db_ui_tmp_query_filename_formatter = {basename, buffer_name, time -> printf('%s.%s-%s.sql', basename, time, buffer_name)}

I have made some experiment with this substitution but I noticed a side effect. The buffer need to have the database name after basename to be correctly displayed in Buffers section. Maybe basename and database should not appear in such callback.

What do you think about adding such flexibility?

kristijanhusak commented 3 years ago

I guess we could add that. I just need a database name at the beginning of the buffer name so I can figure out on which connection it belongs. Everything else after it can be dynamic.

przepompownia commented 3 years ago

I did not want to do this division myself because these parts are used in other cases.

Btw. this part https://github.com/kristijanhusak/vim-dadbod-ui/blob/master/autoload/db_ui/query.vim#L63-L65 has no chance to occur because of earlier return in the same case.

kristijanhusak commented 3 years ago

I added an ability to provide custom generator for name. See this section in documentation: https://github.com/kristijanhusak/vim-dadbod-ui/blob/master/doc/dadbod-ui.txt#L655

I would appreciate if you would give it a try and let me know how it works.

przepompownia commented 3 years ago

With a test generator

function s:bufferNameGenerator(opts) abort
  let l:time = strftime('%Y-%m-%d %T')

  return printf('%s .sql', l:time)
endfunction

let g:Db_ui_buffer_name_generator = function('s:bufferNameGenerator')

I got db_ui.dev2021-04-06 23:24:19 .sql (as expected, thanks!). Its item on the drawer is displayed as sql: image After quit from Vim and reopen DBUI those newly saved buffers does not appear on Buffers list.

przepompownia commented 3 years ago

We would get additional advantage from opts. It probably could transfer the filetype specific to given database to avoid hardcoding it in the return value (like .sql in the example above).

kristijanhusak commented 3 years ago

I did some additional updates to this. Before I was generating tmp file names with a long extension that held the information and date time. Now i'm generating real file names. This will allow adding custom extension like you just tried to do. It should be backward compatible with old structure in case someone is using custom tmp query location. Please pull and give it a try.

przepompownia commented 3 years ago

I see the result on buffers list without need to provide the leading separator :tada: Thanks! I can make the new issue for filetype name transfer through opts.

kristijanhusak commented 3 years ago

I included filetype into the opts now, so you have it available if you need.

przepompownia commented 3 years ago

Thanks again! It works without any problem.