aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/emacs-lisp/vtable.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/vtable.el')
-rw-r--r--lisp/emacs-lisp/vtable.el59
1 files changed, 45 insertions, 14 deletions
diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el
index 5b868440108..f2c20b6a806 100644
--- a/lisp/emacs-lisp/vtable.el
+++ b/lisp/emacs-lisp/vtable.el
@@ -145,8 +145,8 @@ See info node `(vtable)Top' for vtable documentation."
145 :ellipsis ellipsis))) 145 :ellipsis ellipsis)))
146 ;; Compute missing column data. 146 ;; Compute missing column data.
147 (setf (vtable-columns table) (vtable--compute-columns table)) 147 (setf (vtable-columns table) (vtable--compute-columns table))
148 ;; Compute colors if we have to mix them. 148 ;; Compute the colors.
149 (when (and row-colors column-colors) 149 (when (or row-colors column-colors)
150 (setf (slot-value table '-cached-colors) 150 (setf (slot-value table '-cached-colors)
151 (vtable--compute-colors row-colors column-colors))) 151 (vtable--compute-colors row-colors column-colors)))
152 ;; Compute the divider. 152 ;; Compute the divider.
@@ -175,9 +175,41 @@ See info node `(vtable)Top' for vtable documentation."
175 table)) 175 table))
176 176
177(defun vtable--compute-colors (row-colors column-colors) 177(defun vtable--compute-colors (row-colors column-colors)
178 (cl-loop for row in row-colors 178 (cond
179 collect (cl-loop for column in column-colors 179 ((null column-colors)
180 collect (vtable--color-blend row column)))) 180 (mapcar #'vtable--make-color-face row-colors))
181 ((null row-colors)
182 (mapcar #'vtable--make-color-face column-colors))
183 (t
184 (cl-loop for row in row-colors
185 collect (cl-loop for column in column-colors
186 collect (vtable--face-blend
187 (vtable--make-color-face row)
188 (vtable--make-color-face column)))))))
189
190(defun vtable--make-color-face (object)
191 (if (stringp object)
192 (list :background object)
193 object))
194
195(defun vtable--face-blend (face1 face2)
196 (let ((foreground (vtable--face-color face1 face2 #'face-foreground
197 :foreground))
198 (background (vtable--face-color face1 face2 #'face-background
199 :background)))
200 `(,@(and foreground (list :foreground foreground))
201 ,@(and background (list :background background)))))
202
203(defun vtable--face-color (face1 face2 accessor slot)
204 (let ((col1 (if (facep face1)
205 (funcall accessor face1)
206 (plist-get face1 slot)))
207 (col2 (if (facep face2)
208 (funcall accessor face2)
209 (plist-get face2 slot))))
210 (if (and col1 col2)
211 (vtable--color-blend col1 col2)
212 (or col1 col2))))
181 213
182;;; FIXME: This is probably not the right way to blend two colors, is 214;;; FIXME: This is probably not the right way to blend two colors, is
183;;; it? 215;;; it?
@@ -441,10 +473,11 @@ This also updates the displayed table."
441 (let ((start (point)) 473 (let ((start (point))
442 (columns (vtable-columns table)) 474 (columns (vtable-columns table))
443 (column-colors 475 (column-colors
444 (if (vtable-row-colors table) 476 (and (vtable-column-colors table)
445 (elt (slot-value table '-cached-colors) 477 (if (vtable-row-colors table)
446 (mod line-number (length (vtable-row-colors table)))) 478 (elt (slot-value table '-cached-colors)
447 (vtable-column-colors table))) 479 (mod line-number (length (vtable-row-colors table))))
480 (slot-value table '-cached-colors))))
448 (divider (vtable-divider table)) 481 (divider (vtable-divider table))
449 (keymap (slot-value table '-cached-keymap))) 482 (keymap (slot-value table '-cached-keymap)))
450 (seq-do-indexed 483 (seq-do-indexed
@@ -517,8 +550,7 @@ This also updates the displayed table."
517 (when column-colors 550 (when column-colors
518 (add-face-text-property 551 (add-face-text-property
519 start (point) 552 start (point)
520 (list :background 553 (elt column-colors (mod index (length column-colors)))))
521 (elt column-colors (mod index (length column-colors))))))
522 (when (and divider (not last)) 554 (when (and divider (not last))
523 (insert divider) 555 (insert divider)
524 (setq start (point)))))) 556 (setq start (point))))))
@@ -526,11 +558,10 @@ This also updates the displayed table."
526 (insert "\n") 558 (insert "\n")
527 (put-text-property start (point) 'vtable-object (car line)) 559 (put-text-property start (point) 'vtable-object (car line))
528 (unless column-colors 560 (unless column-colors
529 (when-let ((row-colors (vtable-row-colors table))) 561 (when-let ((row-colors (slot-value table '-cached-colors)))
530 (add-face-text-property 562 (add-face-text-property
531 start (point) 563 start (point)
532 (list :background 564 (elt row-colors (mod line-number (length row-colors))))))))
533 (elt row-colors (mod line-number (length row-colors)))))))))
534 565
535(defun vtable--cache-key () 566(defun vtable--cache-key ()
536 (cons (frame-terminal) (window-width))) 567 (cons (frame-terminal) (window-width)))