3333; ; simple DSL which sets up temporary file hierarchies and runs the
3434; ; code in that new context (cf. `with-temp-buffer' )
3535
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:
3939; ;
40- ; ; M-x describe-function RET with-temp-fs RET
40+ ; ; M-x describe-function RET with-temp-filesystem RET
4141
4242; ;; Code:
4343
7373; ;;;;;;;;;;;;;;;;;;;
7474; ;; Mock file system
7575
76- (defun with-temp-fs --make-parent (spec path )
76+ (defun with-temp-filesystem --make-parent (spec path )
7777 " If SPEC is a file name, create its parent directory rooted at PATH."
7878 (save-match-data
7979 (string-match " \\ (.*\\ )/" spec)
8080 (when (match-string 1 spec)
8181 (make-directory (concat path " /" (match-string 1 spec)) t ))))
8282
83- (defun with-temp-fs --init (spec &optional path )
83+ (defun with-temp-filesystem --init (spec &optional path )
8484 " Interpret the SPEC inside PATH."
8585 (setq path (or path " ." ))
8686 (cond
9191 (stringp (cadr spec)))
9292 (when (string-match-p " /\\ '" (car spec))
9393 (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)
9595 (with-temp-file (concat path " /" (car spec))
9696 (insert (cadr spec))))
9797 ; ; directory
9898 ((and (stringp (car spec))
9999 (consp (cadr spec)))
100100 (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)))
102102 ; ; 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))))
104104 ; ; directory specified using a string
105105 ((and (stringp spec)
106106 (string-match-p " /\\ '" spec))
107107 (make-directory (concat path " /" spec) t ))
108108 ; ; empty file
109109 ((stringp spec)
110- (with-temp-fs --make-parent spec path)
110+ (with-temp-filesystem --make-parent spec path)
111111 (write-region " " nil (concat path " /" spec)))
112112 (t (error " Invalid syntax: `%s' " spec))))
113113
114- (defmacro with-temp-fs (spec &rest forms )
114+ (defmacro with-temp-filesystem (spec &rest forms )
115115 " Create temporary file hierarchy according to SPEC and run FORMS.
116116
117117SPEC is a list of specifications for file system entities which
@@ -146,7 +146,7 @@ An example showing all the possibilities:
146146If we want to run some code in a directory with an empty file
147147\" foo.txt\" present, we call:
148148
149- (with-temp-fs '(\" foo\" )
149+ (with-temp-filesystem '(\" foo\" )
150150 (code-here)
151151 (and-some-more-forms))
152152
@@ -162,7 +162,7 @@ for change."
162162 (unwind-protect
163163 (progn
164164 (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 )
166166 ,@forms )
167167 (delete-directory , temp-root t )
168168 (setq default-directory , old-dd )))))
0 commit comments