7

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179

1 Answers1

9

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.

mmmmmm
  • 491
  • 1
  • 4
  • 19
Drew
  • 75,699
  • 9
  • 109
  • 225