21

Usually around this time of year people start to realize that their copyright year is out of date in their files. This is particularly annoying if you like to put the copyright in every source file. I was wondering if emacs could help here.

Is there a mode that would automatically update the copyright year in a file? Ideally, I would setup the mode with my name and affiliations, so that it only updates the copyright for those. It would also only update the copyright automatically when a change is made (although it would be nice to also have an easy way to do a bulk change to a project).

  • Would not matter much which year you write since copyright by the Berne convention is at least life +50 years all over the world. – mathreadler Feb 10 '15 at 10:48
24

You can use the copyright-update function. I would read the docs for the function. and others inside copyright.el for more info, but as a simple example, If I have:

;; Copyright (C) 2014, Jordon Biondo

in a file and run copyright-update from the minibuffer, it updates the line to say

;; Copyright (C) 2014, 2015, Jordon Biondo

You can have the function remove the old year if you'd like.

To handle automatic updates, you could add the function to the before-save-hook list.

To do a batch update, use the command copyright-update-directory.

The copyright library has a lot of features and ways to customize it, I would suggest opening up the library to begin seeing how you can adapt it to your needs.

  • 3
    These are the times that I stand in awe of Emacs. – PythonNut Feb 9 '15 at 17:35
6

Here's what I use:

(when (fboundp 'copyright-update)
  (setq copyright-names-regexp "Monnier\\|Free Software")
  (add-hook 'before-save-hook #'copyright-update))

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.