Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File local variables and pdf / notes symbol #223

Open
jack836 opened this issue Jan 16, 2018 · 17 comments
Open

File local variables and pdf / notes symbol #223

jack836 opened this issue Jan 16, 2018 · 17 comments

Comments

@jack836
Copy link

jack836 commented Jan 16, 2018

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!

@tmalsburg
Copy link
Owner

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

@jack836
Copy link
Author

jack836 commented Jan 17, 2018

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
Copy link
Author

jack836 commented Jan 17, 2018

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.

@tmalsburg
Copy link
Owner

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

@jack836
Copy link
Author

jack836 commented Jan 18, 2018

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

@tmalsburg
Copy link
Owner

tmalsburg commented Jan 18, 2018

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.

@jack836
Copy link
Author

jack836 commented Jan 19, 2018

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.

@djhogan
Copy link

djhogan commented Aug 22, 2018

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.

@tmalsburg
Copy link
Owner

@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?

@djhogan
Copy link

djhogan commented Aug 23, 2018

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

@tmalsburg
Copy link
Owner

tmalsburg commented Aug 25, 2018

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.

@fpopineau
Copy link
Contributor

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,

@tmalsburg
Copy link
Owner

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
Copy link
Owner

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

@fpopineau
Copy link
Contributor

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!)

@tmalsburg
Copy link
Owner

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants