Lisp/SLY: Simplify dump-sbcl-core-for-sly and load just in time.

master
Pierre Neidhardt 2020-11-07 11:06:15 +01:00
parent d11f3f620b
commit 876511407d
1 changed files with 20 additions and 19 deletions

View File

@ -47,28 +47,31 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Sly
;; TODO: Report upstream.
;; https://github.com/joaotavora/sly/issues/363
(defun dump-sbcl-core-for-sly () ; REVIEW: This probably works for SLIME too.
(cl-flet ((read-bytes (path)
(with-temp-buffer
;; (set-buffer-multibyte nil)
;; (setq buffer-file-coding-system 'binary)
(insert-file-contents-literally path)
(buffer-substring-no-properties (point-min) (point-max)))))
(buffer-substring-no-properties (point-min) (point-max))))
(call-process-to-string (command &rest args)
(with-temp-buffer
(apply #'call-process command nil t nil args)
(buffer-string))))
(let* ((sbcl-core-dir (expand-file-name "sly/" user-emacs-directory))
(sbcl-core (expand-file-name "sbcl.core-for-sly" sbcl-core-dir))
(sbcl-core-version (expand-file-name "sbcl.version" sbcl-core-dir))
(current-sbcl-version (cadr (split-string
(with-temp-buffer
(call-process "sbcl" nil t nil "--version")
(buffer-string))))))
(call-process-to-string "sbcl" "--version")))))
(when (or (not (file-exists-p sbcl-core-version))
(version< (car (split-string (read-bytes sbcl-core-version)))
current-sbcl-version))
(make-directory sbcl-core-dir :parents)
(call-process
"sbcl" nil nil nil
"--eval" "(mapc 'require '(sb-bsd-sockets sb-posix sb-introspect sb-cltl2 asdf))"
"--eval" (format "(save-lisp-and-die %S)" sbcl-core))
(ignore-errors
(call-process
"sbcl" nil nil nil
"--eval" "(mapc 'require '(sb-bsd-sockets sb-posix sb-introspect sb-cltl2 asdf))"
"--eval" (format "(save-lisp-and-die %S)" sbcl-core)))
(with-temp-file sbcl-core-version
(insert current-sbcl-version)))
(when (file-exists-p sbcl-core)
@ -84,18 +87,15 @@
(funcall old-func package new-prompt error-level condition)))
(with-eval-after-load 'sly
(let ((core (dump-sbcl-core-for-sly)))
(setq sly-lisp-implementations
`((sbcl ("sbcl"
,@(if core
`("--core" ,core)
'())))
(ccl ("ccl"))
(ecl ("ecl")))))
(advice-add 'sly-mrepl--insert-prompt :around #'ambrevar/sly-prepare-prompt)
(with-eval-after-load 'sly-mrepl
(let ((core (dump-sbcl-core-for-sly)))
(setq sly-lisp-implementations
`((sbcl ("sbcl" ,@(when core
`("--core" ,core))))
(ccl ("ccl"))
(ecl ("ecl")))))
(setq sly-mrepl-history-file-name (expand-file-name "sly-mrepl-history" user-emacs-directory))
(define-key sly-mrepl-mode-map (kbd "C-c M-o") 'sly-mrepl-clear-repl))
@ -109,6 +109,7 @@
(define-key lisp-mode-map (kbd "<f6>") 'ambrevar/sly-load-reload-system)
(defun ambrevar/sly-colorize-buffer (str)
"Useful for colorized output like the tests of Prove."
(ansi-color-apply str))
(add-hook 'sly-mrepl-output-filter-functions 'ambrevar/sly-colorize-buffer)