How can I insert header comments in source files of arbitrary languages?

  • If the file is newly created, the header should be inserted.
  • If a file already exists, then it should be possible to insert a header at the top of the file, or update as needed (update file name in the header if the file name changed, update copyright year)
  • Of course depending on the language, the header should be inserted with the correct commenting characters.

I am looking forward to different packages and/or custom elisp recommendations.


Here is one answer: library header2.el.

You can use it to define file headers for different types of file (C, shell, Emacs Lisp, etc.). You can automatically insert a header when you open a new file buffer. Different parts of the header can be updated automatically when the file is saved. Or you can add or update a header manually.

For Emacs-Lisp files, header2.el headers can take advantage of library lib-requires.el, to fill in and update a list of Lisp libraries that the file with the header might require. The list is based on the currently loaded libraries that are used by the file with the header.

For a more detailed description and examples, see Emacs Wiki page Automatic File Headers.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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