diff options
| author | Glenn Morris | 2008-04-22 02:54:32 +0000 |
|---|---|---|
| committer | Glenn Morris | 2008-04-22 02:54:32 +0000 |
| commit | b2c7c56d5793fa4099f60acf3e697540deb0cc9b (patch) | |
| tree | ad2c7772ed04da2ffdc8e9e4cb20ebf2de76e22a | |
| parent | 743deb5daf81efc6f494980dff897406fc6a3eb3 (diff) | |
| download | emacs-b2c7c56d5793fa4099f60acf3e697540deb0cc9b.tar.gz emacs-b2c7c56d5793fa4099f60acf3e697540deb0cc9b.zip | |
(copyright-at-end-flag): New option.
(copyright-limit): Respect copyright-at-end-flag.
(copyright-re-search, copyright-start-point)
(copyright-offset-too-large-p): New functions.
(copyright-update-year): Use copyright-re-search.
(copyright-update, copyright-fix-years): Use copyright-start-point,
and copyright-re-search.
(copyright): Use copyright-offset-too-large-p.
| -rw-r--r-- | lisp/emacs-lisp/copyright.el | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el index 910ac9eaa23..5ab50847f8c 100644 --- a/lisp/emacs-lisp/copyright.el +++ b/lisp/emacs-lisp/copyright.el | |||
| @@ -43,6 +43,13 @@ A value of nil means to search whole buffer." | |||
| 43 | :type '(choice (integer :tag "Limit") | 43 | :type '(choice (integer :tag "Limit") |
| 44 | (const :tag "No limit"))) | 44 | (const :tag "No limit"))) |
| 45 | 45 | ||
| 46 | (defcustom copyright-at-end-flag nil | ||
| 47 | "Non-nil means to search backwards from the end of the buffer for copyright. | ||
| 48 | This is useful for ChangeLogs." | ||
| 49 | :group 'copyright | ||
| 50 | :type 'boolean | ||
| 51 | :version "23.1") | ||
| 52 | |||
| 46 | (defcustom copyright-regexp | 53 | (defcustom copyright-regexp |
| 47 | "\\(©\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\ | 54 | "\\(©\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\ |
| 48 | \\|[Cc]opyright\\s *:?\\s *©\\)\ | 55 | \\|[Cc]opyright\\s *:?\\s *©\\)\ |
| @@ -89,18 +96,40 @@ When this is `function', only ask when called non-interactively." | |||
| 89 | "String representing the current year.") | 96 | "String representing the current year.") |
| 90 | 97 | ||
| 91 | (defsubst copyright-limit () ; re-search-forward BOUND | 98 | (defsubst copyright-limit () ; re-search-forward BOUND |
| 92 | (and copyright-limit (+ (point) copyright-limit))) | 99 | (and copyright-limit |
| 100 | (if copyright-at-end-flag | ||
| 101 | (- (point) copyright-limit) | ||
| 102 | (+ (point) copyright-limit)))) | ||
| 103 | |||
| 104 | (defun copyright-re-search (regexp &optional bound noerror count) | ||
| 105 | "Re-search forward or backward depending on `copyright-at-end-flag'." | ||
| 106 | (if copyright-at-end-flag | ||
| 107 | (re-search-backward regexp bound noerror count) | ||
| 108 | (re-search-forward regexp bound noerror count))) | ||
| 109 | |||
| 110 | (defun copyright-start-point () | ||
| 111 | "Return point-min or point-max, depending on `copyright-at-end-flag'." | ||
| 112 | (if copyright-at-end-flag | ||
| 113 | (point-max) | ||
| 114 | (point-min))) | ||
| 115 | |||
| 116 | (defun copyright-offset-too-large-p () | ||
| 117 | "Return non-nil if point is too far from the edge of the buffer." | ||
| 118 | (when copyright-limit | ||
| 119 | (if copyright-at-end-flag | ||
| 120 | (< (point) (- (point-max) copyright-limit)) | ||
| 121 | (> (point) (+ (point-min) copyright-limit))))) | ||
| 93 | 122 | ||
| 94 | (defun copyright-update-year (replace noquery) | 123 | (defun copyright-update-year (replace noquery) |
| 95 | (when | 124 | (when |
| 96 | (condition-case err | 125 | (condition-case err |
| 97 | ;; (1) Need the extra \\( \\) around copyright-regexp because we | 126 | ;; (1) Need the extra \\( \\) around copyright-regexp because we |
| 98 | ;; goto (match-end 1) below. See note (2) below. | 127 | ;; goto (match-end 1) below. See note (2) below. |
| 99 | (re-search-forward (concat "\\(" copyright-regexp | 128 | (copyright-re-search (concat "\\(" copyright-regexp |
| 100 | "\\)\\([ \t]*\n\\)?.*\\(?:" | 129 | "\\)\\([ \t]*\n\\)?.*\\(?:" |
| 101 | copyright-names-regexp "\\)") | 130 | copyright-names-regexp "\\)") |
| 102 | (copyright-limit) | 131 | (copyright-limit) |
| 103 | t) | 132 | t) |
| 104 | ;; In case the regexp is rejected. This is useful because | 133 | ;; In case the regexp is rejected. This is useful because |
| 105 | ;; copyright-update is typically called from before-save-hook where | 134 | ;; copyright-update is typically called from before-save-hook where |
| 106 | ;; such an error is very inconvenient for the user. | 135 | ;; such an error is very inconvenient for the user. |
| @@ -176,13 +205,13 @@ interactively." | |||
| 176 | (save-excursion | 205 | (save-excursion |
| 177 | (save-restriction | 206 | (save-restriction |
| 178 | (widen) | 207 | (widen) |
| 179 | (goto-char (point-min)) | 208 | (goto-char (copyright-start-point)) |
| 180 | (copyright-update-year arg noquery) | 209 | (copyright-update-year arg noquery) |
| 181 | (goto-char (point-min)) | 210 | (goto-char (copyright-start-point)) |
| 182 | (and copyright-current-gpl-version | 211 | (and copyright-current-gpl-version |
| 183 | ;; match the GPL version comment in .el files, including the | 212 | ;; match the GPL version comment in .el files, including the |
| 184 | ;; bilingual Esperanto one in two-column, and in texinfo.tex | 213 | ;; bilingual Esperanto one in two-column, and in texinfo.tex |
| 185 | (re-search-forward | 214 | (copyright-re-search |
| 186 | "\\(the Free Software Foundation;\ | 215 | "\\(the Free Software Foundation;\ |
| 187 | either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\ | 216 | either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\ |
| 188 | version \\([0-9]+\\), or (at" | 217 | version \\([0-9]+\\), or (at" |
| @@ -210,8 +239,8 @@ version \\([0-9]+\\), or (at" | |||
| 210 | Uses heuristic: year >= 50 means 19xx, < 50 means 20xx." | 239 | Uses heuristic: year >= 50 means 19xx, < 50 means 20xx." |
| 211 | (interactive) | 240 | (interactive) |
| 212 | (widen) | 241 | (widen) |
| 213 | (goto-char (point-min)) | 242 | (goto-char (copyright-start-point)) |
| 214 | (if (re-search-forward copyright-regexp (copyright-limit) t) | 243 | (if (copyright-re-search copyright-regexp (copyright-limit) t) |
| 215 | (let ((s (match-beginning 2)) | 244 | (let ((s (match-beginning 2)) |
| 216 | (e (copy-marker (1+ (match-end 2)))) | 245 | (e (copy-marker (1+ (match-end 2)))) |
| 217 | (p (make-marker)) | 246 | (p (make-marker)) |
| @@ -235,7 +264,7 @@ Uses heuristic: year >= 50 means 19xx, < 50 means 20xx." | |||
| 235 | ;; Don't mess up whitespace after the years. | 264 | ;; Don't mess up whitespace after the years. |
| 236 | (skip-chars-backward " \t") | 265 | (skip-chars-backward " \t") |
| 237 | (save-restriction | 266 | (save-restriction |
| 238 | (narrow-to-region (point-min) (point)) | 267 | (narrow-to-region (copyright-start-point) (point)) |
| 239 | (let ((fill-prefix " ")) | 268 | (let ((fill-prefix " ")) |
| 240 | (fill-region s last)))) | 269 | (fill-region s last)))) |
| 241 | (set-marker e nil) | 270 | (set-marker e nil) |
| @@ -251,7 +280,7 @@ Uses heuristic: year >= 50 means 19xx, < 50 means 20xx." | |||
| 251 | "Copyright (C) " `(substring (current-time-string) -4) " by " | 280 | "Copyright (C) " `(substring (current-time-string) -4) " by " |
| 252 | (or (getenv "ORGANIZATION") | 281 | (or (getenv "ORGANIZATION") |
| 253 | str) | 282 | str) |
| 254 | '(if (and copyright-limit (> (point) (+ (point-min) copyright-limit))) | 283 | '(if (copyright-offset-too-large-p) |
| 255 | (message "Copyright extends beyond `copyright-limit' and won't be updated automatically.")) | 284 | (message "Copyright extends beyond `copyright-limit' and won't be updated automatically.")) |
| 256 | comment-end \n) | 285 | comment-end \n) |
| 257 | 286 | ||