Skip to content

Commit

Permalink
Indirect through Quicklisp properly by default, plus minor enhancements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexstream committed Feb 23, 2012
1 parent d81907b commit 1f0c8e9
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 9 deletions.
36 changes: 36 additions & 0 deletions clhs-use-local.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;;;; Version: 0.3
;;;;
;;;; This file was installed by clhs (trivial ASDF wrapper), like this:
;;;; (clhs:install-clhs-use-local)
;;;;
;;;; Load this file from your ~/.emacs to use local CLHS, like this:
;;;; (load (expand-file-name "~/quicklisp/clhs-use-local.el") t)

(setq quicklisp-clhs-dist "quicklisp")

(setq quicklisp-clhs-base
(if load-file-name
(file-name-directory load-file-name)
(expand-file-name "~/quicklisp/")))

(defun quicklisp-clhs-file-contents (file)
(with-temp-buffer
(insert-file-contents file)
(buffer-string)))

(defun quicklisp-clhs-location-file ()
(concat quicklisp-clhs-base
"dists/"
quicklisp-clhs-dist
"/installed/systems/clhs.txt"))

(defun quicklisp-clhs-system-location ()
(let ((location-file (quicklisp-clhs-location-file)))
(when (file-exists-p location-file)
(let ((relative (quicklisp-slime-helper-file-contents location-file)))
(file-name-directory (concat quicklisp-clhs-base relative))))))

(setq common-lisp-hyperspec-root
(concat "file:"
(quicklisp-clhs-system-location)
"HyperSpec-7-0/HyperSpec/"))
2 changes: 1 addition & 1 deletion clhs.asd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Thin ASDF wrapper (excluding HyperSpec): Public Domain"
;; See the README file for a longer description.
:description "The HyperSpec-7-0 directory in this thin ASDF wrapper is a complete and unmodified copy of Lispworks' Common Lisp HyperSpec version 7.0 (referenced from <http://www.lispworks.com/documentation/common-lisp.html>). Redistribution of the HyperSpec is made with permission from LispWorks per the terms and restrictions set forth at <http://www.lispworks.com/documentation/HyperSpec/Front/Help.htm#Legal>. You may further redistribute the HyperSpec subject to the same terms and restrictions; consult the previous link for all details."

:version "0.2"
:version "0.3"
:serial cl:t
:components ((:module "HyperSpec-7-0")
(:file "package")
Expand Down
73 changes: 66 additions & 7 deletions main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,80 @@
(make-pathname :directory `(:relative ,@relative-directory))
system-directory))

(defun emacs-setup-form (&key (root (hyperspec-root)))
(format nil "(setq common-lisp-hyperspec-root~% \"file:~A\")"
(namestring root)))
(defun %copy-file (source destination
&key (if-source-does-not-exist :error)
(if-destination-exists :error))
(unless (and (eq if-destination-exists nil) (probe-file destination))
(let (buffer)
(with-open-file (in source
:direction :input
:element-type '(unsigned-byte 8)
:if-does-not-exist if-source-does-not-exist)
(unless in (return-from %copy-file))
(setf buffer (make-array (file-length in)
:element-type '(unsigned-byte 8)))
(read-sequence buffer in))
(when buffer
(with-open-file (out destination
:direction :output
:element-type '(unsigned-byte 8)
:if-exists if-destination-exists)
(unless out (return-from %copy-file))
(write-sequence buffer out)))
t)))

(defun print-emacs-setup-form (&key (root (hyperspec-root)))
(format t "~2&~A
(defun %default-clhs-use-local-directory ()
(make-pathname
:name nil :type nil
:defaults (merge-pathnames (make-pathname
:directory '(:relative "quicklisp"))
(user-homedir-pathname))))

(defun %clhs-use-local (directory)
(make-pathname :name "clhs-use-local" :type "el"
:defaults directory))

(defun install-clhs-use-local (&key if-exists
(verbose t)
(destination-directory
(%default-clhs-use-local-directory))
ensure-directories-exist-p)
(when ensure-directories-exist-p
(ensure-directories-exist destination-directory :verbose verbose))
(%copy-file (%clhs-use-local *system-directory*)
(%clhs-use-local destination-directory)
:if-destination-exists if-exists))

(defun emacs-setup-form (&key (root (hyperspec-root))
(indirect-through-quicklisp-p t))
(if indirect-through-quicklisp-p
"(load (expand-file-name \"~/quicklisp/clhs-use-local.el\") t)"
(format nil "(setq common-lisp-hyperspec-root~% \"file:~A\")"
(namestring root))))

(defun print-emacs-setup-form (&key (root (hyperspec-root))
((:indirect-through-quicklisp-p indirectp) t))
(when (and indirectp
(not (probe-file (%clhs-use-local
(%default-clhs-use-local-directory)))))
(format t "~
\~2&(Please run (clhs:install-clhs-use-local) in the (Common Lisp) REPL.
This will install clhs-use-local.el in your ~~/quicklisp/ directory.
The step below depends on this file.)~2%"))
(format t "~2&Make Emacs evaluate this form to browse the CLHS locally:
~A
Make Emacs evaluate the above form to browse the CLHS locally.
Use C-c C-d h make-instance RET to test if the change was successful.
If it was, then this will open your browser and the URL will begin with \"file:///\".
Put the form in your ~~/.emacs to persist the change for future sessions.
The README file has some further information.
\(Location: ~A)~2%"
(emacs-setup-form :root root)
(emacs-setup-form :root root
:indirect-through-quicklisp-p indirectp)
(make-pathname :name "README"
:defaults *system-directory*))
(values))
3 changes: 2 additions & 1 deletion package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#:*hyperspec-relative-directory*

#:hyperspec-root
#:emacs-setup-form
#:install-clhs-use-local
#:emacs-setup-form
#:print-emacs-setup-form))

0 comments on commit 1f0c8e9

Please sign in to comment.