-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add prefix argument to force reloading of the cache #122
Conversation
For all interactive functions, pass the prefix to `bibtex-read' to allow optionally enforcing the reloading of the bibliography cache.
Thanks for this! A couple of questions:
I will also mention that I had in mind optimization an external notify-based auto cache refresh, as hinted at in the wiki, preferably contributed by someone with more experience with that than I. I did elect, however, NOT to include bibtex-completion-init-like support for this out-of-box. But that doesn't mean we can't do both of course. |
oops, my elisp mode has a hook which calls `whitespace-cleanup' for every save.
The idea is that you can trigger reloading before doing anything with your bibtex stuff. So I export my library by going to Zotero, export the library manually, go back to emacs, and then press C-u . I often work with the browser to add references to Zotero. Then I want to store a note, go to Emacs, and find out that the library has not been refreshed. I sigh, force refresh manually by calling
Actually the PR isstep one for another solution I have in mind. The idea to recreate the This solution, once implemented, would allow the user to bypass any interaction with Zotero. You launch Emacs, you launch Zotero, you put Zotero in the background. You import stuff in the browser, then go to Emacs to add comments etc. You call a bibtex-action with C-u, and everything is fine. |
I'm not super familiar with the tooling landscape around this with elisp. So you're using a built-in command for that; not this package? https://github.com/purcell/whitespace-cleanup-mode I feel like we need some standardized solution, to avoid the repo history getting loaded up with diffs of whitespace. Any thoughts on that? For example, in another project I work on, we have a CI check with prettier for the js and markdown content, so I can basically say to devs, make sure to run prettier on your code, or it will get flagged. How to deal with that for elisp?
So I'm still unsure how this works. You do Ah, I guess so: https://www.emacswiki.org/emacs/PrefixArgument.
Cool! |
Thanks for the hint to whitespace-cleanup-mode, that sounds like a better solution. It actually calls the built-in function, but only if some criteria match. And yes, it would be good to have a standard there. But I don't know what's used by other projects... |
Here's the link to the tool for force-exporting the library: https://github.com/publicimageltd/pullbib |
This seems potentially promising: https://gitlab.com/ideasman42/emacs-elisp-autofmt I'm checking to see how the listed projects use it. Edit: as I do, a number of those projects are by the same author. Also, not on MELPA. Just installed lispy, and then quickly uninstalled it when it installed packages I didn't want.
I'll approve it; just want to figure out the formatting issue. Also, need to add a note about it to the README. |
While I work on the formatting issues, I just ran the CI workflow (I have to approve it for first time PRs because I had a malicious PR awhile back), and it has a warning about one of the docstrings. Check the "files" tab and you'll see it. Can you fix that please? PS - I just pulled down the PR, and your formatting code is replacing spaces with tabs. |
I've spent a bit of time reviewing the options for auto-formatting, and none seem ideal, which appears to be a consequence of lisp itself (it has a very flexible syntax). It seems the most practical thing I can do is say to follow the Elisp style guide, which does say no hard tabs, etc., in the contributing doc, and maybe include a checklist to remind folks. I strongly suggest you deactivate that auto-save solution you have, certainly when working on PRs for other projects which don't use it, because it means every PR you submit will confuse the diffs and history. But I found this very cool solution to getting git to ignore whitespace changes, and to fix a commit that has them. If you check the "inv-cache-clean" branch, the file (and here's the diff if you're curious) has your changes without the whitespace changes. I also fixed the docstring warning. So you could simply copy that file over your local branch and commit it, and I can squash the commits on merge, or you could try the solution I used yourself: |
Sorry for the whitespace mess. Didn't even think that that function |
Formatting/diff now looks perfect! I added a README change as well; merging now. Thanks again! |
On this, I was wondering where there might be room for hooks. This sounds like a good example! |
Just a note on the whitespace mess: I found out that setting the buffer-local variable (add-hook 'emacs-lisp-mode-hook (lambda () (setq indent-tabs-mode nil))) So in conjunction with Purcell's |
Good deal!
And presumably not to touch spaces? |
"Touching" meaning exactly what? If you mean: Leaving them "as-is", yes. But of course, empty lines and trailing spaces are removed. The documentation of |
Sorry; I was vague.
Yes, that's what I meant.
|
@publicimageltd - I have currently removed this in #628, for two reasons:
Any counter-argument? |
Thanks for notifying me. I regularly use the prefix argument to create a new bib file. So my main use is not simply parsing / caching, but rather to trigger Zotero from within Emacs. From an abstract point of view, this is use case completely unrelated to the citar functions and could be removed. But for quite natural reasons, I would rather keep it. I see it more like a hook: If you want something to be done before you access your bibliography (and if you don't want it done every time), call the Citar functions with a prefix. I like it. In sum: You may remove it, since I can simply advise these functions to have the same functionality, but I don't see any reason to not leave it since it is not so much about the cache but rather about "doing something before". But it might well be the case that this is a rather special use case. On the other hand, I imagine a lot of people have this need. Once the data base has grown, auto-updating the corresponding bib tex file, in my view, is not an option anymore (too long, blocks Zotero regularly). |
If it's "like a hook", would a hook be better here? Part of the reason I was asking is also wondering about using prefix args for other UI purposes. But I'm not super knowledgeable about either prefix args or hooks! |
Hooks are usually run every time something happens or is done. Have a look at the standard hooks listed in the Emacs Lisp manual. The current prefix handling, however, only triggers these actions if the associated function is called interactively with a prefix. So no, a hook would not behave the same way. If you feel the need to remove the prefix handling to free it for other purposes, please go ahead. I am afraid not many people are using it, even though I personally think it is super practical and that it is nearly mandatory if one has a huge data base maintained by Zotero. But then, judging from the github traffic, nobody is using |
I'm not committed to removing (or rather not re-implementing it with the new core code); why I was asking the questions ;-) I'll put this on the list of details to settle, and link here. Thanks! |
A second thought: If the cache then is updated via filenotify or in other automatic ways, won't that block Emacs in the case of huge databases? That's the only problem I could see if we are talking about keeping the same functionality. I would like to control the recreation of the cache if it can't be done in the background smoothly. |
Yeah, it could. But @roshanshariff has in mind it may be possible to do this, or parts of it, asynchronously somehow. I do think the branch code is a lot of faster, but my bib file is only ~1000 entries, and I've not figured out a good benchmark yet to test this objectively. |
For all interactive functions, pass the prefix to `bibtex-read' to
allow optionally enforcing the reloading of the bibliography cache.
This is to avoid having to call
bibtex-actions-refresh
manually if the library file has been changed.