joostkremers / ebib

A BibTeX database manager for Emacs.
https://joostkremers.github.io/ebib/
BSD 3-Clause "New" or "Revised" License
275 stars 37 forks source link

Possible to call `after-save-hook` after writing database #306

Open swflint opened 3 weeks ago

swflint commented 3 weeks ago

Would it be possible to call after-save-hook in the context of the buffer visiting a given database file? Not doing so prevents git-auto-commit-mode from operating like I'd expect.

joostkremers commented 2 weeks ago

No, unfortunately not. The reason is that there is no buffer visiting the database file. What Ebib does is read the contents of a .bib file and store it in a hash table. Then when you save the database, it is written to a temp buffer, the content of which is then written (using write-region) to the original file.

I don't immediately see an alternative solution... Perhaps visiting the .bib file and enabling auto-revert-mode in that buffer could work. Ebib shouldn't touch that buffer (it uses temp buffers to read and write the file, it never visits it), and auto-revert-mode should ensure that when Ebib saves the database, the buffer is reverted. I don't know if that triggers after-save-hook, but if not you could probably use after-revert-hook to call gac-after-save-func.

A little cumbersome, of course... Perhaps it makes sense to add some hooks to Ebib to make this easier.

swflint commented 2 weeks ago

That's about what I had expected. I may try to make a PR if I can get something working.