summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-04-13 16:25:52 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-04-13 16:26:01 +0200
commit29fae93d1c480cc69406a19ab9ef69d84ef8142f (patch)
tree9b3c2cee14589c9b6b97724a26a1fccb453d4b9f /lisp/emacs-lisp
parente14e5dff2c5d8113b06e2aafa0d920120bdb68e9 (diff)
downloademacs-29fae93d1c480cc69406a19ab9ef69d84ef8142f.tar.gz
emacs-29fae93d1c480cc69406a19ab9ef69d84ef8142f.tar.bz2
emacs-29fae93d1c480cc69406a19ab9ef69d84ef8142f.zip
Add support for column background colors in vtable
* doc/misc/vtable.texi (Making A Table): Document it. * lisp/emacs-lisp/vtable.el (vtable): Add a column color element. (make-vtable): Use it. (vtable--insert-line): Insert the colors here.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/vtable.el15
1 files changed, 12 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el
index 8d777335315..98106e46700 100644
--- a/lisp/emacs-lisp/vtable.el
+++ b/lisp/emacs-lisp/vtable.el
@@ -57,6 +57,7 @@
(separator-width :initarg :separator-width :accessor vtable-separator-width)
(sort-by :initarg :sort-by :accessor vtable-sort-by)
(ellipsis :initarg :ellipsis :accessor vtable-ellipsis)
+ (column-colors :initarg :column-colors :accessor vtable-column-colors)
(-cache :initform (make-hash-table :test #'equal)))
"A object to hold the data for a table.")
@@ -83,7 +84,8 @@
(separator-width 1)
sort-by
(ellipsis t)
- (insert t))
+ (insert t)
+ column-colors)
"Create and insert a vtable at point.
The vtable object is returned. If INSERT is nil, the table won't
be inserted."
@@ -122,6 +124,7 @@ be inserted."
:keymap keymap
:separator-width separator-width
:sort-by sort-by
+ :column-colors column-colors
:ellipsis ellipsis)))
;; Compute missing column data.
(setf (vtable-columns table) (vtable--compute-columns table))
@@ -377,7 +380,8 @@ This also updates the displayed table."
(defun vtable--insert-line (table line widths spacer
&optional ellipsis ellipsis-width)
(let ((start (point))
- (columns (vtable-columns table)))
+ (columns (vtable-columns table))
+ (colors (vtable-column-colors table)))
(seq-do-indexed
(lambda (elem index)
(let ((value (nth 0 elem))
@@ -438,7 +442,12 @@ This also updates the displayed table."
(propertize " " 'display
(list 'space
:width (list spacer)))))
- (put-text-property start (point) 'vtable-column index))))
+ (put-text-property start (point) 'vtable-column index)
+ (when colors
+ (add-face-text-property
+ start (point)
+ (list :background
+ (elt colors (mod index (length colors)))))))))
(cdr line))
(insert "\n")
(put-text-property start (point) 'vtable-object (car line))))