From: "Ulrich Müller" <ulm@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/emacs-tools:ebuild-mode commit in: /
Date: Tue, 28 Feb 2017 19:23:06 +0000 (UTC) [thread overview]
Message-ID: <1488309542.24a7808a9283f509980a57c1f94de28ad02ae266.ulm@gentoo> (raw)
commit: 24a7808a9283f509980a57c1f94de28ad02ae266
Author: Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 28 19:19:02 2017 +0000
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Tue Feb 28 19:19:02 2017 +0000
URL: https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=24a7808a
Update ebuild header, when customised to do so.
* ebuild-mode.el (ebuild-mode-update-copyright)
(ebuild-mode-delete-cvs-line): New custom variables, default to t.
(ebuild-mode-copyright-regexp, ebuild-mode-cvs-header-regexp):
New variables.
(ebuild-mode-update-copyright, ebuild-mode-delete-cvs-line):
New functions.
(ebuild-mode-before-save): Update copyright years and remove CVS
Id or Header line, when customised to do so, respectively.
ChangeLog | 11 +++++++++++
ebuild-mode.el | 46 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 285118d..4d8c0dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2017-02-28 Ulrich Müller <ulm@gentoo.org>
+
+ * ebuild-mode.el (ebuild-mode-update-copyright)
+ (ebuild-mode-delete-cvs-line): New custom variables, default to t.
+ (ebuild-mode-copyright-regexp, ebuild-mode-cvs-header-regexp):
+ New variables.
+ (ebuild-mode-update-copyright, ebuild-mode-delete-cvs-line):
+ New functions.
+ (ebuild-mode-before-save): Update copyright years and remove CVS
+ Id or Header line, when customised to do so, respectively.
+
2017-02-27 Ulrich Müller <ulm@gentoo.org>
* ebuild-mode.el (ebuild-mode): New customisation group.
diff --git a/ebuild-mode.el b/ebuild-mode.el
index 85491f8..f2c88df 100644
--- a/ebuild-mode.el
+++ b/ebuild-mode.el
@@ -76,6 +76,16 @@ of lines."
:type 'boolean
:group 'ebuild-mode)
+(defcustom ebuild-mode-update-copyright t
+ "If non-nil, update copyright years before writing a file."
+ :type 'boolean
+ :group 'ebuild-mode)
+
+(defcustom ebuild-mode-delete-cvs-line t
+ "If non-nil, delete any CVS $Id$ or $Header$ line before writing a file."
+ :type 'boolean
+ :group 'ebuild-mode)
+
;; Predicate function for comparison of architecture keywords
;; (needed for variable definitions below)
(defun ebuild-mode-arch-lessp (a b)
@@ -125,6 +135,12 @@ of lines."
(defvar ebuild-mode-arch-regexp
"^[ \t]*KEYWORDS=[\"']\\([^\"]*\\)[\"'][ \t]*$")
+(defvar ebuild-mode-copyright-regexp
+ "^#[ \t]*Copyright[ \t]+\\([1-9][0-9]+\\)-\\([1-9][0-9]+\\)[ \t]")
+
+(defvar ebuild-mode-cvs-header-regexp
+ "^#[ \t]*\\$\\(Id\\|Header\\)\\(: .*\\)?\\$[ \t]*$")
+
(defvar ebuild-mode-licenses
(condition-case nil
(directory-files (concat ebuild-mode-portdir "/licenses")
@@ -232,11 +248,39 @@ Optional argument LIMIT restarts collection after that number of elements."
(delete-region (match-beginning 0) (point))
(indent-to end-col)))))))
+(defun ebuild-mode-update-copyright ()
+ ;; Update copyright years
+ (save-excursion
+ (goto-char (point-min))
+ (let ((case-fold-search nil))
+ (if (re-search-forward ebuild-mode-copyright-regexp 400 t)
+ (let ((first-year (string-to-number (match-string 1)))
+ (last-year (string-to-number (match-string 2)))
+ (this-year-string (format-time-string "%Y")))
+ (if (and (<= 1999 first-year) ; only 2 args in GNU Emacs 23
+ (<= first-year last-year)
+ (<= last-year (string-to-number this-year-string)))
+ (replace-match this-year-string t t nil 2)
+ (lwarn 'ebuild-mode :warning
+ "Suspicious range of copyright years: %d-%d"
+ first-year last-year)))))))
+
+(defun ebuild-mode-delete-cvs-line ()
+ ;; Remove a CVS $Id$ or $Header$ line
+ (save-excursion
+ (goto-char (point-min))
+ (let ((case-fold-search nil))
+ (if (re-search-forward ebuild-mode-cvs-header-regexp 400 t)
+ (delete-region (match-beginning 0) (1+ (point)))))))
+
(defun ebuild-mode-before-save ()
(when ebuild-mode-fix-whitespace
(delete-trailing-whitespace)
(ebuild-mode-tabify))
- ;;(copyright-update) ; doesn't exist in XEmacs
+ (when ebuild-mode-update-copyright
+ (ebuild-mode-update-copyright))
+ (when ebuild-mode-delete-cvs-line
+ (ebuild-mode-delete-cvs-line))
;; return nil, otherwise the file is presumed to be written
nil)
next reply other threads:[~2017-02-28 19:24 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-28 19:23 Ulrich Müller [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-09-16 16:28 [gentoo-commits] proj/emacs-tools:ebuild-mode commit in: / Ulrich Müller
2017-09-16 15:28 Ulrich Müller
2017-09-16 15:28 Ulrich Müller
2017-04-07 18:33 Ulrich Müller
2017-04-07 18:33 Ulrich Müller
2017-04-07 17:11 Ulrich Müller
2017-04-07 17:11 Ulrich Müller
2017-04-07 17:11 Ulrich Müller
2017-03-31 5:28 Ulrich Müller
2017-03-17 16:38 Ulrich Müller
2017-03-09 9:51 Ulrich Müller
2017-03-09 9:51 Ulrich Müller
2017-03-06 7:33 Ulrich Müller
2017-03-06 7:33 Ulrich Müller
2017-03-05 17:51 Ulrich Müller
2017-03-05 17:51 Ulrich Müller
2017-03-05 17:51 Ulrich Müller
2017-03-05 17:51 Ulrich Müller
2017-02-28 19:33 Ulrich Müller
2017-02-28 19:23 Ulrich Müller
2017-02-28 19:23 Ulrich Müller
2017-02-28 19:23 Ulrich Müller
2017-02-28 19:23 Ulrich Müller
2017-02-28 19:23 Ulrich Müller
2017-02-28 19:23 Ulrich Müller
2017-02-28 19:23 Ulrich Müller
2016-06-19 19:57 Ulrich Müller
2016-06-19 19:57 Ulrich Müller
2016-06-08 6:48 Ulrich Müller
2016-06-08 6:48 Ulrich Müller
2016-05-07 9:45 Ulrich Müller
2016-05-07 9:45 Ulrich Müller
2016-05-07 9:45 Ulrich Müller
2016-05-07 9:45 Ulrich Müller
2015-12-20 13:53 Ulrich Müller
2015-12-20 13:53 Ulrich Müller
2015-12-20 13:53 Ulrich Müller
2015-12-20 13:53 Ulrich Müller
2015-08-23 14:48 Ulrich Müller
2015-08-23 14:48 Ulrich Müller
2015-08-09 18:34 Ulrich Müller
2015-08-09 18:34 Ulrich Müller
2014-11-18 9:55 Ulrich Müller
2014-11-16 23:13 Ulrich Müller
2014-11-16 23:13 Ulrich Müller
2014-02-02 11:57 Ulrich Müller
2014-01-25 14:17 Ulrich Müller
2014-01-25 14:17 Ulrich Müller
2014-01-23 14:49 Ulrich Müller
2014-01-22 22:43 Ulrich Müller
2014-01-22 22:43 Ulrich Müller
2014-01-22 22:43 Ulrich Müller
2013-10-09 23:49 Ulrich Müller
2013-09-18 6:53 Ulrich Mueller
2013-09-17 21:33 Ulrich Mueller
2013-09-17 21:33 Ulrich Mueller
2013-09-17 21:33 Ulrich Mueller
2013-09-08 10:49 Ulrich Mueller
2013-09-08 10:28 Ulrich Mueller
2013-09-08 10:28 Ulrich Mueller
2013-09-08 10:28 Ulrich Mueller
2013-09-08 10:28 Ulrich Mueller
2013-09-08 10:28 Ulrich Mueller
2013-07-06 23:09 Ulrich Mueller
2013-07-06 23:01 Ulrich Mueller
2013-07-06 22:52 Ulrich Mueller
2013-07-06 22:52 Ulrich Mueller
2013-07-06 22:03 Ulrich Mueller
2013-07-06 17:37 Ulrich Mueller
2013-07-06 17:37 Ulrich Mueller
2013-07-05 18:06 Ulrich Mueller
2013-07-05 18:06 Ulrich Mueller
2013-07-05 14:51 Ulrich Mueller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1488309542.24a7808a9283f509980a57c1f94de28ad02ae266.ulm@gentoo \
--to=ulm@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox