1995-07-07 19:40:05 +00:00
|
|
|
|
;;; copyright.el --- update the copyright notice in current buffer
|
1992-05-30 20:24:49 +00:00
|
|
|
|
|
2004-01-04 23:00:06 +00:00
|
|
|
|
;; Copyright (C) 1991, 92, 93, 94, 95, 1998, 2001, 2003, 2004
|
2003-06-14 20:11:37 +00:00
|
|
|
|
;; Free Software Foundation, Inc.
|
1992-07-22 02:58:48 +00:00
|
|
|
|
|
1998-12-14 03:22:44 +00:00
|
|
|
|
;; Author: Daniel Pfeiffer <occitan@esperanto.org>
|
1995-07-07 19:40:05 +00:00
|
|
|
|
;; Keywords: maint, tools
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1996-01-14 07:34:30 +00:00
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
1995-07-07 19:40:05 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Allows updating the copyright year and above mentioned GPL version manually
|
2003-06-14 20:11:37 +00:00
|
|
|
|
;; or when saving a file.
|
2004-01-05 18:19:11 +00:00
|
|
|
|
;; Do (add-hook 'before-save-hook 'copyright-update), or use
|
|
|
|
|
;; M-x customize-variable RET before-save-hook RET.
|
1991-06-03 19:54:13 +00:00
|
|
|
|
|
1992-07-14 19:42:01 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
1998-04-01 10:44:40 +00:00
|
|
|
|
(defgroup copyright nil
|
|
|
|
|
"Update the copyright notice in current buffer."
|
|
|
|
|
:group 'tools)
|
|
|
|
|
|
|
|
|
|
(defcustom copyright-limit 2000
|
1995-07-07 19:40:05 +00:00
|
|
|
|
"*Don't try to update copyright beyond this position unless interactive.
|
2002-01-13 20:17:46 +00:00
|
|
|
|
A value of nil means to search whole buffer."
|
1998-04-01 10:44:40 +00:00
|
|
|
|
:group 'copyright
|
|
|
|
|
:type '(choice (integer :tag "Limit")
|
|
|
|
|
(const :tag "No limit")))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
|
2003-08-20 18:46:55 +00:00
|
|
|
|
;; The character classes have the Latin-1 version and the Latin-9
|
|
|
|
|
;; version, which is probably enough.
|
1998-04-01 10:44:40 +00:00
|
|
|
|
(defcustom copyright-regexp
|
2002-02-07 17:39:27 +00:00
|
|
|
|
"\\([<5B><><EFBFBD><EFBFBD>]\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\
|
|
|
|
|
\\|[Cc]opyright\\s *:?\\s *[<EFBFBD><EFBFBD><EFBFBD><EFBFBD>]\\)\
|
2004-01-04 23:00:06 +00:00
|
|
|
|
\\s *\\([1-9]\\([-0-9, ';%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)"
|
1995-07-07 19:40:05 +00:00
|
|
|
|
"*What your copyright notice looks like.
|
1998-04-01 10:44:40 +00:00
|
|
|
|
The second \\( \\) construct must match the years."
|
|
|
|
|
:group 'copyright
|
|
|
|
|
:type 'regexp)
|
1995-07-07 19:40:05 +00:00
|
|
|
|
|
|
|
|
|
|
1998-04-01 10:44:40 +00:00
|
|
|
|
(defcustom copyright-query 'function
|
2002-01-13 20:17:46 +00:00
|
|
|
|
"*If non-nil, ask user before changing copyright.
|
1998-04-01 10:44:40 +00:00
|
|
|
|
When this is `function', only ask when called non-interactively."
|
|
|
|
|
:group 'copyright
|
|
|
|
|
:type '(choice (const :tag "Do not ask")
|
1998-06-24 09:06:56 +00:00
|
|
|
|
(const :tag "Ask unless interactive" function)
|
|
|
|
|
(other :tag "Ask" t)))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
|
|
|
|
|
|
1996-01-05 22:21:28 +00:00
|
|
|
|
;; when modifying this, also modify the comment generated by autoinsert.el
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(defconst copyright-current-gpl-version "2"
|
2002-01-13 20:17:46 +00:00
|
|
|
|
"String representing the current version of the GPL or nil.")
|
1991-06-03 19:54:13 +00:00
|
|
|
|
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(defvar copyright-update t)
|
1992-06-19 20:17:18 +00:00
|
|
|
|
|
2001-01-08 16:00:38 +00:00
|
|
|
|
;; This is a defvar rather than a defconst, because the year can
|
|
|
|
|
;; change during the Emacs session.
|
2002-01-13 20:17:46 +00:00
|
|
|
|
(defvar copyright-current-year (substring (current-time-string) -4)
|
2001-01-08 16:00:38 +00:00
|
|
|
|
"String representing the current year.")
|
|
|
|
|
|
2003-06-14 20:11:37 +00:00
|
|
|
|
(defun copyright-update-year (replace noquery)
|
|
|
|
|
(when (re-search-forward copyright-regexp (+ (point) copyright-limit) t)
|
|
|
|
|
;; Note that `current-time-string' isn't locale-sensitive.
|
|
|
|
|
(setq copyright-current-year (substring (current-time-string) -4))
|
|
|
|
|
(unless (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
|
|
|
|
|
(substring copyright-current-year -2))
|
|
|
|
|
(if (or noquery
|
|
|
|
|
(y-or-n-p (if replace
|
|
|
|
|
(concat "Replace copyright year(s) by "
|
|
|
|
|
copyright-current-year "? ")
|
|
|
|
|
(concat "Add " copyright-current-year
|
|
|
|
|
" to copyright? "))))
|
|
|
|
|
(if replace
|
|
|
|
|
(replace-match copyright-current-year t t nil 1)
|
|
|
|
|
(let ((size (save-excursion (skip-chars-backward "0-9"))))
|
|
|
|
|
(if (and (eq (% (- (string-to-number copyright-current-year)
|
|
|
|
|
(string-to-number (buffer-substring
|
|
|
|
|
(+ (point) size)
|
|
|
|
|
(point))))
|
|
|
|
|
100)
|
|
|
|
|
1)
|
|
|
|
|
(or (eq (char-after (+ (point) size -1)) ?-)
|
|
|
|
|
(eq (char-after (+ (point) size -2)) ?-)))
|
|
|
|
|
;; This is a range so just replace the end part.
|
|
|
|
|
(delete-char size)
|
|
|
|
|
;; Detect if this is using the following shorthand:
|
|
|
|
|
;; (C) 1993, 94, 95, 1998, 2000, 01, 02, 2003
|
|
|
|
|
(if (and
|
|
|
|
|
;; Check that the last year was 4-chars and same century.
|
|
|
|
|
(eq size -4)
|
|
|
|
|
(equal (buffer-substring (- (point) 4) (- (point) 2))
|
|
|
|
|
(substring copyright-current-year 0 2))
|
|
|
|
|
;; Check that there are 2-char years as well.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-backward "[^0-9][0-9][0-9][^0-9]"
|
|
|
|
|
(line-beginning-position) t))
|
|
|
|
|
;; Make sure we don't remove the first century marker.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(forward-char size)
|
|
|
|
|
(re-search-backward
|
|
|
|
|
(concat (buffer-substring (point) (+ (point) 2))
|
|
|
|
|
"[0-9][0-9]")
|
|
|
|
|
(line-beginning-position) t)))
|
|
|
|
|
;; Remove the century marker of the last entry.
|
|
|
|
|
(delete-region (- (point) 4) (- (point) 2)))
|
|
|
|
|
;; Insert a comma with the preferred number of spaces.
|
|
|
|
|
(insert
|
|
|
|
|
(save-excursion
|
|
|
|
|
(if (re-search-backward "[0-9]\\( *, *\\)[0-9]"
|
|
|
|
|
(line-beginning-position) t)
|
|
|
|
|
(match-string 1)
|
|
|
|
|
", ")))
|
|
|
|
|
;; If people use the '91 '92 '93 scheme, do that as well.
|
|
|
|
|
(if (eq (char-after (+ (point) size -3)) ?')
|
|
|
|
|
(insert ?')))
|
|
|
|
|
;; Finally insert the new year.
|
|
|
|
|
(insert (substring copyright-current-year size))))))))
|
2001-01-08 16:00:38 +00:00
|
|
|
|
|
1991-06-03 19:54:13 +00:00
|
|
|
|
;;;###autoload
|
2003-06-14 20:11:37 +00:00
|
|
|
|
(defun copyright-update (&optional arg interactivep)
|
2002-01-13 20:17:46 +00:00
|
|
|
|
"Update copyright notice at beginning of buffer to indicate the current year.
|
|
|
|
|
With prefix ARG, replace the years in the notice rather than adding
|
|
|
|
|
the current year after them. If necessary, and
|
|
|
|
|
`copyright-current-gpl-version' is set, any copying permissions
|
2003-06-14 20:11:37 +00:00
|
|
|
|
following the copyright are updated as well.
|
|
|
|
|
If non-nil, INTERACTIVEP tells the function to behave as when it's called
|
|
|
|
|
interactively."
|
|
|
|
|
(interactive "*P\nd")
|
|
|
|
|
(when (or copyright-update interactivep)
|
|
|
|
|
(let ((noquery (or (not copyright-query)
|
|
|
|
|
(and (eq copyright-query 'function) interactivep))))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen)
|
|
|
|
|
(goto-char (point-min))
|
2003-06-14 20:11:37 +00:00
|
|
|
|
(copyright-update-year arg noquery)
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(and copyright-current-gpl-version
|
|
|
|
|
;; match the GPL version comment in .el files, including the
|
|
|
|
|
;; bilingual Esperanto one in two-column, and in texinfo.tex
|
2002-01-13 20:17:46 +00:00
|
|
|
|
(re-search-forward "\\(the Free Software Foundation;\
|
|
|
|
|
either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\
|
|
|
|
|
version \\([0-9]+\\), or (at"
|
2003-06-14 20:11:37 +00:00
|
|
|
|
(+ (point) copyright-limit) t)
|
2002-01-13 20:17:46 +00:00
|
|
|
|
(not (string= (match-string 3) copyright-current-gpl-version))
|
2003-06-14 20:11:37 +00:00
|
|
|
|
(or noquery
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(y-or-n-p (concat "Replace GPL version by "
|
|
|
|
|
copyright-current-gpl-version "? ")))
|
|
|
|
|
(progn
|
|
|
|
|
(if (match-end 2)
|
|
|
|
|
;; Esperanto bilingual comment in two-column.el
|
2003-06-14 20:11:37 +00:00
|
|
|
|
(replace-match copyright-current-gpl-version t t nil 2))
|
|
|
|
|
(replace-match copyright-current-gpl-version t t nil 3))))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(set (make-local-variable 'copyright-update) nil)))
|
2003-06-14 20:11:37 +00:00
|
|
|
|
;; If a write-file-hook returns non-nil, the file is presumed to be written.
|
|
|
|
|
nil))
|
1991-06-03 19:54:13 +00:00
|
|
|
|
|
1992-05-30 20:24:49 +00:00
|
|
|
|
|
1995-07-07 19:40:05 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(define-skeleton copyright
|
|
|
|
|
"Insert a copyright by $ORGANIZATION notice at cursor."
|
|
|
|
|
"Company: "
|
|
|
|
|
comment-start
|
2001-01-08 16:00:38 +00:00
|
|
|
|
"Copyright (C) " `(substring (current-time-string) -4) " by "
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(or (getenv "ORGANIZATION")
|
|
|
|
|
str)
|
2003-06-14 20:11:37 +00:00
|
|
|
|
'(if (> (point) (+ (point-min) copyright-limit))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(message "Copyright extends beyond `copyright-limit' and won't be updated automatically."))
|
2001-10-11 01:50:43 +00:00
|
|
|
|
comment-end \n)
|
1995-07-07 19:40:05 +00:00
|
|
|
|
|
1997-06-22 18:57:55 +00:00
|
|
|
|
(provide 'copyright)
|
|
|
|
|
|
2000-01-06 23:35:31 +00:00
|
|
|
|
;; For the copyright sign:
|
|
|
|
|
;; Local Variables:
|
|
|
|
|
;; coding: emacs-mule
|
|
|
|
|
;; End:
|
|
|
|
|
|
2003-09-01 15:45:59 +00:00
|
|
|
|
;;; arch-tag: b4991afb-b6b1-4590-bebe-e076d9d4aee8
|
2001-07-16 12:23:00 +00:00
|
|
|
|
;;; copyright.el ends here
|