用最新版本的 Emacs、SLIME和CCL来打造自己的 LispBox-0.8

用最新版本的 Emacs、SLIME和CCL来打造自己的 LispBox-0.8

首先得弄清楚 Lispbox 的启动顺序,以及各个部分(emacs、slime 、CCL 、quicklisp)如何被调用,大致描述如下:
1、执行 lispbox.bat ,实际上运行了如下命令

runemacs.exe  --no-init-file --no-site-file --eval=="(progn (load \"lispbox.el\") (slime))" 


2、上面的命令相当于由 emacs 加载了 emacs-24.2\site-lisp\ 目录下的 lispbox.el 文件,然后再执行 slime ,具体的lispbox.el 的内容如下:

(require 'cl)

(defun lispbox-list-to-filename (list)
  (apply 
   #'concat 
   (maplist
    #'(lambda (cons)
        (if (cdr cons) (file-name-as-directory (car cons)) (car cons)))
    list)))

(defun lispbox-file (rest)
  (concat 
   (file-name-as-directory
    (expand-file-name
     (or (getenv "LISPBOX_HOME")
         (file-name-directory load-file-name))))
   rest))

(defun lispbox-find-lisps ()
  (dolist (file (file-expand-wildcards (lispbox-file "*/lispbox-register.el")))
    (load file)))

(defun lispbox-install-lisp-license (license-path lisp-name)
  (let ((license (concat (file-name-directory load-file-name) (lispbox-list-to-filename license-path))))
    (if (not (file-exists-p license))
      (let* ((prompt (format "Need to install license for %s . Please enter name of file where you saved it: " lisp-name))
             (to-install (read-file-name prompt)))
        (copy-file (expand-file-name to-install) license)))))

(global-font-lock-mode t)

(setq load-path (cons (lispbox-file "slime-2012-11-13") load-path))
;(setenv "SBCL_HOME" (lispbox-file "sbcl-1.0.42/lib/sbcl"))
(setenv "SBCL_HOME" (lispbox-file "Steel-Bank-Common-Lisp"))
(setenv "CCL_DEFAULT_DIRECTORY" (lispbox-file "ccl-1.8-windowsx86"))



;(require :aserve)
(require 'slime)

(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(prefer-coding-system 'utf-8)

(setq slime-net-coding-system 'utf-8-unix)
(slime-setup '(slime-fancy slime-asdf slime-banner))
(lispbox-find-lisps)

(provide 'lispbox)

主要关注这几条:
;; 寻找 lispbox-register.el ,找到后加载 lispbox-register.el 
(defun lispbox-find-lisps ()
  (dolist (file (file-expand-wildcards (lispbox-file "*/lispbox-register.el")))
    (load file)))

;; 设置 slime 的路径
(setq load-path (cons (lispbox-file "slime-2012-11-13") load-path))

;; 设置 SBCL 的路径
(setenv "SBCL_HOME" (lispbox-file "Steel-Bank-Common-Lisp"))

;; 设置 CCL 路径
(setenv "CCL_DEFAULT_DIRECTORY" (lispbox-file "ccl-1.8-windowsx86"))

(require 'slime)

(setq slime-net-coding-system 'utf-8-unix)
(slime-setup '(slime-fancy slime-asdf slime-banner))

;; 在上述路径中执行查找 lispbox-register.el 文件,找到后加载它
(lispbox-find-lisps)

(provide 'lispbox)

3、从上述的 lispbox.el 中发现,下一个要加载的文件是 lispbox-register.el ,这个文件放在对应的 Lisp 编译器目录下,比如这里我使用了两种编译器 SBCL 和 CCL,那么就要在相应的目录下准备好这个文件。
CCL 下的 lispbox-register.el 内容为:

(push (list 'clozurecl (list (lispbox-list-to-filename (list (file-name-directory load-file-name) (if (getenv "PROGRAMW6432") "wx86cl64.exe" "wx86cl.exe"))))) slime-lisp-implementations)

SBCL 下的 lispbox-register.el 内容为:
(push (list 'sbcl (list (lispbox-list-to-filename (list (file-name-directory load-file-name) (if (getenv "PROGRAMW6432") "sbcl.exe" "sbcl.exe"))))) slime-lisp-implementations)

4、这样最终通过 runemacs.exe 先后加载了 slime 和 CCL(或SBCL)


集成在 lispbox 中的 CCL-1.6 和单独的 CCL-1.8 的区别:

1、lispbox 的 ccl-1.6-windowsx86 目录下有一个 lispbox-register.el 的文件,单独的 ccl-1.8-windowsx86 目录下没有此文件,该文件如下语句来设置:

(setq load-path (cons (lispbox-file "slime-2012-11-13") load-path))
(setenv "SBCL_HOME" (lispbox-file "sbcl-1.0.42/lib/sbcl"))
(setenv "CCL_DEFAULT_DIRECTORY" (lispbox-file "ccl-1.8-windowsx86"))

2、ccl-1.6-windowsx86\tools\asdf.lisp 文件不同,直接把 ccl-1.8-windowsx86 文件夹拷贝过去后执行lispbox.bat EMACS启动后会有如下提示:
;Compiler warnings for "f:/LISPBO~1.8/ccl-1.8-windowsx86/tools/asdf.lisp" :
;   In ASDF::CCL-FASL-VERSION: Undefined function CCL::TARGET-FASL-VERSION

检查后发现emacs显示同时调用了1.6和1.8的CCL,把1.6的lispbox-register.el 改个名字就不再显示上面的错误了,但是又出现了很多新的警告提示,如下:

(progn (load "f:/LISPBO~1.8/slime-2012-11-13/swank-loader.lisp" :verbose t) (funcall (read-from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "c:/Users/admin/AppData/Local/Temp/slime.5360"))

Welcome to Clozure Common Lisp Version 1.8-r15286M  (WindowsX8632)!
? ;Loading #P"f:/LISPBO~1.8/slime-2012-11-13/swank-loader.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/swank-backend.lisp"...
;Compiler warnings for "f:/LISPBO~1.8/slime-2012-11-13/swank-backend.lisp" :
;   In an anonymous lambda form at position 47772: Unused lexical variable THREAD
;   In an anonymous lambda form at position 48339: Unused lexical variable NAME
;Loading #P"C:/Users/admin/.slime/fasl/2012-11-12/clozure-version_1.8-r15286m__(windowsx8632)-windows-x86/swank-backend.wx32fsl"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/metering.lisp"...
;Loading #P"C:/Users/admin/.slime/fasl/2012-11-12/clozure-version_1.8-r15286m__(windowsx8632)-windows-x86/metering.wx32fsl"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/swank-ccl.lisp"...
;Loading #P"C:/Users/admin/.slime/fasl/2012-11-12/clozure-version_1.8-r15286m__(windowsx8632)-windows-x86/swank-ccl.wx32fsl"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/swank-gray.lisp"...
;Loading #P"C:/Users/admin/.slime/fasl/2012-11-12/clozure-version_1.8-r15286m__(windowsx8632)-windows-x86/swank-gray.wx32fsl"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/swank-match.lisp"...
;Loading #P"C:/Users/admin/.slime/fasl/2012-11-12/clozure-version_1.8-r15286m__(windowsx8632)-windows-x86/swank-match.wx32fsl"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/swank-rpc.lisp"...
;Loading #P"C:/Users/admin/.slime/fasl/2012-11-12/clozure-version_1.8-r15286m__(windowsx8632)-windows-x86/swank-rpc.wx32fsl"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/swank.lisp"...
;Compiler warnings for "f:/LISPBO~1.8/slime-2012-11-13/swank.lisp" :
;   In SWANK::THREAD-FOR-EVALUATION: Undefined function SWANK::FIND-REPL-THREAD
;   In SWANK::THREAD-FOR-EVALUATION: Undefined function SWANK::FIND-REPL-THREAD
;Loading #P"C:/Users/admin/.slime/fasl/2012-11-12/clozure-version_1.8-r15286m__(windowsx8632)-windows-x86/swank.wx32fsl"...
; Warning: These Swank interfaces are unimplemented:
;           (ACTIVATE-STEPPING ADD-FD-HANDLER ADD-SIGIO-HANDLER
;            BACKGROUND-SAVE-IMAGE DUP EXEC-IMAGE MAKE-FD-STREAM
;            REMOVE-FD-HANDLERS REMOVE-SIGIO-HANDLERS SLDB-BREAK-AT-START
;            SLDB-BREAK-ON-RETURN SLDB-STEP-INTO SLDB-STEP-NEXT SLDB-STEP-OUT
;            WAIT-FOR-INPUT)
; While executing: SWANK-BACKEND::WARN-UNIMPLEMENTED-INTERFACES, in process listener(1).
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-util.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-repl.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-c-p-c.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-arglists.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-fuzzy.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-fancy-inspector.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-presentations.lisp"...
;Compiler warnings for "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-presentations.lisp" :
;   In an anonymous lambda form at position 8124: Undeclared free variable *SEND-REPL-RESULTS-FUNCTION*
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-presentation-streams.lisp"...
;Compiler warnings for "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-presentation-streams.lisp" :
;   In an anonymous lambda form at position 12203: Undeclared free variable *SEND-REPL-RESULTS-FUNCTION*
;Compiler warnings for "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-presentation-streams.lisp" :
;   In CCL::CLEAR-PRESENTATIONS inside an anonymous lambda form: Undefined function SWANK::CLEAR-PRESENTATION-TABLES
;   In SWANK::PRESENTING-OBJECT-1: Undefined function SWANK::SAVE-PRESENTED-OBJECT
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-package-fu.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-hyperdoc.lisp"...
;Compiling "f:/LISPBO~1.8/slime-2012-11-13/contrib/swank-mrepl.lisp"...
;; Swank started at port: 50050.
50050
? 
; Warning: Test failed: (&KEY #'#'+) => "(&key (function (function +)))"
;            Expected: "(&key (function #'+))"
; While executing: (:INTERNAL TEST TEST-PRINT-ARGLIST), in process worker(8).

你可能感兴趣的:(用最新版本的 Emacs、SLIME和CCL来打造自己的 LispBox-0.8)