textmate / latex.tmbundle

TextMate support for LaTeX
97 stars 64 forks source link

citation autocomplete bug #115

Closed szymtor closed 9 years ago

szymtor commented 9 years ago

Textmate hangs in the following scenario.

I create the following file test.tex:

\documentclass{article}
\begin{document}
\bibliography{bib}
\end{document}

and the following file bib.bib:

@article{A,
author = {A}}
%@article{B}

(both files should be saved). Then, in test.tex, I execute: insert citation based on current word. This hangs Textmate.

sanssecours commented 9 years ago

Hi Szymon,

I guess the command is kind of picky when it comes to the structure of a bib file. Fixing this might take some time.

I would recommend you use the excellent BibDesk to manage your bibliography entries. If you for example open bib.bib in BibDesk and save it, then “BibDesk” will create a file that “Citation Based on Current Word / Selection…” is able to parse correctly.

Kind regards, René

szymtor commented 9 years ago

Hi René,

thanks for the reply. Actually, I use BibDesk, and you're right – saving this bib files in BibDesk removes the error. The problem is with my coauthors, who submit such bib-files into a common project, and all the sudden this hangs my TextMate (when I try to auto complete a citation). But well, its not a big deal, I just have to beg them not to play such cruel jokes on me...

Best, Szymon

plalteaugal commented 9 years ago

Hi René,

I use Bibdesk with TextMate, but autocompletion does not work in the citation field \cite{xxx}. Of course, I save my bib.bib file whenever I add a bib entry. Is there anything else I should do?

Thanks for all of your great work!

Jenny

On Jan 12, 2015, at 7:58 AM, René Schwaiger notifications@github.com wrote:

Hi Szymon,

I guess the command is kind of picky when it comes to the structure of a bib file. Fixing this might take some time.

I would recommend you use the excellent Bibdesk http://bibdesk.sourceforge.net/ to manage your bibliography entries. If you for example open bib.bib in BibDesk and save it, then “BibDesk” will create a file that “Citation Based on Current Word / Selection…” is able to parse correctly.

Kind regards, René

— Reply to this email directly or view it on GitHub https://github.com/textmate/latex.tmbundle/issues/115#issuecomment-69591966.

sanssecours commented 9 years ago

Hi Jenny,

theoretically you should only need to press ⌥⎋ (Alt-Esc) inside the braces of cite (\cite{˰}) and a list with all the entries in the bib file should pop up. You could also enter some characters that are part of the cite key e.g. ~\cite{1986˰} to narrow down the possible entries. If there is only one fitting entry, then it should be inserted directly.

If the above procedure does not work for you, then it is very likely that the command was not able to parse your bib file. Could you then please post your file so that I can check it and possibly fix your issue.

Kind regards, René


P.S.: Currently there seems to be a problem if we invoke the completion in an empty “cite” like \cite{˰}, since the chosen key also replaces the braces. Instead of \cite{keyOfBibItem} we get \citekeyOfBibItem. It works correctly if we insert a space in the cite, select it, and then invoke the completion. This might be a bug in TextMate.

@sorbits: Allan, is it intentional that the output of the command replaces the braces, although they are not part of the input? Here is a minimal example to reproduce the behaviour:

  1. Create a new bundle item

    #!/usr/bin/env ruby18 -wKU
    puts "Hello world"

    Name: Bla Key Equivalent: ⌥⎋ Input: Selection Format: Text Output: Replace Input Format: Text

  2. Create an new file with the following content: {}
  3. Invoke ⌥⎋ inside the braces ({˰})
  4. Output: Hello World
  5. Expected output: {Hello world}
sorbits commented 9 years ago

@sanssecours Something which isn’t currently exposed in the bundle editor is that commands can have a fallbackInput which is used when there is no selection (and input is set to Selection).

For the cite completion command the fallback input is Word. For empty braces the current word is those braces. This is consistent with what you get if you press ⌃W (Select Word).

So I think the behavior is correct, and the command should special-case getting {} as input.

sanssecours commented 9 years ago

Hi Allan,

thanks for the quick response.

So I think the behavior is correct, and the command should special-case getting {} as input

That sounds like a good idea. I will update the command accordingly.

Kind regards, René

sanssecours commented 9 years ago

Hi,

the newest code should fix the bug reported by Szymon. If anyone has any additional examples that do not work, then please report them. I am always happy about feedback. Even it is about something I broke :).

Thanks, René