da50a6f2ab71ed6d7675024ed9fbb7402ba5bfdb
[profile] / dot / lisp-init.lisp
1 ;;; -*-lisp-*-
2
3 (cl:defpackage #:mdw-hacks
4 (:use #:cl))
5 (cl:defparameter mdw-hacks::*previous-package* cl:*package*)
6 (cl:in-package #:mdw-hacks)
7
8 ;; Shut up.
9 (setf *load-verbose* nil
10 *compile-verbose* nil)
11
12 #+cmu
13 (setf ext:*gc-verbose* nil
14 ext:*require-verbose* nil)
15
16 ;; Obtain ASDF from somewhere.
17 (require "asdf")
18
19 ;; Get CMU CL to quit on EOF.
20 #+cmu
21 (setf ext:*batch-mode* t)
22
23 ;; Tell SBCL where to find its source source.
24 #+sbcl
25 (sb-ext:set-sbcl-source-location #p"/usr/share/sbcl-source/")
26
27 ;; Tell some Lisps about my home directory.
28 #+(and unix (or sbcl clisp))
29 (let* ((homestring (or #+sbcl (sb-ext:posix-getenv "HOME")
30 #+clisp (ext:getenv "HOME")
31 #+cmu (unix:unix-getenv "HOME")
32 "/home/mdw"))
33 (home (pathname (concatenate 'string homestring "/"))))
34 (setf (logical-pathname-translations "HOME")
35 `(("HOME:**;*.*.*" ,(merge-pathnames "**/*.*" home nil)))
36 (logical-pathname-translations "CL")
37 '(("CL:SOURCE;**;*.*.*" #p"/usr/share/common-lisp/source/**/*.*")
38 ("CL:SYSTEMS;**;*.*.*" #p"/usr/share/common-lisp/systems/**/*.*"))))
39
40 ;; Various fixings.
41 #+clisp
42 (setf custom:*parse-namestring-ansi* t)
43
44 ;; CLisp history.
45 #+(and clisp readline)
46 (progn
47 (export '(*history-file* *history-size*))
48 (defvar *history-file* (format nil "~A/.clisp-history" (ext:getenv "HOME"))
49 "File to preserve the REPL history.")
50 (defvar *history-size* 1000)
51 (unless (and (probe-file *history-file*) nil)
52 (let (old-umask stream)
53 ;; Ugh. There's no proper open(2) veneer. Play with umask(2) to avoid
54 ;; a window in which an adversary can open the file.
55 (unwind-protect
56 (setf old-umask (os:umask #o077)
57 stream (open *history-file*
58 :direction :output
59 :if-exists :overwrite
60 :if-does-not-exist :create))
61 (when stream (close stream))
62 (when old-umask (os:umask old-umask)))))
63 (readline:read-history *history-file*)
64 (if *history-size* (readline:stifle-history *history-size*)
65 (readline:unstifle-history))
66 (push (lambda () (readline:write-history *history-file*))
67 custom:*fini-hooks*))
68
69 ;; Shebang.
70 (set-dispatch-macro-character
71 #\# #\!
72 (lambda (stream char arg)
73 (declare (ignore char arg))
74 (values (read-line stream))))
75
76 ;; Start up swank.
77 (export 'crank-swank)
78 (defun crank-swank (&rest args)
79 (let ((swank (find-package "SWANK")))
80 (unless swank
81 (load "/usr/share/common-lisp/source/slime/swank-loader.lisp")
82 (funcall (find-symbol "INIT" (find-package "SWANK-LOADER")))
83 (setf swank (find-package "SWANK")))
84 (set (find-symbol "*GLOBAL-DEBUGGER*" swank) nil)
85 (apply (find-symbol "CREATE-SERVER" swank) args)))
86
87 ;; Treat warnings as, err, warnings.
88 #+asdf
89 (setf asdf:*compile-file-failure-behaviour* :warn)
90
91 ;; Done.
92 (pushnew :mdw *features*)
93 ;;#+(and cmu mp) (mp::startup-idle-and-top-level-loops)
94 (setf *package* *previous-package*)