lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.58k stars 393 forks source link

fold text in bib files? #2065

Closed yongrenjie closed 3 years ago

yongrenjie commented 3 years ago

Is your feature request related to a problem? Please describe it.

Setting foldmethod=syntax in bib files (provided by vim8.2's built in syntax file) gives nice folding, but the default fold text is a bit dull. For example (stealing a paper from my supervisor :-))

@article{Foroozandeh2014ACIE,
    doi = {10.1002/anie.201404111},
    author = {Foroozandeh, Mohammadali and Adams, Ralph W. and Meharry, Nicola J. and Jeannerat, Damien and Nilsson, Mathias and Morris, Gareth A.},
    title = {Ultrahigh-Resolution NMR Spectroscopy},
    journaltitle = {Angew.\ Chem.\ Int.\ Ed.},
    year = {2014},
    volume = {53},
    number = {27},
    pages = {6990--6992},
}

produces the following foldtext

+-- 10 lines: @article{Foroozandeh2014ACIE,-----------------------------------------------

IMO, it's not useful to know how many lines an entry is; also, the remainder of the space could be more usefully utilised to show some information about the bib entry.

Describe the solution you'd like

For most bib entries I think the most useful piece of extra information would be the title (?) or for @set{...}, it would be useful to see which entries are contained within the set.

I actually have an implementation of the foldtext function here: https://github.com/yongrenjie/abbotsbury.vim/blob/master/ftplugin/bib.vim which I use personally. For the same bib entry above it produces the following foldtext:

+-- article{Foroozandeh2014ACIE} -- Ultrahigh-Resolution NMR Spectroscopy ----------------

Describe alternatives you've considered

I mainly opened this issue as I was curious as to whether this would be something you might be interested in including in vimtex. I'm happy to modify the output slightly if desired!

The main alternative would be sticking with the default, I guess. There might be an argument that long fold texts lead to visual clutter.

lervag commented 3 years ago

I mainly opened this issue as I was curious as to whether this would be something you might be interested in including in vimtex. I'm happy to modify the output slightly if desired!

I don't quite see why not to add this. I think improving the fold text for bib files should generally be a good thing for most people, and it seems relevant to VimTeX. If it would be opinionated, then we could easily make it optional.

Do you want to open a PR for this? I could add this based on your implementation myself, but if you feel adventurous and want to keep your name on the contribution, then I wouldn't mind helping you with a PR.

yongrenjie commented 3 years ago

I don't mind trying to put a PR together! Before I start, let me consult you about the strategy...

https://github.com/lervag/vimtex/blob/fef77c8edf655d947e4d9c78d7bd2740ccda70cd/autoload/vimtex/fold.vim#L7-L15

lervag commented 3 years ago

I don't mind trying to put a PR together! Before I start, let me consult you about the strategy...

Ah, yes, I can see how it is somewhat confusing how to integrate this in the current init flow. The code did not really consider bib files, so bib file support is sort of "hackish".

My suggestion would be to make it simple, something like this:

  1. Add minimal init code here:

    https://github.com/lervag/vimtex/blob/fef77c8edf655d947e4d9c78d7bd2740ccda70cd/autoload/vimtex.vim#L84-L92

    Something like this:

    if g:vimtex_fold_bib_enabled
      setlocal foldmethod=syntax
      setlocal foldtext=vimtex#fold#bib#text()
    endif
  2. Add the bibtex foldtext function as vimtex#fold#bib#text() in autoload/vimtex/fold/bib.vim.

  3. Add some related words in the docs (under :help vimtex-folding and document the option).

This would keep the main new code separated from other unrelated code, which I think is good. Then I might do some code maintenance and restructuring afterwards.

Does this make sense to you?

yongrenjie commented 3 years ago

Closed by #2066!

lervag commented 3 years ago

I forgot about this issue; thanks for remembering and closing it! :)