Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Commit

Permalink
Re-enabled dependence on array operations, leads to cleaner code.
Browse files Browse the repository at this point in the history
Removed duplicate code.
  • Loading branch information
tpapp committed Oct 8, 2012
1 parent c9f07c9 commit b04cb38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion latex-table.asd
Expand Up @@ -5,4 +5,4 @@
:serial t
:components ((:file "package")
(:file "latex-table"))
:depends-on (#:alexandria #:anaphora #:let-plus))
:depends-on (#:alexandria #:anaphora #:array-operations #:let-plus))
20 changes: 6 additions & 14 deletions latex-table.lisp
Expand Up @@ -430,7 +430,7 @@ automatically aligning string."
((:top :bottom) #\=)
((:middle) #\-))))))

(defun ascii-row (absolute-positions total-width column-types cells row-index)
(defun ascii-row (absolute-positions total-width column-types row)
"Render ROW in ASCII."
(let+ ((buffer (make-string total-width :initial-element #\space))
((&flet write-aligned (string alignment start-index
Expand All @@ -446,8 +446,9 @@ automatically aligning string."
alignment)
alignment))))))
(loop for col-index from 0
for element across row
for column-type across column-types
do (aetypecase (aref cells row-index col-index)
do (aetypecase element
(null)
(string (if (typep column-type 'numprint)
(write-aligned it (car (numprint-widths it)) col-index)
Expand Down Expand Up @@ -477,9 +478,10 @@ automatically aligning string."
(with-output (filespec-or-stream)
(write-rule 0)
(loop for row-index below (array-dimension cells 0)
for row across (ao:split cells 1)
do (fresh)
(dump (ascii-row absolute-positions total-width column-types
cells row-index))
row))
(write-rule (1+ row-index))))))
(:method (filespec-or-stream (table table)
&key (column-separator *ascii-column-separator*))
Expand All @@ -502,23 +504,13 @@ automatically aligning string."
(setf (aref cells row-index col-index)
(multicolumn alignment (aref cells row-index col-index) number)))

(defun vertical-to-cells (cells sequence &key (row-index 0) (col-index 0))
"Copy sequence to CELLS at the given indexes, vertically."
(loop for element across (coerce sequence 'vector)
for row-index from row-index
do (setf (aref cells row-index col-index) element)))

(defun labeled-vertical (labels values &key (labels-column :left)
(values-column :right) header?)
"Create a table labeling a vector as a vertical column. When HEADER? is
set, the top cells are treated as headers and centered, except when HEADER? is
'MULTICOLUMN, which centers it across the two columns."
(let* ((ncol (length values))
(cells (make-array (list ncol 2)))
(let* ((cells (ao:stack 1 (ao:reshape labels '(t 1)) (ao:reshape values '(t 1))))
(rules '((0 . :top) (-1 . :bottom))))
(assert (length= labels ncol))
(vertical-to-cells cells labels)
(vertical-to-cells cells values :col-index 1)
(when header?
(if (eq header? 'multicolumn)
(multicolumnf cells 0 0 2)
Expand Down

0 comments on commit b04cb38

Please sign in to comment.