Re: useful code snippet
Russell McManus <russell_mcmanus <at> yahoo.com>
2005-06-05 17:42:00 GMT
Christophe Rhodes <csr21 <at> cam.ac.uk> writes:
> Russell McManus <russell_mcmanus <at> yahoo.com> writes:
>
>> While writing some code using run-program, I came upon the need for
>> the following:
>>
>> (defmacro with-current-directory ((new-dir) &body body)
>> (let ((start (gensym)))
>> `(let ((,start (sb-unix:posix-getcwd)))
>> (unless (char= #\\ (aref ,start (1- (length ,start))))
>> (setf ,start (concatenate 'string ,start "/")))
>> (setf ,start (parse-namestring ,start))
>> (unwind-protect
>> (progn
>> (sb-posix:chdir ,new-dir)
>> , <at> body)
>> (sb-posix:chdir ,start)))))
>>
>> Is there an already existing way to do this sort of thing?
>
> No. There is at least a plausible argument that RUN-PROGRAM should
> respect *DEFAULT-PATHNAME-DEFAULTS* by chdir()ing to the directory
> component, which would allow the user to request a different directory
> for run-program simply by binding it. On the other hand, RUN-PROGRAM
> is already a deeply scary mess of options, and adding another doesn't
> really appeal...
I agree about *DEFAULT-PATHNAME-DEFAULTS*, and indeed I tried this
first, hoping that it would "just work". I would be willing the
(Continue reading)