Commit | Line | Data |
---|---|---|
7914c3fa MW |
1 | ;;; -*-lisp-*- |
2 | ||
152e7f69 | 3 | (cl:defpackage #:mdw-hacks |
e623f041 | 4 | (:use #:cl)) |
152e7f69 MW |
5 | (cl:defparameter mdw-hacks::*previous-package* cl:*package*) |
6 | (cl:in-package #:mdw-hacks) | |
d37d5787 MW |
7 | |
8 | ;; Shut up. | |
1865da17 MW |
9 | (setf *load-verbose* nil |
10 | *compile-verbose* nil) | |
5927034b MW |
11 | |
12 | #+cmu | |
3ec148f0 MW |
13 | (setf ext:*gc-verbose* nil |
14 | ext:*require-verbose* nil) | |
d37d5787 | 15 | |
4e7092a3 MW |
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 | ||
297be13e MW |
34 | ;; Obtain ASDF from somewhere. |
35 | (require "asdf") | |
36 | ||
84739668 MW |
37 | ;; Get CMU CL to quit on EOF. |
38 | #+cmu | |
39 | (setf ext:*batch-mode* t) | |
40 | ||
2498576b MW |
41 | ;; Tell SBCL where to find its source source. |
42 | #+sbcl | |
43ef52b8 | 43 | (sb-ext:set-sbcl-source-location #p"/usr/share/sbcl-source/") |
2498576b | 44 | |
0ad84131 MW |
45 | ;; Tell some Lisps about my home directory. CMU CL already has a search list |
46 | ;; which does the same job. | |
2c3abc4c | 47 | #+(and unix (or sbcl clisp)) |
9af2290b MW |
48 | (let* ((homestring (or #+sbcl (sb-ext:posix-getenv "HOME") |
49 | #+clisp (ext:getenv "HOME") | |
9af2290b MW |
50 | "/home/mdw")) |
51 | (home (pathname (concatenate 'string homestring "/")))) | |
ae8efc86 | 52 | (setf (logical-pathname-translations "HOME") |
fb65858f MW |
53 | `(("HOME:**;*.*.*" ,(merge-pathnames "**/*.*" home nil))))) |
54 | (when (#.(car '(#+clisp ext:probe-directory | |
55 | probe-file)) | |
56 | #p"/usr/share/common-lisp/") | |
57 | (setf (logical-pathname-translations "CL") | |
58 | '(("CL:SOURCE;**;*.*.*" #p"/usr/share/common-lisp/source/**/*.*") | |
59 | ("CL:SYSTEMS;**;*.*.*" #p"/usr/share/common-lisp/systems/**/*.*")))) | |
ae8efc86 | 60 | |
62d12c1f | 61 | ;; Various fixings. |
5927034b MW |
62 | #+clisp |
63 | (setf custom:*parse-namestring-ansi* t) | |
62d12c1f | 64 | |
0630988a MW |
65 | ;; CLisp history. |
66 | #+(and clisp readline) | |
67 | (progn | |
68 | (export '(*history-file* *history-size*)) | |
69 | (defvar *history-file* (format nil "~A/.clisp-history" (ext:getenv "HOME")) | |
70 | "File to preserve the REPL history.") | |
71 | (defvar *history-size* 1000) | |
72 | (unless (and (probe-file *history-file*) nil) | |
73 | (let (old-umask stream) | |
74 | ;; Ugh. There's no proper open(2) veneer. Play with umask(2) to avoid | |
75 | ;; a window in which an adversary can open the file. | |
76 | (unwind-protect | |
77 | (setf old-umask (os:umask #o077) | |
78 | stream (open *history-file* | |
79 | :direction :output | |
80 | :if-exists :overwrite | |
81 | :if-does-not-exist :create)) | |
82 | (when stream (close stream)) | |
83 | (when old-umask (os:umask old-umask))))) | |
84 | (readline:read-history *history-file*) | |
85 | (if *history-size* (readline:stifle-history *history-size*) | |
86 | (readline:unstifle-history)) | |
87 | (push (lambda () (readline:write-history *history-file*)) | |
88 | custom:*fini-hooks*)) | |
89 | ||
0712ae95 MW |
90 | ;; Don't choke on shebang lines. This isn't here so that we can run Lisp |
91 | ;; scripts like proper Unix programs: `cl-launch' or `runlisp' do that. It's | |
92 | ;; here so that we can `load' a script into a running Lisp without it choking | |
93 | ;; on the shebang. | |
86c2d6fd MW |
94 | (set-dispatch-macro-character |
95 | #\# #\! | |
9af2290b MW |
96 | (lambda (stream char arg) |
97 | (declare (ignore char arg)) | |
98 | (values (read-line stream)))) | |
86c2d6fd | 99 | |
d37d5787 | 100 | ;; Start up swank. |
e623f041 | 101 | (export 'crank-swank) |
9af2290b MW |
102 | (defun crank-swank (&rest args) |
103 | (let ((swank (find-package "SWANK"))) | |
104 | (unless swank | |
d37d5787 | 105 | (load "/usr/share/common-lisp/source/slime/swank-loader.lisp") |
77619173 | 106 | (funcall (find-symbol "INIT" (find-package "SWANK-LOADER"))) |
9af2290b MW |
107 | (setf swank (find-package "SWANK"))) |
108 | (set (find-symbol "*GLOBAL-DEBUGGER*" swank) nil) | |
109 | (apply (find-symbol "CREATE-SERVER" swank) args))) | |
d37d5787 | 110 | |
d9667bfa | 111 | ;; Treat warnings as, err, warnings. |
5927034b MW |
112 | #+asdf |
113 | (setf asdf:*compile-file-failure-behaviour* :warn) | |
502738c0 | 114 | |
d37d5787 | 115 | ;; Done. |
6f7bbd84 | 116 | (pushnew :mdw *features*) |
d37d5787 | 117 | ;;#+(and cmu mp) (mp::startup-idle-and-top-level-loops) |
152e7f69 | 118 | (setf *package* *previous-package*) |