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,回車,看是否能正確執行.html

          2.2若是路徑中有空格,則配置文件中就會有空格,安裝時不會出錯,可是在emacs中運行M-x slime時會出現問題:apply: Spawning child process: invalid argument.git

     3.下載slime,http://github.com/slime/slime,解壓縮到合適的路徑便可.github

 具體問題能夠參考下列博客windows

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

  • 第二步,emacs的配置

    打開系統路徑:C:\Users\你的用戶名\AppData\Roaming,找到.emacs文件,打開方式選擇記事本便可(之後可使用emacs),在其中添加以下語句:ide

(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/105566ui

這樣設置以後就可使用漢語寫lisp文件了,如圖:編碼


 

 

 

 

 

 

 

 

 

 

 

 

 

這樣就解決了中文亂碼問題.spa

要寫這樣一個程序,首先能夠新建一個空文本文檔,將格式改成.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

       很是感謝大神們對於小生曾經提出問題的悉心幫助!

相關文章
相關標籤/搜索