LispBox 集成开发环境分析 (一)Windows版本分析 html
LispBox 是一个开源的LISP 集成开发环境,由 SLIME (The Superior Lisp Interaction Mode for Emacs) 交互接口、 Quicklisp 库管理器、Clozure Common Lisp 编译器和 Emacs 编辑器组成,有WINDOWS、LINUX和MAC OSX三种版本,目前已经中止更新,下载地址为:
http://www.common-lisp.net/project/lispbox/ shell
使用方法很简单,只要把对应的版本下载回去,而后直接执行对应的程序便可启动整个LISP 开发环境了,好比:
一、在WINDOWS下执行 lispbox.bat
二、在LINUX下执行 lispbox.sh
三、在MAC环境下执行 Emacs
对于新手来讲不须要进行任何配置工做,很是方便,因此虽然 LispBox 已经中止更新,可是对于Lisp初学者我仍是推荐使用LispBox。 windows
本文是一个学习记录,为了不学了后面的忘记前面的,因此把学习过程当中每一个阶段理解的内容都用书面的形式作一个总结,以便温故而知新。 app
首先从LISPBOX的目录结构开始: 编辑器
解压后的Lispbox 目录名为 "\lispbox-0.7-ccl-1.6-windowsx86\lispbox-0.7\" ,里面有4个目录,以下:
"\ccl-1.6-windowsx86"
"\emacs-23.2"
"\Quicklisp"
"\slime-20110205.092829"
有3个文件,分别为:
asdf.lisp
asdf-extensions.lisp
lispbox.bat
前两个文件稍微有些复杂暂时不讨论,第三个文件 lispbox.bat 就是咱们要启动 lispbox 的集成开发环境时执行的文件,它是一个批处理文件,先看看它的内容: ide
@echo off rem Thanks to Venkat who provided this bit of COMMAND wizardry. if NOT %OS%==Windows_NT goto checkhome for %%i in ( "%CD%" ) do set LISPBOX_HOME=%%~si% goto start :checkhome rem rem if the environment variable is not defined, dereferencing rem it produces the same string! rem if %LISPBOX_HOME%==%LISPBOX_HOME% goto noenv :start set EMACS=%LISPBOX_HOME%/emacs-23.2/bin/runemacs.exe set TO_EVAL="(progn (load \"lispbox\") (slime))" %EMACS% --no-init-file --no-site-file --eval=%TO_EVAL% goto end :noenv echo LISPBOX_HOME environment variable should be set and echo point to the installation directory of LISPBOX before echo launching this command. :end
@echo on
这下就清楚了,首先是判断操做系统是否为WINDOWS,而后设置当前LISPBOX所在目录 LISPBOX_HOME 的值,最后执行了emacs目录下的 runemacs.exe 文件,执行参数有3个:
一、 --no-init-file 表示不加载 emacs 的初始化文件(~\.emacs)
二、 --no-site-file 表示不加载 emacs 的全站点配置文件(emacs 通常使用这些文件做为默认的全站点初始化文件 site-load.el site-init.el site-start.el)
三、 --eval="(progn (load \"lispbox\") (slime))" EVAL是lisp里的一个求值函数,该语句表示由 emacs 顺序执行以下两条命令: (load "lispbox") ,(slime) ,第一条命令表示首先要加载 lispbox (也就是emacs-23.2/site-lisp/目录下的 lispbox.el 文件,因此你也能够把这条命令改写为 (load \"lispbox.el\") ,效果是同样的),而后再执行 slime ,咱们能够看一下 lispbox.el 文件有哪些内容,以下: 函数
;; 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-20110205.092829") load-path)) (setenv "SBCL_HOME" (lispbox-file "sbcl-1.0.42/lib/sbcl")) (setenv "CCL_DEFAULT_DIRECTORY" (lispbox-file "ccl-1.6-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)
关键是这几句: 学习
(setq load-path (cons (lispbox-file "slime-20110205.092829") load-path)) (setenv "SBCL_HOME" (lispbox-file "sbcl-1.0.42/lib/sbcl")) (setenv "CCL_DEFAULT_DIRECTORY" (lispbox-file "ccl-1.6-windowsx86"))第一句指定了 slime 的目录,这样执行 slime 时EMACS就可以自动到 slime 的安装目录下找到 slime.el 文件了