common lisp 下载设置入门

桂学
2023-12-01

起点:下载

linux: https://gist.github.com/jteneycke/7947353

下载最新的sbcl & emacs:
http://jaist.dl.sourceforge.net/project/sbcl/sbcl/1.3.5/sbcl-1.3.5-x86-windows-binary.msi
http://mirrors.ustc.edu.cn/gnu/emacs/windows/emacs-24.5-bin-i686-mingw32.zip

curl -k -O https://beta.quicklisp.org/quicklisp.lisp
sbcl –load quicklisp.lisp
(quicklisp-quickstart:install :path “quicklisp-down/”)
(ql:quickload “quicklisp-slime-helper”)

配置 .emacs

这里通过key mapping解决emacs启动慢。

;;;; .emacs
(setq inhibit-startup-message t)
(setq gnus-inhibit-startup-message t)
(setq frame-title-format “%b”)
(tool-bar-mode -1)
(setq default-major-mode ‘text-mode)
(setq column-number-mode t)
(setq next-screen-context-lines 4) ;for page down.
(setq kill-ring-max 200) ;for history record
(setq message-log-max t)

;(setq make-backup-files nil); no backup!
(setq
backup-by-copying t ; don’t clobber symlinks
backup-directory-alist
‘((“.” . “~/.emacs_saves”)) ; don’t litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t) ; use versioned backups

(setq scroll-margin 3
scroll-conservatively 10000)
(require ‘package) ;M-x list-packages
(add-to-list ‘package-archives
‘(“melpa” . “http://melpa.org/packages/“) t)
(add-to-list ‘load-path “~/.emacs.d/elpa/vlf-1.7/”)
(package-initialize) ;auto set load-path of installed pkg and load them
;;common lisp + slime
(defun my-load-slime-and-set ()
(interactive) “the magic of eclip command”
(load (expand-file-name “E:/PL/lispstick/quicklisp-down/slime-helper.el”))
(setq inferior-lisp-program “sbcl”)
(slime) “M-x slime”
)
(global-set-key (kbd “ ”) ‘my-load-slime-and-set)

加到鼠标右键上下文菜单

假设emacs解压到c:\emacs,从cmd启动:
C:\emacs\bin\runemacs.exe -Q –load .emacs
通常我们希望对一个文件点右键就可以打开,把下面的另存为right-menu.reg, 双击运行就行了:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*\shell\emacs]
@=”emacs”
[HKEY_CLASSES_ROOT*\shell\emacs\command]
@=”C:\emacs\bin\runemacs.exe -Q –load E:\PL\lispstick\.emacs \”%1\”“

emacs + slime 操作

window:
C-x 3 vertical split
C-x o move to next window
C-x 0 kill current window
C-x 1 kill all windows except current window

buffer:
C-x C-f find and load file
C-x C-w save as
C-x C-s save
C-mouse
C-x LEFT/RIGHT ARROW switch buffer
C-x C-q toggle read-only/read-write
C-x k kill current buffer

frame:
C-x 5 2 make new frame
C-x 5 o move to next frame

Edit:
C-a C-k kill whole line
C-x u undo last operaption
C-x z repeat last command
Esc n op repead n times

Move:
C-a 移到行首(ahead),C-e行尾
C-v page down
M-v page up

Search:
M-x o ;vimgrep

Highlight:
M-s h r ;highlight regexp
M-s h u ;unhighlight regexp

Setting:
C-h v A;check variables A’s value
M-x set-variable next-screen-context-lines
M-: (getenv “HOME”)
M-: (expand-file-name “~”)
M-x linum-mode ; toggles the line number mode on and off
M-x (require ‘vlf-setup) ; M-x vlf to open very large file

M-x slime 打开repl buffer
当焦点在repl buffer时:
TAB 命令补全
C-Enter 自动补充上括号并求值
C-c M-o 清空显示

当焦点在text buffer时:
C-c C-k 编译当前文件并加载
C-c C-l 选择一个文件加载
C-c C-c 编译当前光标处的toplevel form。
C-M-q 自动缩进
C-c C-] 补全右括号
C-M-a C-M-e M-x slime-end-of-defun

C-c C-c 是体现了lisp的interactive
C-x C-e 对光标处求值,不用print
C-M-x 对当前的toplevel form求值
C-c C-r 对选中的区域求值

C-c < list callers
C-c > list callees

C-c C-t 打开或关闭当前光标处的trace.
M-x slime-untrace-all

教程

ansi common lisp: https //7chan.org/pr/src/ANSI_Common_Lisp_-_Paul_Graham.pdf

创建独立的可执行程序

lispstick\Steel Bank Common Lisp\1.1.12
.\sbcl.exe –core sbcl.core

(defun main () (print “hello”))
(sb-ext:save-lisp-and-die “hello.exe” :toplevel #’main :executable t)

.\hello.exe
这个文件有31MB!
我也试过allegro CL的,太复杂了,没成功。

vim lisp 设置

vim我更熟练,也有类似slime的叫slimv:
https://bitbucket.org/kovisoft/slimv/get/bd61b0a83d66.zip
它会自动检测sbcl的安装位置,把它丢到vimfiles/bundle下面就行了,
.vimrc设置:

“slimv
let g:paredit_mode = 1 “输入’(‘时自动加上’)’
let g:paredit_electric_return = 0 “防止Enter换行时把’)’单独一行
let g:lisp_rainbow = 1 “更花哨些

总的说来

虽然vim也支持lisp,但是emacs支持得更好。

ref

http://www.sbcl.org/manual/

 类似资料: