From c2e83dd729be41dd3b174d74084460673098c6c8 Mon Sep 17 00:00:00 2001 From: Javier Olaechea Date: Fri, 15 Aug 2014 14:09:09 -0500 Subject: [PATCH 1/3] current-directory not needed, use uiop instead Add setf expansion for getcwd --- src/packages.lisp | 2 ++ src/util.lisp | 29 ++++++++--------------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/packages.lisp b/src/packages.lisp index c6755a5..dd6dccd 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -7,6 +7,8 @@ (:import-from :cl-fad #:file-exists-p) (:import-from :closure-template #:compile-template) (:import-from :local-time #:format-rfc1123-timestring) + (:import-from :uiop #:getcwd + #:chdir) (:export #:main #:preview #:*config* diff --git a/src/util.lisp b/src/util.lisp index ebafe4e..b9c76a0 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -30,33 +30,20 @@ BODY on files that match the given extension." #',extension-p (constantly t)))))) +(defun (setf getcwd) (path) + "Change the operating system's current directory to PATH." + (chdir path) + path) + (defmacro with-current-directory (path &body body) "Change the current directory to PATH and execute BODY in an UNWIND-PROTECT, then change back to the current directory." (alexandria:with-gensyms (old) - `(let ((,old (current-directory))) + `(let ((,old (getcwd))) (unwind-protect (progn - (setf (current-directory) ,path) + (setf (getcwd) ,path) ,@body) - (setf (current-directory) ,old))))) - -(defun current-directory () - "Return the operating system's current directory." - #+sbcl (sb-posix:getcwd) - #+ccl (ccl:current-directory) - #+ecl (si:getcwd) - #+cmucl (unix:unix-current-directory) - #+clisp (ext:cd) - #-(or sbcl ccl ecl cmucl clisp) (error "Not implemented yet.")) - -(defun (setf current-directory) (path) - "Change the operating system's current directory to PATH." - #+sbcl (sb-posix:chdir path) - #+ccl (setf (ccl:current-directory) path) - #+ecl (si:chdir path) - #+cmucl (unix:unix-chdir (namestring path)) - #+clisp (ext:cd path) - #-(or sbcl ccl ecl cmucl clisp) (error "Not implemented yet.")) + (setf (getcwd) ,old))))) (defun exit () "Exit the lisp system returning a 0 status code." From 221a9cbe86cb216e23ce671ce36c7130cb1c9a8d Mon Sep 17 00:00:00 2001 From: Javier Olaechea Date: Sat, 16 Aug 2014 02:12:12 -0500 Subject: [PATCH 2/3] Make tags indices URL absolute --- themes/hyde/post.tmpl | 2 +- themes/readable/post.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/hyde/post.tmpl b/themes/hyde/post.tmpl index cebe759..8400fcb 100644 --- a/themes/hyde/post.tmpl +++ b/themes/hyde/post.tmpl @@ -6,7 +6,7 @@
{\n} {if $post.tags} Tagged as {foreach $tag in $post.tags} - {$tag.name}{nil} + {$tag.name}{nil} {if not isLast($tag)},{sp}{/if} {/foreach} {/if} diff --git a/themes/readable/post.tmpl b/themes/readable/post.tmpl index b655ce7..d2789ea 100644 --- a/themes/readable/post.tmpl +++ b/themes/readable/post.tmpl @@ -6,7 +6,7 @@

{if $post.tags} Tagged as {foreach $tag in $post.tags} - {$tag.name}{nil} + {$tag.name}{nil} {if not isLast($tag)},{sp}{/if} {/foreach} {/if} From 8304e6b74bd8a8ebac03ef0db9c78b49779ef08f Mon Sep 17 00:00:00 2001 From: Javier Olaechea Date: Sun, 17 Aug 2014 16:46:57 -0500 Subject: [PATCH 3/3] More robust directory changing - Doesn't fail when the directory is missing a trailing '/' - When directory doesn't exist it signals an informative condition. --- src/packages.lisp | 4 +++- src/util.lisp | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/packages.lisp b/src/packages.lisp index dd6dccd..a9a3786 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -8,7 +8,9 @@ (:import-from :closure-template #:compile-template) (:import-from :local-time #:format-rfc1123-timestring) (:import-from :uiop #:getcwd - #:chdir) + #:chdir + #:ensure-directory-pathname + #:directory-exists-p) (:export #:main #:preview #:*config* diff --git a/src/util.lisp b/src/util.lisp index b9c76a0..1811bde 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -30,9 +30,17 @@ BODY on files that match the given extension." #',extension-p (constantly t)))))) +(define-condition directory-does-not-exist (error) + ((directory :initarg dir :reader dir)) + (:report (lambda (c stream) + (format stream "The directory '~A' does not exist" (dir c))))) + (defun (setf getcwd) (path) "Change the operating system's current directory to PATH." - (chdir path) + (setf path (ensure-directory-pathname path)) + (or (and (directory-exists-p path) + (chdir path)) + (error 'directory-does-not-exist :dir path)) path) (defmacro with-current-directory (path &body body)