0447d1ec509ba3c5e5b233347f6c59419babe182
[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 #+ecl
17 (let ((old-output *standard-output*)
18 (old-prompt si:*tpl-prompt-hook*))
19 ;; There doesn't seem to be a good way to do this, so we do it the bad
20 ;; way. Since the herald is printed to `*standard-outout*', we set (not
21 ;; bind!) that to a bit bucket, and then arrange to restore it just before
22 ;; the first REPL prompt is written.
23 ;;
24 ;; One more awful part is that, having intercepted the prompt hook, I need
25 ;; to restore and invoke the old version, and there isn't a clean way to do
26 ;; this.
27 (when (<= (ext:argc) 1)
28 (setf *standard-output* (make-broadcast-stream)
29 si:*tpl-prompt-hook* (lambda ()
30 (setf *standard-output* old-output
31 si:*tpl-prompt-hook* old-prompt)
32 (si::tpl-prompt)))))
33
34 #+ccl
35 (setf ccl::*inhibit-greeting* t)
36
37 ;; Obtain ASDF from somewhere.
38 (require "asdf")
39
40 ;; Get CMU CL and CCL to quit on EOF.
41 #+cmu
42 (setf ext:*batch-mode* t)
43 #+ccl
44 (setf ccl:*quit-on-eof* t)
45
46 ;; Tell SBCL where to find its source source.
47 #+sbcl
48 (sb-ext:set-sbcl-source-location #p"/usr/share/sbcl-source/")
49
50 ;; Tell some Lisps about my home directory. CMU CL already has a search list
51 ;; which does the same job, and CCL sets up a logical-pathname host.
52 #+(and unix (or sbcl clisp ecl abcl))
53 (let* ((homestring (or #+sbcl (sb-ext:posix-getenv "HOME")
54 #+(or clisp ecl abcl) (ext:getenv "HOME")
55 #+abcl (java:jstatic "getProperty"
56 "java.lang.System"
57 "user.home")
58 "/home/mdw"))
59 (home (pathname (concatenate 'string homestring "/"))))
60 (setf (logical-pathname-translations "HOME")
61 `(("HOME:**;*.*.*" ,(merge-pathnames "**/*.*" home nil)))))
62 (when (#.(car '(#+clisp ext:probe-directory
63 probe-file))
64 #p"/usr/share/common-lisp/")
65 (setf (logical-pathname-translations "CL")
66 '(("CL:SOURCE;**;*.*.*" #p"/usr/share/common-lisp/source/**/*.*")
67 ("CL:SYSTEMS;**;*.*.*" #p"/usr/share/common-lisp/systems/**/*.*"))))
68
69 ;; Various fixings.
70 #+clisp
71 (setf custom:*parse-namestring-ansi* t)
72
73 ;; CLisp history.
74 #+(and clisp readline)
75 (progn
76 (export '(*history-file* *history-size*))
77 (defvar *history-file* (format nil "~A/.clisp-history" (ext:getenv "HOME"))
78 "File to preserve the REPL history.")
79 (defvar *history-size* 1000)
80 (unless (and (probe-file *history-file*) nil)
81 (let (old-umask stream)
82 ;; Ugh. There's no proper open(2) veneer. Play with umask(2) to avoid
83 ;; a window in which an adversary can open the file.
84 (unwind-protect
85 (setf old-umask (os:umask #o077)
86 stream (open *history-file*
87 :direction :output
88 :if-exists :overwrite
89 :if-does-not-exist :create))
90 (when stream (close stream))
91 (when old-umask (os:umask old-umask)))))
92 (readline:read-history *history-file*)
93 (if *history-size* (readline:stifle-history *history-size*)
94 (readline:unstifle-history))
95 (push (lambda () (readline:write-history *history-file*))
96 custom:*fini-hooks*))
97
98 ;; Don't choke on shebang lines. This isn't here so that we can run Lisp
99 ;; scripts like proper Unix programs: `cl-launch' or `runlisp' do that. It's
100 ;; here so that we can `load' a script into a running Lisp without it choking
101 ;; on the shebang.
102 (set-dispatch-macro-character
103 #\# #\!
104 (lambda (stream char arg)
105 (declare (ignore char arg))
106 (values (read-line stream))))
107
108 ;; Start up swank.
109 (export 'crank-swank)
110 (defun crank-swank (&rest args)
111 (let ((swank (find-package "SWANK")))
112 (unless swank
113 (load "/usr/share/common-lisp/source/slime/swank-loader.lisp")
114 (funcall (find-symbol "INIT" (find-package "SWANK-LOADER")))
115 (setf swank (find-package "SWANK")))
116 (set (find-symbol "*GLOBAL-DEBUGGER*" swank) nil)
117 (apply (find-symbol "CREATE-SERVER" swank) args)))
118
119 ;; Treat warnings as, err, warnings.
120 #+asdf
121 (setf asdf:*compile-file-failure-behaviour* :warn)
122
123 ;; Done.
124 (pushnew :mdw *features*)
125 ;;#+(and cmu mp) (mp::startup-idle-and-top-level-loops)
126 (setf *package* *previous-package*)