WIN下scheme語言編程環境的搭建
- 概要
- 下載并安裝emacs
- 下載并安裝chezscheme
- 配置
- 使用
- 尾聲
概要
在windows系統下(并不合適,阻力好大),使用chezscheme+emacs 搭建scheme語言的編程環境.
下載并安裝emacs
請自行搜索并下載安裝emacs(用來和語言實現交互的文本編輯器)
下載并安裝chezscheme
在Github是有windows系統可用的安裝包的,安裝chezscheme后記得將要用的.exe文件配置到win系統的系統環境變量path中.一般會有兩個版本的.exe文件,線程功能不同.
下文中 M 表示 Alt C 表示 Ctrl C-c 表示 Ctrl+c
配置
修改emacs/site-lisp下的subdirs.el,添加以下幾行
`(defun fullpath-relative-to-call-location (file-path) (concat (file-name-directory (or load-file-name buffer-file-name)) file-path))
(defalias 'fullpath 'fullpath-relative-to-call-location)
(load (fullpath “…/CFG/init.el”) )`
注意CFG會在subdirs.el的上一級路徑中,比如subdirs.el位于…\emacs-28.1\share\emacs\site-lisp,那么CFG就應當在…\emacs-28.1\share\emacs中
參考博文 https://blog.csdn.net/weixin_33208391/article/details/116579680
2. 在路徑 *…\emacs-24.3* 中新建 CFG 文件夾
3. 在CFG文件家中建立init.el文件(可以新建文本文件,將后綴.txt改為.el,查看不了文件后綴的,自行搜索解決)
4. 打開init.el文件,在其中粘貼以下代碼:
(message "Init init.el!")
;;-SET-ENVIRONMENT--------------------------------------------------------------------------------------------
(setq jinz-default-dir (concat default-directory "/../CFG"))
(setq jinz-default-path (concat default-directory "/.."))
(setq source-directory (concat jinz-default-path "/24.3"))
(setq-default frame-title-format (concat "%b - e@" (system-name)))
(setq user-init-file jinz-default-path)
(setq user-emacs-directory jinz-default-dir)
(setenv "HOME" jinz-default-dir)
(setenv "PATH" jinz-default-path)
;; set the default file path
(add-to-list 'load-path jinz-default-dir)
;; window-system 表示是否為x窗體,其判斷為:
;; (if window-system nil)
;; (if (not window-system) nil);; system-type 表示系統類型
(cond((string-equal system-type "windows-nt") ; Microsoft Windows(progn(message "Microsoft Windows") ))((string-equal system-type "darwin") ; Mac OS X(progn(message "Mac OS X")))((string-equal system-type "gnu/linux") ; linux(progn(message "Linux") )))
CFG文件夾中新建 .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)'(column-number-mode t)'(cua-mode t nil (cua-base))'(current-language-environment "utf-8")'(safe-local-variable-values (quote ((package . net\.aserve\.client) (package . net\.aserve) (package . net\.html\.generator))))'(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.)
;============================================
(set-language-environment "utf-8")
;注意,下行不能u8,否則打開漢語名文件不顯示內容
(setq file-name-coding-system 'gb18030)
(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)
;;===============================
;設置行號
(global-linum-mode 1)
(setq linum-format "%d")
(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")
;將幫助命令綁定到 F1鍵
(global-set-key [f1] 'help-command)
(global-set-key "\C-c\M-q" 'slime-reindent-defun);;;======================================注意可移動模式,不然每次都要改
;;;關于scheme需要的包
;注意有時路徑不對依舊可以啟動scheme-mode
;下行需使用scheme.exe所在的路徑
(add-to-list 'exec-path "C:\\Program Files\\Chez Scheme 9.5\\bin\\ta6nt")
(add-to-list 'load-path "C:\\Program Files\\Chez Scheme 9.5\\bin\\ta6nt");paredit是一個插件,M+x paredit-mode啟動,
(autoload 'paredit-mode "paredit""Minor mode for pseudo-structurally editing Lisp code."t);; scheme配置
(require 'cmuscheme)
;ALT+x scheme-mode 即可對一個buffer開啟scheme模式
(setq scheme-program-name "scheme");; bypass the interactive question and start the default interpreter
(defun scheme-proc ()"Return the current Scheme process, starting one if necessary."(unless (and scheme-buffer(get-buffer scheme-buffer)(comint-check-proc scheme-buffer))(save-window-excursion(run-scheme scheme-program-name)))(or (scheme-get-process)(error "No current process. See variable `scheme-buffer'")))(defun scheme-split-window ()(cond((= 1 (count-windows))(delete-other-windows)(split-window-vertically (floor (* 0.68 (window-height))))(other-window 1)(switch-to-buffer "*scheme*")(other-window 1))((not (find "*scheme*"(mapcar (lambda (w) (buffer-name (window-buffer w)))(window-list)):test 'equal))(other-window 1)(switch-to-buffer "*scheme*")(other-window -1))))(defun scheme-send-last-sexp-split-window ()(interactive)(scheme-split-window)(scheme-send-last-sexp))(defun scheme-send-definition-split-window ()(interactive)(scheme-split-window)(scheme-send-definition))(add-hook 'scheme-mode-hook(lambda ()(paredit-mode 1)(define-key scheme-mode-map (kbd "<f5>") 'scheme-send-last-sexp-split-window)(define-key scheme-mode-map (kbd "<f6>") 'scheme-send-definition-split-window)))
5.geiser配置,在.emacs文件中加入如下代碼(記得將geiser解壓到CFG/.emacs.d/路徑下,沒有的話,請去github下載geiser):
(load-file "~/.emacs.d/geiser-0.9/elisp/geiser.el") ;
(setq geiser-active-implementations '(chez))
geiser可以幫助emacs和chezscheme更好地交流,解決很多奇怪的問題, geiser是有使用手冊的, 不長, C-c C-z 估計是最常用的:)
6.scheme代碼自動索引和補全的配置,需要插件popup , fuzzy , pos-tip, auto-complete以及ac-geiser,這些都需要去github下載,解壓到CFG/.emacs.d/路徑下配置到emacs能找到就OK了
;; ==============================================代碼自動補全==============================
;; ac的前件
;(setq expls '(popup fuzzy))
;(map 'require expls)
(add-to-list 'load-path "~/.emacs.d")
(require 'popup)
(require 'fuzzy)(add-to-list 'load-path "~/.emacs.d/auto-complete")
(require 'auto-complete)
(require 'auto-complete-config)(global-auto-complete-mode t) ;全局自動補全;; 使用自帶字典
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete/dict")
(ac-config-default);; 輸入2個字符才開始補全
(setq ac-auto-start 2);; 0輸入即開始補全的快捷鍵
(global-set-key "\M-/" 'auto-complete) ;; 使用增強的pos-tip
(require 'pos-tip)
(setq ac-quick-help-prefer-pos-tip t);;使用quick-help
(setq ac-use-quick-help t)
(setq ac-quick-help-delay 0.5);; Show 0.8 second later
(setq ac-auto-show-menu 0.8);;設置tab的使用模式--??
;;(setq ac-dwim t);;?使用fuzzy的模糊匹配
(setq ac-fuzzy-enable t);;菜單參數
(setq ac-menu-height 12)
(set-face-background 'ac-candidate-face "lightgray")
(set-face-underline 'ac-candidate-face "darkgray")
(set-face-background 'ac-selection-face "steelblue") ;; =========================================== ac-geiser配置========================
(add-to-list 'load-path "~/.emacs.d/ac-geiser")
(require 'ac-geiser)
(add-hook 'geiser-mode-hook 'ac-geiser-setup)
(add-hook 'geiser-repl-mode-hook 'ac-geiser-setup)
(eval-after-load "auto-complete"'(add-to-list 'ac-modes 'geiser-repl-mode))
CFG文件夾中放入paredit.el文件(一個編輯器插件,用來高效處理lisp代碼,提供括號自動匹配等功能)paredit.el應該也是可以下載到的.
使用
emacs運行后,按C-c C-z, chezscheme就啟動了或者新建.ss文件,拖動到emacs窗口,再C-c C-z接下來愉快地彈奏代碼就OK.
尾聲
目前就這樣了,還請各位多多指教.
總結
以上是生活随笔為你收集整理的windows系统下scheme语言编程环境的搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。