Gentoo Archives: gentoo-commits

From: "Ulrich Müller" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/emacs-tools:ebuild-mode commit in: /
Date: Tue, 28 Feb 2017 19:24:17
Message-Id: 1488309542.24a7808a9283f509980a57c1f94de28ad02ae266.ulm@gentoo
1 commit: 24a7808a9283f509980a57c1f94de28ad02ae266
2 Author: Ulrich Müller <ulm <AT> gentoo <DOT> org>
3 AuthorDate: Tue Feb 28 19:19:02 2017 +0000
4 Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
5 CommitDate: Tue Feb 28 19:19:02 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=24a7808a
7
8 Update ebuild header, when customised to do so.
9
10 * ebuild-mode.el (ebuild-mode-update-copyright)
11 (ebuild-mode-delete-cvs-line): New custom variables, default to t.
12 (ebuild-mode-copyright-regexp, ebuild-mode-cvs-header-regexp):
13 New variables.
14 (ebuild-mode-update-copyright, ebuild-mode-delete-cvs-line):
15 New functions.
16 (ebuild-mode-before-save): Update copyright years and remove CVS
17 Id or Header line, when customised to do so, respectively.
18
19 ChangeLog | 11 +++++++++++
20 ebuild-mode.el | 46 +++++++++++++++++++++++++++++++++++++++++++++-
21 2 files changed, 56 insertions(+), 1 deletion(-)
22
23 diff --git a/ChangeLog b/ChangeLog
24 index 285118d..4d8c0dd 100644
25 --- a/ChangeLog
26 +++ b/ChangeLog
27 @@ -1,3 +1,14 @@
28 +2017-02-28 Ulrich Müller <ulm@g.o>
29 +
30 + * ebuild-mode.el (ebuild-mode-update-copyright)
31 + (ebuild-mode-delete-cvs-line): New custom variables, default to t.
32 + (ebuild-mode-copyright-regexp, ebuild-mode-cvs-header-regexp):
33 + New variables.
34 + (ebuild-mode-update-copyright, ebuild-mode-delete-cvs-line):
35 + New functions.
36 + (ebuild-mode-before-save): Update copyright years and remove CVS
37 + Id or Header line, when customised to do so, respectively.
38 +
39 2017-02-27 Ulrich Müller <ulm@g.o>
40
41 * ebuild-mode.el (ebuild-mode): New customisation group.
42
43 diff --git a/ebuild-mode.el b/ebuild-mode.el
44 index 85491f8..f2c88df 100644
45 --- a/ebuild-mode.el
46 +++ b/ebuild-mode.el
47 @@ -76,6 +76,16 @@ of lines."
48 :type 'boolean
49 :group 'ebuild-mode)
50
51 +(defcustom ebuild-mode-update-copyright t
52 + "If non-nil, update copyright years before writing a file."
53 + :type 'boolean
54 + :group 'ebuild-mode)
55 +
56 +(defcustom ebuild-mode-delete-cvs-line t
57 + "If non-nil, delete any CVS $Id$ or $Header$ line before writing a file."
58 + :type 'boolean
59 + :group 'ebuild-mode)
60 +
61 ;; Predicate function for comparison of architecture keywords
62 ;; (needed for variable definitions below)
63 (defun ebuild-mode-arch-lessp (a b)
64 @@ -125,6 +135,12 @@ of lines."
65 (defvar ebuild-mode-arch-regexp
66 "^[ \t]*KEYWORDS=[\"']\\([^\"]*\\)[\"'][ \t]*$")
67
68 +(defvar ebuild-mode-copyright-regexp
69 + "^#[ \t]*Copyright[ \t]+\\([1-9][0-9]+\\)-\\([1-9][0-9]+\\)[ \t]")
70 +
71 +(defvar ebuild-mode-cvs-header-regexp
72 + "^#[ \t]*\\$\\(Id\\|Header\\)\\(: .*\\)?\\$[ \t]*$")
73 +
74 (defvar ebuild-mode-licenses
75 (condition-case nil
76 (directory-files (concat ebuild-mode-portdir "/licenses")
77 @@ -232,11 +248,39 @@ Optional argument LIMIT restarts collection after that number of elements."
78 (delete-region (match-beginning 0) (point))
79 (indent-to end-col)))))))
80
81 +(defun ebuild-mode-update-copyright ()
82 + ;; Update copyright years
83 + (save-excursion
84 + (goto-char (point-min))
85 + (let ((case-fold-search nil))
86 + (if (re-search-forward ebuild-mode-copyright-regexp 400 t)
87 + (let ((first-year (string-to-number (match-string 1)))
88 + (last-year (string-to-number (match-string 2)))
89 + (this-year-string (format-time-string "%Y")))
90 + (if (and (<= 1999 first-year) ; only 2 args in GNU Emacs 23
91 + (<= first-year last-year)
92 + (<= last-year (string-to-number this-year-string)))
93 + (replace-match this-year-string t t nil 2)
94 + (lwarn 'ebuild-mode :warning
95 + "Suspicious range of copyright years: %d-%d"
96 + first-year last-year)))))))
97 +
98 +(defun ebuild-mode-delete-cvs-line ()
99 + ;; Remove a CVS $Id$ or $Header$ line
100 + (save-excursion
101 + (goto-char (point-min))
102 + (let ((case-fold-search nil))
103 + (if (re-search-forward ebuild-mode-cvs-header-regexp 400 t)
104 + (delete-region (match-beginning 0) (1+ (point)))))))
105 +
106 (defun ebuild-mode-before-save ()
107 (when ebuild-mode-fix-whitespace
108 (delete-trailing-whitespace)
109 (ebuild-mode-tabify))
110 - ;;(copyright-update) ; doesn't exist in XEmacs
111 + (when ebuild-mode-update-copyright
112 + (ebuild-mode-update-copyright))
113 + (when ebuild-mode-delete-cvs-line
114 + (ebuild-mode-delete-cvs-line))
115 ;; return nil, otherwise the file is presumed to be written
116 nil)