Paste number 4744: Colorize example

Index of paste annotations: 1 | 2

Paste number 4744: Colorize example
Pasted by: luis
When:9 years, 11 months ago
Share:Tweet this! | http://paste.lisp.org/+3NS
Channel:None
Paste contents:
Raw Source | XML | Display As
;; (require :cl-ppcre)
;; (require :colorize)

#| This little example opens a file, and looks for
   <!-- LISP foobar --> tokens which it then substitutes
   with the colorized code of the "foobar" file. |#

;; this regex needs some tweaking
(defparameter *rgx* "(.*)<!-- LISP +(\\S+) +-->(.*)")

(defun lisp-into-html (file-in file-out)
  (with-open-file (html file-in :direction :input)
    (with-open-file (out file-out :direction :output :if-exists :error)
      (loop with line
            while (setq line (read-line html nil nil))
            do (multiple-value-bind (found-p res)
                   (cl-ppcre:scan-to-strings *rgx* line)
                 (if found-p
                     (progn
                       (write-string (aref res 0) out)
                       (write-string "<div class=\"code\">" out)
                       (colorize:colorize-file-to-stream :common-lisp
                                                         (aref res 1) ; input file
                                                         out
                                                         :wrap nil)
                       (write-string "</div>" out)
                       (write-string (aref res 2) out)
                       (terpri))
                     (write-line line out)))))))

Annotations for this paste:

Annotation number 1: test-ppmx
Pasted by: verec
When:9 years, 3 weeks ago
Share:Tweet this! | http://paste.lisp.org/+3NS/1
Paste contents:
Raw Source | Display As
;; ppmx: pretty print macro expansion

(defmacro ppmx (form)
  "Pretty prints the macro expansion of FORM."
  `(let* ((exp1 (macroexpand-1 ',form))
          (exp (macroexpand exp1))
          (*print-circle* nil))
     (cond ((equal exp exp1)
            (format t "~&Macro expansion:")
            (pprint exp))
           (t (format t "~&First step of expansion:")
              (pprint exp1)
              (format t "~%~%Final expansion:")
              (pprint exp)))
     (format t "~%~%")
     (values)))

Annotation number 2: S
Pasted by: A
When:8 years, 7 months ago
Share:Tweet this! | http://paste.lisp.org/+3NS/2
Paste contents:
Raw Source | Display As
ASDF ASDF ASDF

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.