1 ;;; -*- Mode: lisp; outline-regexp: ";;;;;*"; indent-tabs-mode: nil -*-;;;
3 ;;; file: smarkup-asdf.cl
4 ;;; author: cyrus harmon
7 ;;; miscellaneous functions
11 (defgeneric render-as
(type sexp file
))
13 (defun remove-from-plist (plist &rest keys
)
14 (cond ((eql (length keys
) 1)
15 (loop for
(x y
) on plist by
#'cddr
16 append
(unless (eql x
(car keys
))
19 (reduce (lambda (&optional plist x
)
20 (when x
(remove-from-plist plist x
)))
23 (defun remove-pair-from-list (list key
)
24 (let ((pos (position key list
)))
26 (append (subseq list
0 pos
)
27 (subseq list
(+ pos
2))))))
29 (defun find-file-for-types (default-file types
)
30 (loop for type in types
31 do
(let ((path (merge-pathnames (make-pathname :type type
) default-file
)))
32 (when (probe-file path
)
35 (defparameter *images-per-line
* 5)
36 (defparameter *images-per-page
* 30)
38 (defun multi-line-figure (image-sequence
44 (images-per-line *images-per-line
*)
46 (let* ((image-sequence
50 (end (or end
(1- (length image-sequence
)))))
51 (when (some #'identity image-sequence
)
53 ,@(when label
`(:label
,label
))
55 ,@(loop for i from start to end by images-per-line
59 for j from i to
(min (+ i images-per-line -
1) end
)
61 (let ((img (elt image-sequence j
)))
62 `(:image
,(namestring img
)
64 ,(when caption
`(:caption
,@(if (listp caption
) caption
(list caption
))))))))
67 (defun multi-multi-line-figure (image-sequence
70 (first-caption caption
)
73 (images-per-line *images-per-line
*)
74 (images-per-page *images-per-page
*)
76 (let* ((image-sequence
80 (end (or end
(1- (length image-sequence
)))))
82 ,@(loop for i from start to end by images-per-page
84 (multi-line-figure image-sequence
(if (= i start
)
87 :start i
:end
(min (+ i images-per-page -
1) end
)
88 :images-per-line images-per-line
93 (defun multi-line-subfigure (image-sequence
97 (end (1- (length image-sequence
)))
98 (images-per-line *images-per-line
*)
100 (when (some #'identity image-sequence
)
102 ,@(loop for i from start to end by images-per-line
106 for j from i to
(min (+ i images-per-line -
1) end
)
108 (let ((img (elt image-sequence j
)))
109 `(:image
,(namestring img
)
113 ,@(when caption
`(:caption
,caption
)))))
115 (defun multi-line-subfigure (image-sequence
119 (end (1- (length image-sequence
)))
120 (images-per-line *images-per-line
*)
123 (when (some #'identity image-sequence
)
125 (loop for i from start to end by images-per-line
131 for j from i to
(min (+ i images-per-line -
1) end
)
133 (let ((img (elt image-sequence j
)))
134 `(:image
,(namestring img
)
136 (if (and caption
(> (+ i images-per-line
) end
))
138 (unless increment-counter
139 `(:increment-counter nil
)))))))))