Difference between revisions of "Common Lisp"

From WikEmacs
Jump to: navigation, search
m (added category)
(Added a basic Common Lisp page)
Line 1: Line 1:
 +
Emacs ships with a lisp-mode for Common Lisp that supports basic stuff like indentation, sexp navigation and font-locking.
 +
 +
If you're doing serious Common Lisp development you should have a look at the complementary [[SLIME]], which gives you the ability to develop Lisp programs interactively. Here's a few useful Emacs Lisp code snippets
 +
for your SLIME configuration:
 +
 +
<syntaxhighlight lang="lisp">
 +
;; a list of alternative Common Lisp implementations that can be
 +
;; used with SLIME. Note that their presence render
 +
;; inferior-lisp-program useless. This variable holds a list of
 +
;; programs and if you invoke SLIME with a negative prefix
 +
;; argument, M-- M-x slime, you can select a program from that list.
 +
(setq slime-lisp-implementations
 +
      '((ccl ("ccl"))
 +
        (clisp ("clisp" "-q"))
 +
        (cmucl ("cmucl" "-quiet"))
 +
        (sbcl ("sbcl" "--noinform") :coding-system utf-8-unix)))
 +
 +
;; select the default value from slime-lisp-implementations
 +
(if (eq system-type 'darwin)
 +
    ;; default to Clozure CL on OS X
 +
    (setq slime-default-lisp 'ccl)
 +
  ;; default to SBCL on Linux and Windows
 +
  (setq slime-default-lisp 'sbcl))
 +
 +
(add-hook 'lisp-mode-hook (lambda () (run-hooks 'prelude-lisp-coding-hook)))
 +
(add-hook 'slime-repl-mode-hook (lambda () (run-hooks 'prelude-interactive-lisp-coding-hook)))
 +
 +
;; start slime automatically when we open a lisp file
 +
(defun prelude-start-slime ()
 +
  (unless (slime-connected-p)
 +
    (save-excursion (slime))))
 +
 +
(add-hook 'slime-mode-hook 'prelude-start-slime)
 +
 +
;; Stop SLIME's REPL from grabbing DEL,
 +
;; which is annoying when backspacing over a '('
 +
(defun prelude-override-slime-repl-bindings-with-paredit ()
 +
  (define-key slime-repl-mode-map
 +
    (read-kbd-macro paredit-backward-delete-key) nil))
 +
 +
(add-hook 'slime-repl-mode-hook 'prelude-override-slime-repl-bindings-with-paredit)
 +
 +
(eval-after-load "slime"
 +
  '(progn
 +
    (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol
 +
          slime-fuzzy-completion-in-place t
 +
          slime-enable-evaluate-in-emacs t
 +
          slime-autodoc-use-multiline-p t)
 +
 +
    (define-key slime-mode-map (kbd "TAB") 'slime-indent-and-complete-symbol)
 +
    (define-key slime-mode-map (kbd "C-c i") 'slime-inspect)
 +
    (define-key slime-mode-map (kbd "C-c C-s") 'slime-selector)))
 +
</syntaxhighlight>
 +
 
== Books ==  
 
== Books ==  
 
* [http://www.gigamonkeys.com/book/ Practical Common Lisp (Book)]
 
* [http://www.gigamonkeys.com/book/ Practical Common Lisp (Book)]

Revision as of 15:39, 24 March 2012

Emacs ships with a lisp-mode for Common Lisp that supports basic stuff like indentation, sexp navigation and font-locking.

If you're doing serious Common Lisp development you should have a look at the complementary SLIME, which gives you the ability to develop Lisp programs interactively. Here's a few useful Emacs Lisp code snippets for your SLIME configuration:

;; a list of alternative Common Lisp implementations that can be
;; used with SLIME. Note that their presence render
;; inferior-lisp-program useless. This variable holds a list of
;; programs and if you invoke SLIME with a negative prefix
;; argument, M-- M-x slime, you can select a program from that list.
(setq slime-lisp-implementations
      '((ccl ("ccl"))
        (clisp ("clisp" "-q"))
        (cmucl ("cmucl" "-quiet"))
        (sbcl ("sbcl" "--noinform") :coding-system utf-8-unix)))
 
;; select the default value from slime-lisp-implementations
(if (eq system-type 'darwin)
    ;; default to Clozure CL on OS X
    (setq slime-default-lisp 'ccl)
  ;; default to SBCL on Linux and Windows
  (setq slime-default-lisp 'sbcl))
 
(add-hook 'lisp-mode-hook (lambda () (run-hooks 'prelude-lisp-coding-hook)))
(add-hook 'slime-repl-mode-hook (lambda () (run-hooks 'prelude-interactive-lisp-coding-hook)))
 
;; start slime automatically when we open a lisp file
(defun prelude-start-slime ()
  (unless (slime-connected-p)
    (save-excursion (slime))))
 
(add-hook 'slime-mode-hook 'prelude-start-slime)
 
;; Stop SLIME's REPL from grabbing DEL,
;; which is annoying when backspacing over a '('
(defun prelude-override-slime-repl-bindings-with-paredit ()
  (define-key slime-repl-mode-map
    (read-kbd-macro paredit-backward-delete-key) nil))
 
(add-hook 'slime-repl-mode-hook 'prelude-override-slime-repl-bindings-with-paredit)
 
(eval-after-load "slime"
  '(progn
     (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol
           slime-fuzzy-completion-in-place t
           slime-enable-evaluate-in-emacs t
           slime-autodoc-use-multiline-p t)
 
     (define-key slime-mode-map (kbd "TAB") 'slime-indent-and-complete-symbol)
     (define-key slime-mode-map (kbd "C-c i") 'slime-inspect)
     (define-key slime-mode-map (kbd "C-c C-s") 'slime-selector)))

Books