Michael Weber: Random Bits and Pieces

...Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web Authoring just because these are the only things they happened to list.

Kent M. Pitman

Lisp Logo (by Conrad Barsky)

Some time ago, Xach mentioned his Elisp snippet which inserts DEFPACKAGE forms into the current buffer.

I finally beefed up my version a little, so that it uses Emacs' buffer filename as default package name. For quick dabbling, visiting a new file and typing RET RET RET is enough. Otherwise, packages to be USEd can be autocompleted from the lists of loaded packages, thanks to SLIME.

Here goes:

(define-skeleton mwe:cl-defpackage-skeleton
  "Inserts a Common Lisp DEFPACKAGE skeleton."
  (skeleton-read "Package: " (if v1
  (if (setq v1 (bobp)) ";;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp;")
  & (if buffer-file-coding-system
        (concat " Coding:"
                 (coding-system-get buffer-file-coding-system 
  & " -*-"
  & \n
  & \n "(defpackage #:" str
  \n "(:nicknames" ("Nickname: " " #:" str) & ")" | '(kill-whole-line -1)
  \n "(:use #:CL" ((slime-read-package-name "USEd package: ") " #:" str) ")"
  ")" \n
  (if v1 "(in-package #:") & str & ")" & \n &

Works with skeleton mode from GNU Emacs (version 22.0.92). First-time users of autoinsert might want to use the following additional setup:

(eval-after-load 'autoinsert
     (push '(lisp-mode . mwe:cl-defpackage-skeleton) auto-insert-alist)
     (auto-insert-mode +1)))

(require 'autoinsert)

It is also possible to just M-x mwe:cl-defpackage-skeleton. If done somewhere else than at the beginning of a buffer, the comment and IN-PACKAGE form is not generated (useful for a packages.lisp file containing multiple package forms.)

UPDATE 2008-01-08: Old News...

The above skeleton is part of Redshank mode now.