-
Notifications
You must be signed in to change notification settings - Fork 5
/
remembered-filenames.lisp
61 lines (49 loc) · 1.96 KB
/
remembered-filenames.lisp
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
;; remembered-filenames.lispp -- convenience macros for remembering
;; prompted filenames
;;
;; DM/RAL 11/10
;; -------------------------------------------------------------
(in-package :um)
;; ----------------------------------------------------------
(defvar *remembered-filenames*
(make-hash-table))
(defun remember-filename (key fname)
(setf (gethash key *remembered-filenames*) fname))
(defun remembered-filename (key)
(gethash key *remembered-filenames*))
(defun do-with-remembered-filename (key init prompter fn)
(um:when-let (fname (or init (funcall prompter (remembered-filename key))))
(remember-filename key fname)
(funcall fn fname)))
(defmacro with-remembered-filename ((fname key &optional init) form &body body)
`(do-with-remembered-filename ,key ,init
(lambda (,fname)
(declare (ignorable ,fname))
,form)
(lambda (,fname)
(declare (ignorable ,fname))
,@body)))
#+:LISPWORKS
(editor:setup-indent "with-remembered-filename" 2)
;; ----------------------------------------------------------
(defvar *last-timestamp* nil)
(defvar *timestamp-index* 0)
(defun filename-timestamp-string ()
(let ((now (get-universal-time)))
(unless (eql now *last-timestamp*)
(setf *last-timestamp* now
*timestamp-index* 0))
(multiple-value-bind (ss mm hh dd mon yr)
(decode-universal-time now 0)
(format nil "~A~{~{~2,'0d~}-~}~d"
yr (list
(list mon dd)
(list hh mm ss))
(incf *timestamp-index*)))))
(defun add-timestamp-to-filename (fname)
(concatenate 'string
(pathname-name fname)
"-"
(filename-timestamp-string)
"."
(pathname-type fname)))