From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id E56C7139694 for ; Tue, 28 Feb 2017 19:24:17 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3E85AE0D34; Tue, 28 Feb 2017 19:23:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0B996E0D34 for ; Tue, 28 Feb 2017 19:23:11 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EE04E34164A for ; Tue, 28 Feb 2017 19:23:09 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 7D96257DA for ; Tue, 28 Feb 2017 19:23:06 +0000 (UTC) From: "Ulrich Müller" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" Message-ID: <1488309542.24a7808a9283f509980a57c1f94de28ad02ae266.ulm@gentoo> Subject: [gentoo-commits] proj/emacs-tools:ebuild-mode commit in: / X-VCS-Repository: proj/emacs-tools X-VCS-Files: ChangeLog ebuild-mode.el X-VCS-Directories: / X-VCS-Committer: ulm X-VCS-Committer-Name: Ulrich Müller X-VCS-Revision: 24a7808a9283f509980a57c1f94de28ad02ae266 X-VCS-Branch: ebuild-mode Date: Tue, 28 Feb 2017 19:23:06 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c436a491-b3e3-4c98-96b9-8e725bd3218b X-Archives-Hash: 66e1c8c8f8424f346f71086b6c6a45e7 commit: 24a7808a9283f509980a57c1f94de28ad02ae266 Author: Ulrich Müller gentoo org> AuthorDate: Tue Feb 28 19:19:02 2017 +0000 Commit: Ulrich Müller gentoo 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 + + * 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 * 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)