Bug 130167

Summary: Tooltips for completion of bibtex citations
Product: [Applications] kile Reporter: Dominic Battre <dominic>
Component: generalAssignee: Jeroen Wijnhout <spam>
Status: CONFIRMED ---    
Severity: wishlist CC: nicolascasaballe, raghuramsusarla
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: This is what it looks like
The patch
Parsing of bibItems

Description Dominic Battre 2006-07-03 00:01:26 UTC
Version:            (using KDE KDE 3.5.3)
Installed from:    Gentoo Packages

I thought that it would be nice to extend the regular completion of bibtex references (when you type \cite{}) such that not only list of known bibtex keys is shown but also a synopsis that explains what the key references to (author, year, title).

I would appreciate if you could have a look at the attached patch and send me comments or include it into subversion in case you like it.

Here are some issues, I would like to discuss:

I have replaced the bibtex parser with the more powerful parser from KBibTeX.  My questions are:
1) Is this a good idea? It creates code duplication.
2) Is this ok from a copyright perspective?  KBibTeX is licenced under GPL 2 as well.

The parser of KBibTeX uses a QTextStream.  Until Qt 4.2 the QTextStream supports no pos() and seek().  Therefore, I have to search for each item-key to determine its row and column in the .bib file.  Therefore the runtime is something like O( nrEntries * bibfile length ).  With Qt 4.2 it is possible to use the pos() method.  I have included something like that (see the #if QT_VERSION >= 0x040200 section) but I have not been able to test it.  Therefore, I cannot tell whether it complies with Qt 4.2.
Comment 1 Dominic Battre 2006-07-03 00:01:51 UTC
Created attachment 16866 [details]
This is what it looks like
Comment 2 Dominic Battre 2006-07-03 00:03:15 UTC
Created attachment 16867 [details]
The patch

The patch comprises the one of bug #130148 in an updated version (allowing
underscores)
Comment 3 Jeroen Wijnhout 2006-07-03 20:45:50 UTC
This looks like an interesting feature. However on my system the patch does not compile:
kileinfo.cpp:236: error redefinition of 'const QStringList *KileInfo::allBibItemsAnnotated(KileDocument::Info *)

best,
Jeroen
Comment 4 Dominic Battre 2006-07-08 14:25:24 UTC
Sorry for the delay.  I can work on this almost only on the weekends.

Could you please check whether you have applied the patch correctly?  I have had some problems with that when trying to reproduce your error (I was able to).  This is what works fine for me:

domi@domi2:~/tmp/office/kile> svn update
domi@domi2:~/tmp/office/kile> svn revert -R .
domi@domi2:~/tmp/office/kile> rm bibtex*      # delete some stuff that was created due to wrongly applying the patch before
domi@domi2:~/tmp/office/kile> rm kile/bibtex* # delete new files not covered by svn revert
domi@domi2:~/tmp/office/kile> make clean
domi@domi2:~/tmp/office/kile> patch -p0 < tooltipsincompletion.patch 
patching file kile/bibtexentry.cpp
patching file kile/bibtexentryfield.h
patching file kile/bibtexfile.h
patching file kile/bibtexentryfield.cpp
patching file kile/bibtexfileimporterbibtex.cpp
patching file kile/kileinfo.cpp
patching file kile/codecompletion.cpp
Hunk #2 succeeded at 389 (offset 4 lines).
Hunk #3 succeeded at 977 (offset 4 lines).
Hunk #4 succeeded at 997 (offset 4 lines).
Hunk #5 succeeded at 1106 (offset 4 lines).
patching file kile/bibtexstring.cpp
patching file kile/bibtexcomment.h
patching file kile/bibtexvalue.cpp
patching file kile/Makefile.am
patching file kile/kiledocumentinfo.h
patching file kile/bibtexfileimporter.h
patching file kile/bibtexvalue.h
patching file kile/kiledocumentinfo.cpp
Hunk #2 succeeded at 519 (offset -7 lines).
Hunk #3 succeeded at 807 (offset -7 lines).
Hunk #4 succeeded at 888 (offset -7 lines).
Hunk #5 succeeded at 966 (offset -7 lines).
patching file kile/bibtexfileimporter.cpp
patching file kile/bibtexfileimporterbibtex.h
patching file kile/bibtexfile.cpp
patching file kile/bibtexelement.h
patching file kile/bibtexcomment.cpp
patching file kile/bibtexelement.cpp
patching file kile/bibtexentry.h
patching file kile/kileinfo.h
patching file kile/codecompletion.h
patching file kile/bibtexstring.h
domi@domi2:~/tmp/office/kile> make
...
domi@domi2:~/tmp/office/kile> kile/kile
Program starts fine...
Comment 5 Jeroen Wijnhout 2006-07-09 12:17:05 UTC
The patch applied cleanly. But I discovered the problem: all bibtex*.{h,cpp} files had duplicate entries. That is the original files were copied three times into the bibtex*.{h,cpp} files. This caused multiple definitions of the same methods, which is illegal in C++. I've removed the duplicate definitions by hand, it compiles now. However no tooltips show, do I have to do something special?

best,
Jeroen
Comment 6 Dominic Battre 2006-07-09 14:47:53 UTC
No, maybe you can checkout kile at a separate location from subversion and apply the patch with "patch -p0 < tooltipsincompletion.patch".  It should work out of the box.

Oh, and it requires a bib-tex file.  It does not work with handwritten inline bibtex commands like
  \bibitem{Murray-vanRyper}James D. Murray, William vanRyper:
           {\sl Graphics File Formats}. O'Reilly\&Associates, Inc.,
           Sebastopol, CA, 1994.
Comment 7 Jeroen Wijnhout 2006-07-09 14:52:52 UTC
I applied the patch on a clean checkout, it didn't work out of the box. Don't understand why, but I fixed it manually.

Didn't test with a .bib file yet. However it should work with manually written bibitems too. Otherwise we end up with inconsistent behavior.

best,
Jeroen
Comment 8 Dominic Battre 2006-07-09 15:05:08 UTC
sure, but that is much harder because it requires to parse LaTeX.  Data in BibTeX are structured and much easier to handle.  Of course, one could just copy the latex commands and reproduce them in the tooltip.  That should not be very difficult.
Comment 9 Dominic Battre 2006-07-09 15:53:39 UTC
Created attachment 16931 [details]
Parsing of bibItems

Maybe you can try the attached snippet.

It is supposed to go into kiledocumentinfo.cpp (just look for the line "else if
( (*it).type == KileStruct::BibItem )" in "void TeXInfo::updateStruct()".  The
snippet is supposed to replace the whole old "else if"-block.  I thought that
this is easier than another patch-file.

It is not particularly nice but probably better than nothing.
Comment 10 Thomas Braun 2006-09-20 22:54:25 UTC
Hello,

I just wanted to give my 2 cents.
I like the funcionality of the patch, but I don't like that we take so much code from kbibtex. It is really a lot, and that means also much new code to maintain (and perhaps also somehow sync with upstream)
Wouldn't it be easier to ask the kbibtex dev to create a library of useful functions for that?
Or use same dcop magic to use a current running kbibtex to parse the file?

Thomas
Comment 11 Thomas Braun 2009-08-07 19:19:09 UTC
*** Bug 202534 has been marked as a duplicate of this bug. ***