Common Lisp支持中文编辑和编译的windows下环境搭建志

  • 第一步,安装emacs+slime+sbcl/ccl/...

  1. 安装windows下的emacs ,http://ftp.gnu.org/gnu/emacs/windows/emacs-24.3-bin-i386.zip
  2. 安装windows 下的sbcl(注意下载win下的文件),http://www.sbcl.org/platform-table.html(点击相应配置对应表格中的方块即可下载).

          2.1安装完成后重启系统,否则会提示:fatal error encountered in SBCL pid 10236(tid 9971200): can't find core file at XXXXX。检测环境变量是否生效的方法是:打开windows控制台,输入sbcl,回车,看是否能正确执行.

          2.2如果路径中有空格,则配置文件中就会有空格,安装时不会出错,但是在emacs中运行M-x slime时会出现问题:apply: Spawning child process: invalid argument.

     3.下载slime,http://github.com/slime/slime,解压缩到合适的路径即可.

 具体问题可以参考下列博客

    http://www.tuicool.com/articles/FBzANvE

  • 第二步,emacs的配置

    打开系统路径:C:\Users\你的用户名\AppData\Roaming,找到.emacs文件,打开方式选择记事本即可(以后可以使用emacs),在其中添加如下语句:

(load-file "自己的emacs安装目录/emacs-24.3/.emacs")
;注意斜杠不要搞错,如果目录下没有.emacs,就把原来的.emacs复制过去,之后改写内容
(setenv "HOME" "同上那个目录/emacs-24.3/")
(setenv "PATH" "同上那个目录/emacs-24.3/")
;;set the default file path
(setq default-directory "~/")

    改写了emacs配置文件的路径后,找到emacs文件夹内,复制过去的.emacs文件,打开它,改写如下:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
	 '(case-fold-search nil)
	 '(current-language-environment "utf-8");这句不需要gb18030
	 '(column-number-mode t);下面这几句没有什么实际效果,有追求的同学可以再研究下
	 '(cua-mode t nil (cua-base))
	 '(show-paren-mode t)
	 '(text-mode-hook (quote (text-mode-hook-identify)))
	 '(uniquify-buffer-name-style (quote forward) nil (uniquify)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
;=============================
(setq inferior-lisp-program "E:/ProgramData/SBCL/sbcl.exe -K utf-8")
;按照自己的sbcl路径配置正确,注意斜杠,不要弄错
(add-to-list 'load-path "E:/ProgramData/SBCL/slime/");slime路径,我放到sbcl下了
(require 'slime-autoloads)
;自动加载slime全部,如果是'slime,会导致很多快捷键用不了
(slime-setup '(slime-fancy
	      ; slime-asdf slime-banner
	       ));舒服的slime风格'(slime-fancy),比如把sbcl的*变成CL-USER>
;=============================
;注意,下面这句使用gb18030等编码会导致utf-8设置下的编译失败,所以用utf-8
(set-language-environment "utf-8")

;注意,下面这句不能utf-8,否则打开汉语名文件不显示内容
(setq file-name-coding-system 'gb18030)

;下面这句用于解决个别机器的乱码问题
(set-fontset-font "fontset-default" 'cp936 '("SimSun" . "unicode-bmp"))

(set-buffer-file-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-next-selection-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-clipboard-coding-system 'utf-8)  
(setq ansi-color-for-comint-mode t)
(modify-coding-system-alist 'process "*" 'utf-8)  
(setq-default pathname-coding-system 'utf-8)  
(prefer-coding-system 'utf-8)
(setq default-process-coding-system '(utf-8 . utf-8))  
(setq locale-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)  
(setq slime-net-coding-system 'utf-8-unix)
;;============================美化设置
(set-cursor-color "white") 
(set-mouse-color "blue") 
(set-foreground-color "green") 
(set-background-color "black") 
(set-border-color "lightgreen") 
(set-face-foreground 'highlight "red") 
(set-face-background 'highlight "lightblue") 
(set-face-foreground 'region "darkcyan") 
(set-face-background 'region "lightblue") 
(set-face-foreground 'secondary-selection "skyblue") 
(set-face-background 'secondary-selection "darkblue") 
;;=============================键绑定
(global-set-key [f1]   'help-command);将帮助命令绑定到 F1键
(global-set-key "\C-c\M-q" 'slime-reindent-defun);这句也没效果....

这样就可以支持中文编辑了,还可以参考Free lues的博客http://my.oschina.net/freeblues/blog/105566

这样设置之后就可以使用汉语写lisp文件了,如图:


 

 

 

 

 

 

 

 

 

 

 

 

 

这样就解决了中文乱码问题.

要写这样一个程序,首先可以新建一个空文本文档,将格式改为.lisp再用emacs打开,或者打开emacs,C-x,C-f(C表示Ctrl键,M表示Alt键,意思就是先按Ctrl+x再按Ctrl+f),下边栏出现Find file,输入"文件名.lisp",(如果原路径没有,就会新建文件),enter后会打开相应文件,并建立对应缓冲区(buffer).

按下M-x 输入slime,(M-x slime),enter启动slime.

接着在文件中写代码,然后按C-c,C-c编译函数或C-x,C-e求值S表达式,之后可以在写好的函数区块按C-c,C-y,将函数发送到slime的缓冲区来调试函数.

  • 关于含有汉字的流写入文件的问题

    只需在with-open-file宏或相关函数中添加如下代码:

    :external-format :utf-8或:external-format :gbk

    即可.

  • 中文函数的编译与加载

     1. 在lisp文件中写入如下代码:

(compile-file "编辑的lisp文件.lisp" :external-format utf-8)

     然后C-c,C-l加载编译后生成的.fasl文件即可加载文件中的全部函数.

     切记不要在文件中写下(load "编译后的.fasl")语句,否则在编译(compile-file.....)时会导致无限循环从而出错!

    2. 或者在slime的缓冲区写入

(load "目标文件.lisp" :external-format :utf-8)

      接着enter即可.

      使用lispbox的朋友也可以参考FreeBlues大神的博客 http://my.oschina.net/freeblues/blog/89720

       非常感谢大神们对于小生曾经提出问题的悉心帮助!

转载于:https://my.oschina.net/ether/blog/755906

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值