33
33
; ; simple DSL which sets up temporary file hierarchies and runs the
34
34
; ; code in that new context (cf. `with-temp-buffer' )
35
35
36
- ; ; The entry point is `with-temp-fs ' which as first argument accepts
37
- ; ; the specification and then variable number of forms (i.e. "body").
38
- ; ; To see the documentation of the DSL call:
36
+ ; ; The entry point is `with-temp-filesystem ' which as first argument
37
+ ; ; accepts the specification and then variable number of forms
38
+ ; ; (i.e. "body"). To see the documentation of the DSL call:
39
39
; ;
40
- ; ; M-x describe-function RET with-temp-fs RET
40
+ ; ; M-x describe-function RET with-temp-filesystem RET
41
41
42
42
; ;; Code:
43
43
73
73
; ;;;;;;;;;;;;;;;;;;;
74
74
; ;; Mock file system
75
75
76
- (defun with-temp-fs --make-parent (spec path )
76
+ (defun with-temp-filesystem --make-parent (spec path )
77
77
" If SPEC is a file name, create its parent directory rooted at PATH."
78
78
(save-match-data
79
79
(string-match " \\ (.*\\ )/" spec)
80
80
(when (match-string 1 spec)
81
81
(make-directory (concat path " /" (match-string 1 spec)) t ))))
82
82
83
- (defun with-temp-fs --init (spec &optional path )
83
+ (defun with-temp-filesystem --init (spec &optional path )
84
84
" Interpret the SPEC inside PATH."
85
85
(setq path (or path " ." ))
86
86
(cond
91
91
(stringp (cadr spec)))
92
92
(when (string-match-p " /\\ '" (car spec))
93
93
(error " Invalid syntax: `%s' - cannot create a directory with text content " (car spec)))
94
- (with-temp-fs --make-parent (car spec) path)
94
+ (with-temp-filesystem --make-parent (car spec) path)
95
95
(with-temp-file (concat path " /" (car spec))
96
96
(insert (cadr spec))))
97
97
; ; directory
98
98
((and (stringp (car spec))
99
99
(consp (cadr spec)))
100
100
(make-directory (concat path " /" (car spec)) t )
101
- (mapc (lambda (s ) (with-temp-fs --init s (concat path " /" (car spec)))) (cadr spec)))
101
+ (mapc (lambda (s ) (with-temp-filesystem --init s (concat path " /" (car spec)))) (cadr spec)))
102
102
; ; recursive spec, this should probably never happen
103
- (t (mapc (lambda (s ) (with-temp-fs --init s path)) spec))))
103
+ (t (mapc (lambda (s ) (with-temp-filesystem --init s path)) spec))))
104
104
; ; directory specified using a string
105
105
((and (stringp spec)
106
106
(string-match-p " /\\ '" spec))
107
107
(make-directory (concat path " /" spec) t ))
108
108
; ; empty file
109
109
((stringp spec)
110
- (with-temp-fs --make-parent spec path)
110
+ (with-temp-filesystem --make-parent spec path)
111
111
(write-region " " nil (concat path " /" spec)))
112
112
(t (error " Invalid syntax: `%s' " spec))))
113
113
114
- (defmacro with-temp-fs (spec &rest forms )
114
+ (defmacro with-temp-filesystem (spec &rest forms )
115
115
" Create temporary file hierarchy according to SPEC and run FORMS.
116
116
117
117
SPEC is a list of specifications for file system entities which
@@ -146,7 +146,7 @@ An example showing all the possibilities:
146
146
If we want to run some code in a directory with an empty file
147
147
\" foo.txt\" present, we call:
148
148
149
- (with-temp-fs '(\" foo\" )
149
+ (with-temp-filesystem '(\" foo\" )
150
150
(code-here)
151
151
(and-some-more-forms))
152
152
@@ -162,7 +162,7 @@ for change."
162
162
(unwind-protect
163
163
(progn
164
164
(setq default-directory , temp-root )
165
- (mapc (lambda (s ) (with-temp-fs --init s " ." )) , spec )
165
+ (mapc (lambda (s ) (with-temp-filesystem --init s " ." )) , spec )
166
166
,@forms )
167
167
(delete-directory , temp-root t )
168
168
(setq default-directory , old-dd )))))
0 commit comments