preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.09k stars 484 forks source link

Error on configuration of g:tagbar_type_bib #856

Closed andregpss closed 9 months ago

andregpss commented 11 months ago

I think there is an error on the suggested configuration for Bibtex files on the Wiki page.

The ctagstype variable must be set to bibtex, instead of bib. When i use bib, it does not work.

By the way, Misc references are not shown on Tagbar, although other types of references (Article, Books, etc) work.

raven42 commented 11 months ago

It looks like the Wiki page entry is for a custom defined version for bibtex with a custom regex parser for bibtex files. Do you if universal-ctags has native support for bibtex now? Or do we still need to have the regex pattern definition?

Another part of this might be that we have to let vim know the correct file type. If vim has been updated since that wiki entry to know about bibtex files, then that could be the cause too. I.E. in a previous version vim may have just recognized the file extension and used that as the filetype, but now it may know the language and correctly label the filetype as bibtex.

Either way, ya it looks like the wiki page is out of date. If you can provide me with a sample bibtex file I can do some testing and look at updating it.

andregpss commented 11 months ago

Thanks for answering.

Do you if universal-ctags has native support for bibtex now? Or do we still need to have the regex pattern definition?

Universal-ctags has native support for bibtex (ctags.exe --list-languages). When I type ctags.exe references.bib on prompt, a tags file is created, containing tags for the references, including misc reference type.

If vim has been updated since that wiki entry to know about bibtex files, then that could be the cause too.

I'm using NeoVim 0.9.1. There may be a difference between using Vim and NeoVim.

If you can provide me with a sample bibtex file I can do some testing and look at updating it.

Here's a sample of reference.bib Bibtex file:

@inproceedings{emmerich2000software, title={Software engineering and middleware: a roadmap}, author={Emmerich, Wolfgang}, booktitle={Proceedings of the Conference on The future of Software engineering}, pages={117--129}, year={2000}, organization={ACM} }

@misc{schmidt1996pattern, title={Pattern-Oriented Software Architecture, Volume 1: A System of Patterns}, author={Schmidt, D and Stal, M and Rohnert, H and Buschmann, F}, year={1996}, publisher={John Wiley \& Sons} }

@inproceedings{trilla2015improving, title={Improving implicit parallelism}, author={Trilla, Jos{\'e} Manuel Calder{\'o}n and Runciman, Colin}, booktitle={Proceedings of the 8th ACM SIGPLAN Symposium on Haskell}, pages={153--164}, year={2015}, organization={ACM} }

@inproceedings{marlow2009runtime, title={Runtime support for multicore Haskell}, author={Marlow, Simon and Peyton Jones, Simon and Singh, Satnam}, booktitle={ACM Sigplan Notices}, volume={44}, number={9}, pages={65--78}, year={2009}, organization={ACM} } @inproceedings{hickey2008clojure, title={The clojure programming language}, author={Hickey, Rich}, booktitle={Proceedings of the 2008 symposium on Dynamic languages}, pages={1}, year={2008}, organization={ACM} } @book{jones2003haskell, title={Haskell 98 language and libraries: the revised report}, author={Jones, Simon Peyton}, year={2003}, publisher={Cambridge University Press} }

@online{currying, author = {HaskellWiki}, title = {Currying}, year = {2006}, url = {https://wiki.haskell.org/Currying}, urldate = {2016-02-29}, note = {Disponível em \url{https://wiki.haskell.org/Currying}. }, howpublished = {Acesso em 2016-02-29.} }

@misc{merrick2006xml, title={XML remote procedure call (XML-RPC)}, author={Merrick, Phillip and Allen, Stewart and Lapp, Joseph}, year={2006}, month=apr # "~11", publisher={Google Patents}, note={US Patent 7,028,312} } @misc{morley2014json, title={JSON-RPC 2.0 Specification}, author={Morley, Matt}, year={2014}, publisher={JSON-RPC} }

@book{vanbrabant2008google, title={Google Guice: agile lightweight dependency injection framework}, author={Vanbrabant, Robbie}, year={2008}, publisher={Apress} }

@article{appeltauer2011contextj, title={ContextJ: Context-oriented programming with Java}, author={Appeltauer, Malte and Hirschfeld, Robert and Haupt, Michael and Masuhara, Hidehiko}, journal={Information and Media Technologies}, volume={6}, number={2}, pages={399--419}, year={2011}, publisher={Information and Media Technologies Editorial Board} }

@book{siriwardena2013enterprise, title={Enterprise Integration with Wso2 Esb}, author={Siriwardena, Prabath}, year={2013}, publisher={Packt Publishing Ltd} }

raven42 commented 11 months ago

@andregpss I've created a PR that adds native bibtex support. Can you help me identify which ones need the fold and stl (scope) fields set? Currently the PR has all kinds marked with a 0 for both, but that probably isn't accurate.

andregpss commented 11 months ago

@andregpss I've created a PR that adds native bibtex support. Can you help me identify which ones need the fold and stl (scope) fields set? Currently the PR has all kinds marked with a 0 for both, but that probably isn't accurate.

My opinion is that all kinds should be marked with 1 for both. Something like:

let g:tagbar_type_bib = {
    \ 'ctagstype' : 'bib',
    \ 'kinds'     : [
        \ 'a:Articles:1:1',
        \ 'b:Books:1:1',
        \ 'L:Booklets:1:1',
        \ 'c:Conferences:1:1',
        \ 'B:Inbook:1:1',
        \ 'C:Incollection:1:1',
        \ 'P:Inproceedings:1:1',
        \ 'm:Manuals:1:1',
        \ 'T:Masterstheses:1:1',
        \ 'M:Misc:1:1',
        \ 't:Phdtheses:1:1',
        \ 'p:Proceedings:1:1',
        \ 'r:Techreports:1:1',
        \ 'u:Unpublished:1:1',
    \ ]
\ }
raven42 commented 10 months ago

As near as I can tell, there are not child tags under any of these. Is the format of bibtex such that all these tag kinds are at 'global' scope for lack of a better description? Or can there be nested tags? In the example file, it looks like all the tag kinds are at the global scope level and there are no tag kinds for anything inside of those definitions from what I can see.

andregpss commented 10 months ago

There are no nested tags. References are listed without dependencies between them. Bibtex is a simple list of references. Documentation is here

andregpss commented 10 months ago

It is also essential to consider the types introduced by additional packages commonly used on Latex docs.

The main packages are biblatex and natbib.

So, here goes a complete type declaration for Taglib i have created: gtagbar_type_bib.txt .

raven42 commented 10 months ago

I'm hesitant to add kinds that aren't officially supported by ctags. Currently it looks BibTeX is the only bib... language supported by the latest universal-ctags, and the only kinds are the ones I listed. I just pulled the latest universal-ctags and rebuilt from scratch to be sure.

If support is needed for something that universal-ctags does not support itself, then a custom configuration would be needed. For these additional packages you are referencing, do they have a plugin for universal-ctags to add the additional kinds? Without that, even if we defined the extra kinds in our definition, we'd never see them if ctags can't output them.

$ ctags --version
Universal Ctags 6.0.0(p6.0.20230813.0), Copyright (C) 2015-2022 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Aug 15 2023, 14:09:49
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +wildcards, +regex, +gnulib_regex, +iconv, +option-directory, +xpath, +packcc, +optscript, +pcre2
$ ctags --list-languages | grep -i bib
BibTeX
$ ctags --list-kinds=bibtex
a  article
b  book
B  booklet
c  conference
i  inbook
I  incollection
j  inproceedings
m  manual
M  mastersthesis
n  misc
p  phdthesis
P  proceedings
s  string
t  techreport
u  unpublished
$

For now I'll plan to merge in the changes I have pushed up already, and we can always add more later if needed and ctags support is there.

andregpss commented 10 months ago

For these additional packages you are referencing, do they have a plugin for universal-ctags to add the additional kinds? Without that, even if we defined the extra kinds in our definition, we'd never see them if ctags can't output them.

I don't know if there is a plugin for u-Ctags to add Bibtex additional kings. I search for it but not find it.

For now I'll plan to merge in the changes I have pushed up already, and we can always add more later if needed and ctags support is there.

When will this merge be available? Thanks.

raven42 commented 10 months ago

It should be merged into the master branch already. I merged it in yesterday.

andregpss commented 10 months ago

Ok. Plug update command update it.

Now Tagbar show misc type. Thank you!

But it is a pity that additional and very popular types such as online are not shown.

raven42 commented 10 months ago

If you want to open an issue on the universal-ctags github for additional support you can try that. Then if that is supported from the ctags side, we can add support here.

andregpss commented 9 months ago

universal-ctags now supports biblatex types. I have oppened an issue, and they did it. Can you please provide that support on Tagbar? One main example is the support for @online reference. Please note the sequence below:

cat .\references.bib @online{WinNT, author = {MultiMedia LLC}, title = {{MS Windows NT} Kernel Description}, year = 1999, url = {http://web.archive.org/web/20080207010024/http://www.808multimedia.com/winnt/kernel.htm}, urldate = {2010-09-30} }

https://github.com/Article{autili2012developing, title={Developing highly complex distributed systems: a software engineering perspective}, author={Autili, Marco and Inverardi, Paola and Pelliccione, Patrizio and Tivoli, Massimo}, journal={Journal of Internet Services and Applications}, volume={3}, number={1}, pages={15--22}, year={2012}, publisher={Springer} }

@online{Network.Remote.RPC, author = {Matthew Mirman}, title = {rpc-framework: a remote procedure call framework}, year = {2012}, url = {https://hackage.haskell.org/package/rpc-framework-2.0.0.2}, urldate = {2016-02-29}, note = {Disponível em \url{https://hackage.haskell.org/package/rpc-framework-2.0.0.2}. }, howpublished = {Acesso em 2016-02-29.} }

ctags --version Universal Ctags 6.0.0(https://github.com/universal-ctags/ctags/commit/dedfed1a22ab542be257fd14362fcc919d4140dc), Copyright (C) 2015-2022 Universal Ctags Team Universal Ctags is derived from Exuberant Ctags. Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert Compiled: Sep 20 2023, 01:55:08 URL: https://ctags.io/ Output version: 0.0 Optional compiled features: +win32, +wildcards, +regex, +

ctags --options=NONE -o - .\references.bib ctags.exe: Notice: No options will be read from files or environment Network.Remote.RPC ./references.bib /^@online{Network.Remote.RPC,$/;" V WinNT ./references.bib /^@online{WinNT,$/;" V autili2012developing ./references.bib /^https://github.com/Article{autili2012developing,$/;" a

raven42 commented 9 months ago

@andregpss I merged in the support for this. Note however, that vim does not have a recognized file extension type for biblatex files so a custom definition is needed. I've updated the doc page in the *tagbar-extend* block, and updated the Wiki page with a new entry for biblatex (https://github.com/preservim/tagbar/wiki#biblatex).

With this change, the online references are showing up in tagbar for the sample file you provided.

image

andregpss commented 9 months ago

@raven42 Universal-CTags developer asked me to show you this message about BibLatex support. Thanks.

raven42 commented 9 months ago

Thanks @andregpss let me know if pulled the latest and if you got it working with my merged code. If you have any issues, let me know.

andregpss commented 9 months ago

@raven42 I have updated Tagbar by executing :PlugUpdate. Now I have the following screen. The article reference is not listed on Tagbar. I have noticed that all Bibtex standard types references are not shown, e.g., article, inproceedings, etc.

image

raven42 commented 9 months ago

This is intentional. The universal-ctags implementation was done by defining a new tag kind of biblatex that is independent and incompatible with bibtex. Take for example the 'B' kind. In the bor.al bibtex definition, this is defined as 'Inbook', but in the biblatex definition, it is 'Audio' From the tagbar perspective, we have to have only a single language definition, especially if we have overlapping kinds like this. I'm not sure how we would merge the two effectively and accurately given yhe way it was implemented in universal-ctags.

andregpss commented 9 months ago

Biblatex adds new types to Bibtex. Biblatex support should include the Bibtex standard types. According to your message, how universal tags implement Biblatexdoes not make sense. It is better to Tagbarsupport Bibtexthan Biblatex. I will discuss it with universal-ctags developer.

raven42 commented 9 months ago

Hmm... ok it appears that universal-ctags is using both the bibtex and biblatex parsers when processing a .bib file. Even if the language type is forced to just bibtex. I'm not sure if this is by design or not, but we can try to accommodate in tagbar.

tagbar-test-files$ ctags --extras=+F -f - --format=2 --excmd=pattern --fields=nksSafet --sort=no --append=no -V --language-force=bibtex --bibtex-kinds=abBciIjmMnpPstu
  Option: --language-force=bibtex
  Option: --bibtex-kinds=abBciIjmMnpPstu
Initialize parser: BibTeX
Initialize parser: BibLaTeX
enable field "name": yes
enable field "input": yes
enable field "pattern": yes
Reading command line arguments
OPENING test.bib as BibTeX language file [new]
emmerich2000software    test.bib        /^@inproceedings{emmerich2000software,$/;"      j       line:1
schmidt1996pattern      test.bib        /^@misc{schmidt1996pattern,$/;" n       line:10
trilla2015improving     test.bib        /^@inproceedings{trilla2015improving,$/;"       j       line:17
marlow2009runtime       test.bib        /^@inproceedings{marlow2009runtime,$/;" j       line:26
hickey2008clojure       test.bib        /^@inproceedings{hickey2008clojure,$/;" j       line:36
jones2003haskell        test.bib        /^@book{jones2003haskell,$/;"   b       line:44
currying        test.bib        /^@online{currying,$/;" V       line:51
merrick2006xml  test.bib        /^@misc{merrick2006xml,$/;"     n       line:61
morley2014json  test.bib        /^@misc{morley2014json,$/;"     n       line:69
vanbrabant2008google    test.bib        /^@book{vanbrabant2008google,$/;"       b       line:76
appeltauer2011contextj  test.bib        /^@Article{appeltauer2011contextj,$/;"  a       line:83
siriwardena2013enterprise       test.bib        /^@book{siriwardena2013enterprise,$/;"  b       line:94
tagbar-test-files$

I can update the existing .bib kinds to include at least the non-conflicting entries from the bibtex definition. The following will not be able to be included though as they conflict with existing tag kinds for the bibtex language type.

B:audios
I:datasets
M:legislations
P:movies
i:references
j:reports
m:software
n:standards
p:suppcollections
s:videos
t:xdatas
raven42 commented 9 months ago

@andregpss Ok I pushed in another change that merges the bibtex and biblatex versions as much as possible. Give the latest a shot and let me know how it goes. As I stated in my last comment, there are a number of biblatex kinds that conflict with the bibtex kinds, so in those instances I used the bibtex kind definition.

andregpss commented 9 months ago

@raven42 This new update satisfies me. Tagbarnow includes all bibtex and partial biblatex references. Thanks! By the way, universal-ctags developer commented about "running multiple parsers on an input file". It may be useful.