Can you use emacs to program in common lisp?

During my course on lisp programming I used the lispworks IDE trial version, which is a very good IDE but it's still a trial version. I searched for a new IDE. And I saw this video

In which he uses slime sbcl and quicklisp to program in common lisp on emacs.

My question is how is that possible?Doesn't emacs come with it's own dialect of lisp which is known as Emacs lisp or are they separate from each other?

4 answers

  • answered 2018-07-11 04:27 Basile Starynkevitch

    Emacs is an extensible editor (scriptable in Elisp). Read its documentation.

    Its slime-mode (written in Elisp on emacs side, and in Common Lisp on your Lisp system's side) is able to interact with Common Lisp implementations. But you need to install that. Read the documentation of slime. Some Linux distributions are packaging slime (e.g. Debian has some slime package).

    Emacs has many other modes (i.e. extensions, provided in Elisp) able to interact with various other programming languages implementations and other applications (shells, email, version control, ...).

    BTW, Common Lisp HyperSpec is freely available. Read it. And SBCL is also documented.

    You don't need any IDE to use SBCL (or Clisp, or most Common Lisp implementations....). You can use the REPL (inside of emacs or outside of it) and perhaps some editor (e.g. emacs -without even slime-, vim, gedit, ....). When I try some simple code with SBCL, I don't use SLIME (just the REPL, perhaps copy/paste from some editor, and editing a Lisp file then load-ing in Lisp). SLIME is convenient, but is a luxury that you can avoid. However, it is more easy to you to use some editor capable of matching parenthesis (and of skipping lisp comments). But you could code some Common Lisp program -even with many thousands of lines and several dozens of files- even with an editor as simplistic as Notepad on Windows (or Leafpad or nano on Linux). Your editor don't need to "know" Lisp (e.g. have some mode, or some syntactic variant, for it), since lisp syntax is very regular and simple.

    Notice that a programming language is a specification (given in some technical report, often in English - the HyperSpec) and should not be confused by its implementation (e.g. some software like SBCL or Clisp).

    I actually wrote all my Lisp programs with emacs but without slime. And I developed a Lisp dialect (GCC MELT) and implemented it -it is free software that I abandoned, but you can still download it- with emacs but without using Slime. So Slime is really not a requirement, even to code a Lisp program of dozens of thousands of lines. Slime is a luxury you can avoid. The Lisp-mode of emacs is more than enough (even to code a program of several thousands of Common Lisp lines).

    PS. The largest program I have written in Common Lisp was the prebootstrap primordial compiler of GCC MELT, since I bootstrapped GCC MELT I have lost all that large program (because I didn't need it any more). IIRC that thing -prebootstrap MELT- had a dozen of thousands lines of Common Lisp. GCC MELT had more than 120KLOC.

    PPS. I actually recommend to not use any IDE in Common Lisp if you are a newbie. Use just the REPL and some editor (and of course a good Common Lisp implementation such as SBCL). Leave slime to Lisp experts. Only start using slime when you are fluent enough in Common Lisp (and its REPL).

  • answered 2018-07-11 08:50 Gwang-Jin Kim

    Setting up Emacs and SBCL can cost you some time. I highly recommend you portacle - so to say the newer/younger brother of lispbox. Lispbox is created for 'out of the box'-to go lisp environment using emacs with installed slime-mode readily connected with sbcl and quicklisp-installed (for readers of 'Practical Common Lisp' by Peter Seibel) - kind of emacs-set-up-for-Lisp (or batteries-included-emacs from the perspective of a Lisp-beginner-programmer). I was long searching for this "update" of Lispbox - though meanwhile installed sbcl and quicklisp and slime manually - Actually I think the Lispbox site should link and hint to portacle because this is the up-to-date version of Lispbox - it would have saved me time. The Lisp community should spread the words about portacle. (both provide you with ready-to-go emacs which then is connected to sbcl and also has quicklisp installed - quicklisp for Lisp is like pip for Python, a package manager by which you can pull and install Lisp packages from a central repository - or like melpa for emacs lisp). (quicklisp is in its core asdf, an old package manager, but nobody nowadays uses asdf to install packages directly, but does it via quicklisp).

    For an easier entry to emacs which is very complex and I had also several attempts to get to used to it, I highly recommend you Derek Banas' video tutorial on emacs which is one of the best intro-level tutorial I found for this topic. Also his tutorial for common lisp might give you a good start.

    The Common Lisp HyperSpec is helpful if you really begin to program in Lisp - it is a necessary tool, I would say - and also the Cookbook page for Lisp initiated by Edi Weitz and also his book with recipes for Common Lisp. However, since Lisp is very different from all the C-derived languages, I highly recommend you to begin with sth which explains you more what lisp is and how it works. A combination of Practical Common Lisp by Peter Seibel and Land of Lisp by Conrad Barski was the starter for me. But although the authors did really a great job, I think a easy-to-read and smooth intro for C-derived language programmer into Lisp is still to be written.

    By the way, if you find vim easier to use, there is a nice way to use vim short-cuts in emacs - the evil mode - and even better and fantastic is Spacemacs which has in addition to vim shortcuts - their very specific way to access functions - mostly beginning with pressing the space-button (thus the name spacemacs). It is an open source project.

    Unfortunately there is no Portacle-like batteries-included spacemacs for lisp novices. But maybe that is to be set up in near future by some of us :) . Spacemacs is fantastic!

  • answered 2018-07-11 10:00 Ehvince

    Well yes, Emacs is the "go to" Common Lisp editor :)

    We can still use more editors: Atom and Sublime don't have great support though (no interactive debugger yet, even if it's in development for Atom). Lem is a Common Lisp editor written… in Common Lisp, with also other modes (a Go mode, a directory mode,…). It exists for the console and has an Electron interface.

    This is an up to date guide on how to install a Lisp implementation and Quicklisp: (it might not be complete for windows).

    Other nice Lisp resources:

  • answered 2018-07-11 11:15 Bozhidar Batsov

    Even though there are already a few good answers to the question, I'd like to add here an answer myself, mostly to mention a great alternative to SLIME for Common Lips development in Emacs.

    SLY is a fork of SLIME and contains the following improvements upon it:

    • Completely redesigned REPL based on Emacs's own full-featured comint.el
    • Live code annotations via a new sly-stickers contrib
    • Consistent interactive button interface. Everything can be copied to the REPL.
    • Doesn't need an extra package to work with company (a popular (code) completion package)
    • Contribs are are enabled by default, and loaded with ASDF on demand
    • Support for NAMED-READTABLES, macrostep.el and quicklisp

    SLY tracks SLIME's bugfixes and all its familar features (debugger, inspector, xref, etc...) are still available , but with better integration.

    Seems to me SLY is the best way to get started with Common Lisp under Emacs these days, so I encourage people to check it out.