Testing out Lisp in Emacs

Set up development environment in Emacs

  • Emacs - The default editor for Lisp development and is written in Lisp itself including the configuration file. Install Emacs on Ubuntu is easy with sudo apt install emacs and for Windows you need to manually download the package for installation. It works on WSL too but only has the terminal version of Emacs.
  • SBCL - An implementation of Common Lisp by default in many editors and applications. Install SBCL with sudo apt install sbcl for Ubuntu.
  • Slime - An extension of the Emacs editor. The installation guide can be found here https://github.com/slime/slime
  • Quicklisp - Some commonly used libraries and utility functions for the current Lisp implementation like SBCL.

Basic usage of Emacs

  • Open a file C-x C-f to find the file and C-x s to save the changes

  • C-x z to suspend the editor and type %emacs to bring it back to the front. C-x C-c to permanently shut down the editor.

  • M-x slime to open the Slime editor

  • C-x 2 or C-x 3 to split the window vertically or horizontally and C-x o to switch between panes.

  • C-c C-c to compile the program in Slime

  • C-f Move forward a character C-b Move backward a character

    M-f Move forward a word M-b Move backward a word

    C-n Move to next line C-p Move to previous line

    C-a Move to beginning of line C-e Move to end of line

    M-a Move back to beginning of sentence M-e Move forward to end of sentence

  • M-w to copy and C-y to paste

Switch back to Vim but still with Emacs enabled

Enough..my fingers are not designed to hit CTRL and ALT every five seconds and I need to switch back to my Vim heaven. Fortunately we have a Vim plugin Vlime to rescue us from the nightmare of learning and configuring a new editor with very steep learning curve. The only reasons I decide to try Emacs is that I want to learn Lisp language,which uses Emacs as its default IDE and I saw some weird professors using Emacs to send emails a long time ago.

  • Download the Vlime repository and start a vlime server sbcl --load <vlime repo>/lisp/start-vlime.lisp.

  • Type \cc to build a connection between editor and the backend server. Type \cs to list all current connections. Type \cd to close the current connection.

  • \ss to evaluate the expression and \i to enable the interactive mode so you can just hit or by default to see the result of evaluation.

  • \of to compile the program and generate a new file ending with .fasl.