22

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).

Dan
  • 32,584
  • 6
  • 98
  • 168
asmeurer
  • 1,552
  • 12
  • 30
  • 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

2 Answers2

25

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.

tarsius
  • 25,298
  • 4
  • 69
  • 109
Jordon Biondo
  • 12,332
  • 2
  • 41
  • 62
6

Here's what I use:

(when (fboundp 'copyright-update)
  (setq copyright-names-regexp "Monnier\\|Free Software")
  (add-hook 'before-save-hook #'copyright-update))
Stefan
  • 26,154
  • 3
  • 46
  • 84