Daily Archives: February 15, 2007

Using vi with Lisp

Most Lisp developers prefer emacs to vi since emacs allows one to run Lisp within a separate buffer with a tightly integrated compile/test cycle. For those already familiar with vi, vi can do two of the most important functions you would need from the editor:

  • balance the parentheses.
    set sm turns on the blinking of matching parens as you type the close parenthesis.
    Typing % when the cursor is on a parenthesis will move the cursor to the matching parenthesis.
  • indent expressions.
    vi allows to set different modes, either by setting them in your .cshrc file in the EXINIT variable (as shown later) or by setting them once you are in vi using the command :set . The modes you are interested in are:
    • set ai turns on auto-indentation. This means that each line you type will match the previous line’s indentation.
    • set lisp turns on lisp mode. This means the indenting is done as required by Lisp.

    You can set the desired modes to vi by adding this line to your .cshrc file:

    setenv EXINIT 'map # Ji^M^[|set wm=6 para=lpppipnpbp sect=shuh showmatch ai'

    or by defining in your .cshrc file an alias command for vi (in the example shown here is li ) that includes all the modes you want when using lisp:

    alias li "vi '+set ic lisp ai wm=0 |map # Ji^M^[ |1' \!*"

    You can also set the modes after you are in vi by typing :set ai lisp

When using Xwindows, the easiest solution is to have two xterm windows, one for Lisp and one for vi. Do not forget to reload your file into Lisp every time you change it.

Lisp tutorial

对Lisp没什么好感,但是为了做AI的作业,还是要看一下的。昨天搜了一下,发现没有什么写的比较好的tutorial,文档比起Python来说,网上的资源实在是很差。虽然AI的老师说作业可以用Python来做,虽然我对Python很感兴趣,但还是怕花的时间比直接学Lisp的时间还长。忍了,去看看Lisp吧,看看Lisp到底有多好,一个老美居然认为学会Lisp是他上AI的主要收获之一。

谢谢Sophie同学给的一些链接:

Learning Lisp
Common LISP Hints
Common Lisp: A Brief Tutorial
Programming in Emacs Lisp – An introduction
Paul Graham’s Lisp Page