helm-bibtex icon indicating copy to clipboard operation
helm-bibtex copied to clipboard

File local variables and pdf / notes symbol

Open jack836 opened this issue 7 years ago • 17 comments

When I set my variables (as global) in my .org file as shown below

# Local Variables:
# eval: (setq bibtex-completion-bibliography "~/projects/ipDisplay/bibliography/references.bib"
#         bibtex-completion-library-path "~/projects/ipDisplay/bibliography/pdfs"
#         bibtex-completion-notes-path "~/projects/ipDisplay/bibliography/notes.org")
# End:

On doing helm-bibtex, I get the following output with the pdf and notes symbols as expected

globalwithmarks

Now, when I try to set my variables buffer specific (as local), as shown below

# Local Variables:
# bibtex-completion-notes-path: "~/projects/ipDisplay/bibliography/notes.org"
# bibtex-completion-bibliography: "~/projects/ipDisplay/bibliography/references.bib"
# bibtex-completion-library-path: "~/projects/ipDisplay/bibliography/pdfs"
# End:

Now, On doing helm-bibtex, I get the following output where the ** pdf and notes symbols are missing**

localwithoutmarks

I am using Emacs 26 and the latest version of bibtex-completion. Is this issue reproducible or Am I missing some thing? Would be nice if this issue can be fixed!

jack836 avatar Jan 16 '18 13:01 jack836

Very strange. Not sure what's happening here. However, I'm not too surprised because helm-bibtex wasn't designed to do that. Have you seen this section in the documentation?: https://github.com/tmalsburg/helm-bibtex#search-in-the-local-bibliography

tmalsburg avatar Jan 16 '18 14:01 tmalsburg

I already tried both (helm-bibtex and helm-bibtex-with-local-bibliography) and they produce the same result. Is there a way to manually force re-parsing the references.bib and notes.org file (or refresh the database)?

jack836 avatar Jan 17 '18 04:01 jack836

In addition to the above the following also happens.

When I add or delete an entry in the notes.org file, the note symbols are not updated accordingly. Then when I change thebibtex-completion-bibliography variable from "~/projects/ipDisplay/bibliography/references.bib" to "/Users/name/projects/ipDisplay/bibliography/references.bib" and reload the variables, the note symbols appear correctly reflecting the change to the notes file. [Note:they both point to the same file, but in a different way]

Then when I make another addition or deletion to the notes.org file , the note symbols will not update again. So I have to change (in the reverse) again from "/Users/name/projects/ipDisplay/bibliography/references.bib" back to "~/projects/ipDisplay/bibliography/references.bib" to make it reflect the changes.

It continues to work correctly (reflecting the changes) as long as I keep switching the variables.

It appears that the database/entries are updated/reloaded only when helm-bibtex sees as change in the reference.bib file path variable. Is it the intended behavior? If so manually forcing an update/reload/re-parsing can be a solution? Any help is highly appreciated.

jack836 avatar Jan 17 '18 09:01 jack836

It appears that the database/entries are updated/reloaded only when helm-bibtex sees as change in the reference.bib file path variable.

This is exactly right. You can force a reload by prefixing helm-bibtex with C-u. This is explained in the documentation: https://github.com/tmalsburg/helm-bibtex#force-reloading-of-the-bibliography

tmalsburg avatar Jan 17 '18 19:01 tmalsburg

Oh! my mistake. Sorry about that! But how did I miss that paragraph? (I went through the readMe up and down at least 10 times). Is it time to add a table of contents to the heavily grown-up readMe?

Coming to the point, the issue with update is solved right away! Thank you @tmalsburg for pointing out.

But the earlier issue with file local variables, still remains. I even tried C-u M-x helm-bibtex-with-local-bibliography

jack836 avatar Jan 18 '18 03:01 jack836

When using the local bib, there's usually no need to C-u. But to be honest, I'm not sure whether we implemented local-bib only for latex or also for org files (I'm assuming you're referring to org-ref?).

With regards to the missing icons, I'm at a loss here. I don't see how changing these variables could lead to this problem. Could you try to pin down which of the three variables is triggering the problem? (I'm not using org-ref.) Thank you.

tmalsburg avatar Jan 18 '18 09:01 tmalsburg

Yes! I am using org-ref. Thank you for the suggestion, that looks like a good starting point. I will play with the three variables this week-end.

jack836 avatar Jan 19 '18 06:01 jack836

When I add or delete an entry in the notes.org file, the note symbols are not updated accordingly.

I also see the same behaviour. I have to restart emacs before the notes symbols are updated.

djhogan avatar Aug 22 '18 20:08 djhogan

@djhogan are you using helm-bibtex-with-local-bibliography or buffer-local variables?

Could you try the following:

  • Create new note.
  • M-: (bibtex-completion-clear-cache)
  • And then fire up helm-bibtex.

Do you see the notes symbol then?

tmalsburg avatar Aug 23 '18 09:08 tmalsburg

I haven't dealt with these options. I'm using the defaults except I've set the variables

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(bibtex-completion-bibliography "~/Dropbox/bib/sources.bib")
 '(bibtex-completion-notes-path "~/Dropbox/bib/notes.org")

I tried doing what you said and the notes symbol appeared. It also appears when I type C-u before firing up helm-bibtex

djhogan avatar Aug 23 '18 16:08 djhogan

Thanks. My understanding is that this issue only arises when the local bibliography is used. Are you using helm-bibtex-with-local-bibliography to open helm-bitbex with the local bib or the approach described at the top (using buffer-local variables). Sorry if this question was unclear in my previous post. More generally, it would be good to have a recipe for reproducing the problem that you're observing.

tmalsburg avatar Aug 25 '18 13:08 tmalsburg

I am not sure this is totally relevant, but I was looking why I couldn't use a buffer local variable for bibtex-completion-library. Actually I had a global value for this variable and I tried to change it locally in some buffer. I ended up finding that in bibtex-completion.el there is the function bibtex-completion-get-entry1 which is using a temporary buffer. In this temporary buffer, the global value for bibtex-completion-library prevails. So because of this temp buffer, using a buffer local value for bibtex-completion-library is bound to fail. A possible fix for this is to rewrite this function:

(defun bibtex-completion-get-entry1 (entry-key &optional do-not-find-pdf)
  (let ((bib (bibtex-completion-normalize-bibliography 'bibtex)))
    (with-temp-buffer
      (mapc #'insert-file-contents bib)
      (goto-char (point-min))
      (if (re-search-forward (concat "^[ \t]*@\\(" parsebib--bibtex-identifier
                                     "\\)[[:space:]]*[\(\{][[:space:]]*"
                                     (regexp-quote entry-key) "[[:space:]]*,")
                             nil t)
          (let ((entry-type (match-string 1)))
            (reverse (bibtex-completion-prepare-entry
                      (parsebib-read-entry entry-type (point) bibtex-completion-string-hash-table) nil do-not-find-pdf)))
        (progn
          (display-warning :warning (concat "Bibtex-completion couldn't find entry with key \"" entry-key "\"."))
          nil)))))

However I am not sure it fixes everything in this area.

Regards,

fpopineau avatar Jun 05 '19 23:06 fpopineau

Oh, that makes sense. @fpopineau, would you mind making a PR.

Can you see any downsides of your approach compared to the code we currently use?

tmalsburg avatar Jul 03 '19 15:07 tmalsburg

And sorry for the slow responses. I was (technically I still am) on parental leave and tried to cut down on screen time.

tmalsburg avatar Jul 03 '19 15:07 tmalsburg

I made the PR for my small patch. I don't see any downsides, as it will allow to change the value of bibtex-completion-library per buffer. Plus the fix is very light: catch the value of the variable before switching to the temp buffer.

(No problem at all for the slow responses, hope the kids are alright!)

fpopineau avatar Jul 06 '19 21:07 fpopineau

Merged. Thank you. Not sure though whether this will fix the current issue. @jack836 would you mind trying it with the new code? Should be on MELPA in a couple of hours. Thank you!

tmalsburg avatar Jul 08 '19 09:07 tmalsburg

Never mind, @jack836. It doesn't work yet. I had a look at the code and fixing this unfortunately takes a bit more work. When I wrote this code, I just didn't think of buffer local customization variables and the current architecture is fundamentally incompatible with them. Sigh. The problem is that reading and all postprocessing the bib entries is all done in the context of a temp buffer. Instead we should do minimal work in the in temp buffer and then postprocess in the buffer where we started.

tmalsburg avatar Jul 08 '19 09:07 tmalsburg