When I run bibtex-fill-entry it formats the current entry block where the cursor is at. Note that bibtex-fill-entry (C-c C-q) Fill current BibTeX entry. So I have to traverse all the entries to align them one by one which is time consuming.

Instead I want to apply bibtex-fill-entry for all fields in the bibtex buffer, after each save after-save-hook. How can I apply bibtex-fill-entry to entire buffer (all the entries)?

Here cursor is at the beginning of the title = {Clique}, line. When I do M-x bibtex-fill-entry it only aligns the first entry. I also want to align second entry (considering all entries in the buffer).

        title          = {Clique},
  url          = {https://github.com/ethereum/EIPs/issues/225/},

          title        = {Geth},
  url          = {https://github.com/ethereum/go-ethereum/wiki/geth/},

Related: How to make emacs align and indent a bibtex entry?

  • You should be able to create a keyboard macro that does bibtex-fill-entry and then bibtex-next-entry to get to the next one. Then you can repeat the keyboard macro say 1000 times to do all of them. However, in my experiment M-} which is bound to bibtex-next-entry does not seem to do anything, but you might want to see if it works for you (I didn't try very hard to make it work).
    – NickD
    Commented Oct 28, 2022 at 15:49
  • @NickD That's a smart solution. I get hard time coding and debugging in lisp. But I will try to implemet what you recommended by looking for solution that repeat keyboard macros from beginning of the buffer.
    – alper
    Commented Oct 28, 2022 at 20:01
  • Found out what was wrong with M-} - see answer.
    – NickD
    Commented Oct 28, 2022 at 22:52

1 Answer 1


EDIT: There is bibtex-reformat which will reformat the whole buffer (or the selected region), so there is no need to define a macro: M-x bibtex-reformat will do it all.

[Obsolete answer] Go to the beginning of the buffer and create a keyboard macro that does bibtex-fill-entry (bound to C-c C-q) and then bibtex-next-entry (bound to M-}):

C-x ( C-c C-q M-} C-x )

That defines an anonymous macro that you can execute once with C-x e to try it out. You should be at the beginning of the third entry at this point, so all you have to do is repeat the invocation of the macro: C-u 1000 C-x e. That will repeat it 1000 times; if you have more entries, just do it again (maybe with a larger number).

The reason that M-} was ineffective in my case, was that @electronic was not a known BibTeX entry type. When I changed it to @article, it worked. I presume there is a way to add new entry types to bibtex, but I haven't gone down that path.

  • Can we define the macro in the config file by default?
    – alper
    Commented Oct 28, 2022 at 23:59
  • There is no need for a macro - see the edit.
    – NickD
    Commented Oct 29, 2022 at 1:34
  • To make bibtex-reformat work , I have to select complete buffer using mark-whole-buffer than apply bibtex-reformat right? Could this combined in a single keybinding?
    – alper
    Commented Oct 29, 2022 at 11:38
  • 1
    I don't think so: if you don't have a region defined, it defaults to the whole buffer. There is no need for a single keybinding.
    – NickD
    Commented Oct 29, 2022 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.