Paste number 4744: | Colorize example |
Pasted by: | luis |
When: | 13 years, 3 months ago |
Share: | Tweet this! | http://paste.lisp.org/+3NS |
Channel: | None |
Paste contents: |
;; (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: | 12 years, 4 months ago |
Share: | Tweet this! | http://paste.lisp.org/+3NS/1 |
Paste contents: |
;; 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: | 11 years, 11 months ago |
Share: | Tweet this! | http://paste.lisp.org/+3NS/2 |
Paste contents: |
ASDF ASDF ASDF