| 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 | ;; Obtain ASDF from somewhere. |
| 35 | (require "asdf") |
| 36 | |
| 37 | ;; Get CMU CL to quit on EOF. |
| 38 | #+cmu |
| 39 | (setf ext:*batch-mode* t) |
| 40 | |
| 41 | ;; Tell SBCL where to find its source source. |
| 42 | #+sbcl |
| 43 | (sb-ext:set-sbcl-source-location #p"/usr/share/sbcl-source/") |
| 44 | |
| 45 | ;; Tell some Lisps about my home directory. |
| 46 | #+(and unix (or sbcl clisp)) |
| 47 | (let* ((homestring (or #+sbcl (sb-ext:posix-getenv "HOME") |
| 48 | #+clisp (ext:getenv "HOME") |
| 49 | #+cmu (unix:unix-getenv "HOME") |
| 50 | "/home/mdw")) |
| 51 | (home (pathname (concatenate 'string homestring "/")))) |
| 52 | (setf (logical-pathname-translations "HOME") |
| 53 | `(("HOME:**;*.*.*" ,(merge-pathnames "**/*.*" home nil))) |
| 54 | (logical-pathname-translations "CL") |
| 55 | '(("CL:SOURCE;**;*.*.*" #p"/usr/share/common-lisp/source/**/*.*") |
| 56 | ("CL:SYSTEMS;**;*.*.*" #p"/usr/share/common-lisp/systems/**/*.*")))) |
| 57 | |
| 58 | ;; Various fixings. |
| 59 | #+clisp |
| 60 | (setf custom:*parse-namestring-ansi* t) |
| 61 | |
| 62 | ;; CLisp history. |
| 63 | #+(and clisp readline) |
| 64 | (progn |
| 65 | (export '(*history-file* *history-size*)) |
| 66 | (defvar *history-file* (format nil "~A/.clisp-history" (ext:getenv "HOME")) |
| 67 | "File to preserve the REPL history.") |
| 68 | (defvar *history-size* 1000) |
| 69 | (unless (and (probe-file *history-file*) nil) |
| 70 | (let (old-umask stream) |
| 71 | ;; Ugh. There's no proper open(2) veneer. Play with umask(2) to avoid |
| 72 | ;; a window in which an adversary can open the file. |
| 73 | (unwind-protect |
| 74 | (setf old-umask (os:umask #o077) |
| 75 | stream (open *history-file* |
| 76 | :direction :output |
| 77 | :if-exists :overwrite |
| 78 | :if-does-not-exist :create)) |
| 79 | (when stream (close stream)) |
| 80 | (when old-umask (os:umask old-umask))))) |
| 81 | (readline:read-history *history-file*) |
| 82 | (if *history-size* (readline:stifle-history *history-size*) |
| 83 | (readline:unstifle-history)) |
| 84 | (push (lambda () (readline:write-history *history-file*)) |
| 85 | custom:*fini-hooks*)) |
| 86 | |
| 87 | ;; Shebang. |
| 88 | (set-dispatch-macro-character |
| 89 | #\# #\! |
| 90 | (lambda (stream char arg) |
| 91 | (declare (ignore char arg)) |
| 92 | (values (read-line stream)))) |
| 93 | |
| 94 | ;; Start up swank. |
| 95 | (export 'crank-swank) |
| 96 | (defun crank-swank (&rest args) |
| 97 | (let ((swank (find-package "SWANK"))) |
| 98 | (unless swank |
| 99 | (load "/usr/share/common-lisp/source/slime/swank-loader.lisp") |
| 100 | (funcall (find-symbol "INIT" (find-package "SWANK-LOADER"))) |
| 101 | (setf swank (find-package "SWANK"))) |
| 102 | (set (find-symbol "*GLOBAL-DEBUGGER*" swank) nil) |
| 103 | (apply (find-symbol "CREATE-SERVER" swank) args))) |
| 104 | |
| 105 | ;; Treat warnings as, err, warnings. |
| 106 | #+asdf |
| 107 | (setf asdf:*compile-file-failure-behaviour* :warn) |
| 108 | |
| 109 | ;; Done. |
| 110 | (pushnew :mdw *features*) |
| 111 | ;;#+(and cmu mp) (mp::startup-idle-and-top-level-loops) |
| 112 | (setf *package* *previous-package*) |