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
|
|
|
|
|
1998-04-18 17:09:18 +00:00
|
|
|
|
;; Copyright (C) 1991, 92, 93, 94, 95, 1998 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
|
|
|
|
|
;; or when saving a file. Do (add-hook 'write-file-hooks 'copyright-update).
|
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.
|
1998-04-01 10:44:40 +00:00
|
|
|
|
`nil' means to search whole buffer."
|
|
|
|
|
:group 'copyright
|
|
|
|
|
:type '(choice (integer :tag "Limit")
|
|
|
|
|
(const :tag "No limit")))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
|
2000-01-06 23:35:31 +00:00
|
|
|
|
;; Cleaner to specify Latin-1 coding for this file, and not use both
|
|
|
|
|
;; unibyte and multibyte copyright symbol characters?
|
1998-04-01 10:44:40 +00:00
|
|
|
|
(defcustom copyright-regexp
|
1998-04-24 20:58:03 +00:00
|
|
|
|
"\\([\251<EFBFBD><EFBFBD>]\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *(C)\
|
|
|
|
|
\\|[Cc]opyright\\s *:?\\s *[\251<EFBFBD><EFBFBD>]\\)\
|
2000-01-14 22:42:11 +00:00
|
|
|
|
\\s *\\([1-9][-0-9, ']*[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
|
1995-07-07 19:40:05 +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"
|
|
|
|
|
"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.
|
|
|
|
|
(defvar copyright-current-year "2001"
|
|
|
|
|
"String representing the current year.")
|
|
|
|
|
|
|
|
|
|
|
1991-06-03 19:54:13 +00:00
|
|
|
|
;;;###autoload
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(defun copyright-update (&optional arg)
|
|
|
|
|
"Update the copyright notice at the beginning of the buffer to indicate
|
|
|
|
|
the current year. If optional prefix ARG is given replace the years in the
|
|
|
|
|
notice rather than adding the current year after them. If necessary and
|
|
|
|
|
`copyright-current-gpl-version' is set, the copying permissions following the
|
|
|
|
|
copyright, if any, are updated as well."
|
1991-06-03 19:54:13 +00:00
|
|
|
|
(interactive "*P")
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(if copyright-update
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(widen)
|
|
|
|
|
(goto-char (point-min))
|
2001-01-08 16:00:38 +00:00
|
|
|
|
(setq copyright-current-year (substring (current-time-string) -4))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(if (re-search-forward copyright-regexp copyright-limit t)
|
1995-12-03 20:43:00 +00:00
|
|
|
|
(if (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
|
1995-07-07 19:40:05 +00:00
|
|
|
|
(substring copyright-current-year -2))
|
|
|
|
|
()
|
|
|
|
|
(if (or (not copyright-query)
|
|
|
|
|
(and (eq copyright-query 'function)
|
|
|
|
|
(eq this-command 'copyright-update))
|
|
|
|
|
(y-or-n-p (if arg
|
|
|
|
|
(concat "Replace copyright year(s) by "
|
|
|
|
|
copyright-current-year "? ")
|
|
|
|
|
(concat "Add " copyright-current-year
|
|
|
|
|
" to copyright? "))))
|
|
|
|
|
(if arg
|
|
|
|
|
(progn
|
|
|
|
|
(delete-region (match-beginning 1) (match-end 1))
|
|
|
|
|
(insert copyright-current-year))
|
|
|
|
|
(setq arg (save-excursion (skip-chars-backward "0-9")))
|
|
|
|
|
(if (and (eq (% (- (string-to-number
|
|
|
|
|
copyright-current-year)
|
|
|
|
|
(string-to-number (buffer-substring
|
|
|
|
|
(+ (point) arg)
|
|
|
|
|
(point))))
|
|
|
|
|
100)
|
|
|
|
|
1)
|
|
|
|
|
(or (eq (char-after (+ (point) arg -1)) ?-)
|
|
|
|
|
(eq (char-after (+ (point) arg -2)) ?-)))
|
|
|
|
|
(delete-char arg)
|
|
|
|
|
(insert ", ")
|
|
|
|
|
(if (eq (char-after (+ (point) arg -3)) ?')
|
|
|
|
|
(insert ?')))
|
|
|
|
|
(insert (substring copyright-current-year arg))))))
|
|
|
|
|
(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
|
|
|
|
|
(re-search-forward "\\(the Free Software Foundation; either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)version \\([0-9]+\\), or (at"
|
|
|
|
|
copyright-limit t)
|
|
|
|
|
(not (string= (buffer-substring (match-beginning 3) (match-end 3))
|
|
|
|
|
copyright-current-gpl-version))
|
|
|
|
|
(or (not copyright-query)
|
|
|
|
|
(and (eq copyright-query 'function)
|
|
|
|
|
(eq this-command 'copyright-update))
|
|
|
|
|
(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
|
|
|
|
|
(progn
|
|
|
|
|
(delete-region (match-beginning 2) (match-end 2))
|
|
|
|
|
(goto-char (match-beginning 2))
|
|
|
|
|
(insert copyright-current-gpl-version)))
|
|
|
|
|
(delete-region (match-beginning 3) (match-end 3))
|
|
|
|
|
(goto-char (match-beginning 3))
|
|
|
|
|
(insert copyright-current-gpl-version))))
|
|
|
|
|
(set (make-local-variable 'copyright-update) nil)))
|
|
|
|
|
;; If a write-file-hook returns non-nil, the file is presumed to be written.
|
1992-03-16 06:13:09 +00:00
|
|
|
|
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)
|
|
|
|
|
'(if (> (point) copyright-limit)
|
|
|
|
|
(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:
|
|
|
|
|
|
2001-07-16 12:23:00 +00:00
|
|
|
|
;;; copyright.el ends here
|