Skip to content

Instantly share code, notes, and snippets.

@fukamachi
Last active December 24, 2015 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fukamachi/6837386 to your computer and use it in GitHub Desktop.
Save fukamachi/6837386 to your computer and use it in GitHub Desktop.
Common Lisp script to open a HyperSpec HTML which corresponds to a specified symbol. (Works only with SBCL on Mac)
#!/usr/bin/env sbcl --script
;; -*- mode: common-lisp -*-
;; Usage:
;; clhs [SYMBOL]
(require 'asdf)
(defparameter *hyperspec-home*
(merge-pathnames "Dropbox/Documents/HyperSpec/" (user-homedir-pathname))
"Set a directory where HyperSpec HTML files are in."))
(defun find-clhs-file (target-symbol)
(let ((map-sym-file (merge-pathnames "Data/Map_Sym.txt" *hyperspec-home*)))
(with-open-file (in map-sym-file
:direction :input)
(loop with eof = '#:end-of-file
for symbol = (read-line in nil eof)
for file = (read-line in nil eof)
until (eq symbol eof)
when (string-equal symbol target-symbol)
do (return (merge-pathnames file map-sym-file))))))
(defun clhs (target-symbol)
(let ((file (find-clhs-file target-symbol)))
(if file
(progn
(format t "~&Opening ~A~%" file)
(asdf:run-shell-command "open ~A" file))
(format *error-output* "~&Symbol not found: ~A~%"
target-symbol))))
(let ((symbol (second sb-ext:*posix-argv*)))
(if symbol
(clhs symbol)
(format t "~&Usage: clhs [SYMBOL]~%")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment