datum #;(comments) for common lisp

Upstream URL



Tom Gillespie <tgbugs@gmail.com>


Public Domain (Unlicense)
datum comments for common lisp


Racket style #; comments implemented as a dispatch macro.

#; ; regular comments are treated as whitespace
(and the next datum is skipped by the reader)
#; (so you can skip a datum inline) (print "and not just a line or block")



(ql:quickload :datum-comments)
#;(skip) '(show)  ; datum comments work immediately after quickload

1.2Manual install

Using sbcl as an example.
git clone https://github.com/tgbugs/datum-comments.git
cat "(push (truename #p\"datum-comments\") asdf:*central-registry*)" >> ~/.sbclrc
sbcl --eval "(asdf:load-system :datum-comments) #;(i im a comment) (print 'hello)"


Since comments are a fundamental part of a language datum-comments automaticallyregisters itself as a dispatch macro for the #; symbol. Install via one of themethods above and then include :datum-comments in the :use section ofdefpackage where you want to be able to use datum comments, e.g. as
(defpackage :my-package
  (:use :cl :datum-comments))

at which point you can #;(use datum comments to your heart's content)

3Implementation support

This should work on any cl that has asdf, and the copy/paste versionbelow should work on pretty much anything.See travis for the listof tested working implementations.


(defpackage :datum-comments
  (:use :cl))
(in-package :datum-comments)
(defun datum-comment (stream char arg)
  (declare (ignore char arg))
  (read-preserving-whitespace stream t nil t)
(set-dispatch-macro-character #\# #\; #'datum-comment)

5Syntax highlighting and editing

An experimental datum-comments-mode is available for emacs. A minimalentry for ~/.emacs/init.elis below.
(use-package lisp-mode
  (use-package datum-comments
    :load-path "~/git/datum-comments" ;; adjust accordingly
    :hook (lisp-mode . datum-comments-mode)))

This will probably fail right now unless you also have slime enabled, and has not been sufficiently tested.

Support for named readtables or detection by slime of a datum-comments feature has not been implemented but is planned.

There are also known bugs with the interaction between regular comments and datum comments causing datum comments to be highlighted incorrectly.

6Racket behavior for comparison

#lang racket/base
#;(this is commented out) '(this is not) ; this is
#;(this should break how does greg avoid the issue? ; this is a comment)
        and this is open ended)

(test this should ;be ok right?)
      #; nothing)

;; double, the racket behavior is as expected, comments are comments
#; ; help I'm
#; ; trapped in
(one fish) ; yay!
(two fish) ; woo!

#; #; 'one 'two 'three

Dependencies (0)

    Dependents (0)

      • GitHub
      • Quicklisp