-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpjb-asdf.el
More file actions
160 lines (146 loc) · 6.22 KB
/
Copy pathpjb-asdf.el
File metadata and controls
160 lines (146 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
;;;; -*- mode:emacs-lisp;coding:utf-8;lexical-binding:t -*-
;;;;**************************************************************************
;;;;FILE: pjb-asdf.el
;;;;LANGUAGE: emacs lisp
;;;;SYSTEM: POSIX
;;;;USER-INTERFACE: NONE
;;;;DESCRIPTION
;;;;
;;;; ASDF utilities.
;;;;
;;;;AUTHORS
;;;; <PJB> Pascal Bourguignon <pbourguignon@dxo.com>
;;;;MODIFICATIONS
;;;; 2023-08-03 <PJB> Created.
;;;;BUGS
;;;;LEGAL
;;;; AGPL3
;;;;
;;;; Copyright Pascal Bourguignon 2023 - 2023
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Affero General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program 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 Affero General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Affero General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;**************************************************************************
(require 'cl)
(defun goto-asdf-form ()
(interactive)
(goto-char (point-min))
(when (re-search-forward "^(\\(defsystem\\|asdf:defsystem\\) ")
(goto-char (match-beginning 0))))
(defun goto-asdf-version ()
(interactive)
(goto-asdf-form)
(forward-char)
(forward-sexp) (backward-sexp)
(while (not (looking-at ":version"))
(forward-sexp) (forward-sexp) (backward-sexp))
(forward-sexp) (forward-sexp) (backward-sexp))
(defun next-date-version (version)
"version is a list of 3 or 4 integers,
representing (YEAR MONTH DAY [INCREMENT]
If it's the current date, then the increment is added or augmented,
otherwise the current date is returned."
(let* ((date (nreverse (subseq (decode-time (current-time)) 3 6)))
(m (mismatch date version)))
(cond
((null m) ; same date, add a new increment
(nconc (subseq date 0 3) (list 1)))
((eql m 3) ; same date, increment
(nconc (subseq date 0 3) (list (+ (fourth version) 1))))
(t ; different date, reset it
date))))
(let* ((year (string-to-number (format-time-string "%Y")))
(month (string-to-number (format-time-string "%m")))
(day (string-to-number (format-time-string "%d")))
(current-date (list year month day)))
(assert (equal (list (next-date-version '(2012 12 31 0))
(next-date-version '(2012 12 31 12))
(next-date-version '(2012 12 31))
(next-date-version `(,year ,month ,day))
(next-date-version `(,year ,month ,day 12)))
(list current-date
current-date
current-date
(append current-date '(1))
(append current-date '(13))))))
(defun next-usual-version (version)
"version is a list of 1 or more integers,
we just increment the last one."
(nconc (subseq version 0 (1- (length version)))
(list (1+ (car (last version))))))
(assert (equal (list (next-usual-version '(1))
(next-usual-version '(1 2))
(next-usual-version '(1 2 3))
(next-usual-version '(1 2 3 4)))
'((2) (1 3) (1 2 4) (1 2 3 5))))
(defun bump-asdf-version ()
(interactive)
(goto-asdf-version)
(unless (looking-at "\"\\(\\([0-9]+\\.\\)*[0-9]+\\)\"")
(error "Not a valid ASDF version"))
(let* ((start (match-beginning 1))
(end (match-end 1))
(version (mapcar (lambda (item)
(car (read-from-string item)))
(split-string (buffer-substring start end) "\\.")))
(new-version (cond
((and (<= 3 (length version) 4)
(< 1990 (first version) 2100)
(<= 1 (second version) 12)
(<= 1 (third version) 31))
(next-date-version version))
(t
(next-usual-version version)))))
(delete-region start end)
(goto-char start)
(insert (mapconcat (function prin1-to-string) new-version "."))))
;; (defun pjb-bump-asdf-version (&optional vf)
;; "Bump the version in the asdf systems in the current buffer.
;; vf= 1 => increment the minor.
;; vf= 4 => increment the major.
;; vf=16 => increment the version.
;; "
;; (interactive "p")
;; (let* ((vf (or vf 1))
;; (field (case vf
;; ((1) 3)
;; ((4) 2)
;; ((16) 1)
;; (otherwse
;; (error "Invalid version field parameter %d, should be (member 1 4 16)"
;; vf))))
;; (fmt (case field
;; ((1) "%d.0.0")
;; ((2) "%d.0")
;; ((3) "%d"))))
;; (goto-char (point-min))
;; (while (re-search-forward ":version +\"\\([0-9]+\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\"" (point-max) t)
;; (replace-region (match-beginning field) (match-end 3)
;; (format fmt (1+ (let* ((s (match-string field))
;; (n (read s)))
;; (if (integerp n)
;; n
;; (error "Expected an integer, not %s" s)))))))))
;;
;; (defun pjb-bump-asdf-version-in-directory (vf &optional directory)
;; "Bumps the ASD system version in all asd files in the `directory' (recursively).
;; vf= 1 => increment the minor.
;; vf= 4 => increment the major.
;; vf=16 => increment the version.
;; "
;; (interactive "p\nDDirectory: ")
;; (process-all-files-in-directory (or directory default-directory)
;; "\\(\\.asd\\)$"
;; "Bumping version of asd systems"
;; (lambda ()
;; (pjb-bump-asdf-version vf))))