summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-04-23 14:47:55 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-04-23 14:47:55 +0200
commit2c0a01ee389944d95034ef673ff0255d99ef4b80 (patch)
tree9e8bd0f3ae5c84edd2430649ff4bd080622eafb8 /lisp/emacs-lisp
parentca5fb2b922581505ad96d7e03c2a7bba17adb8e8 (diff)
downloademacs-2c0a01ee389944d95034ef673ff0255d99ef4b80.tar.gz
Don't make a header if the user hasn't specified columns in vtable
* lisp/emacs-lisp/vtable.el (vtable): (make-vtable): Store whether the user has specified the columns. (vtable-insert): Don't insert a header line or a header if the user hasn't specified the columns (bug#55075).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/vtable.el66
1 files changed, 36 insertions, 30 deletions
diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el
index 7148844b638..61265c97c28 100644
--- a/lisp/emacs-lisp/vtable.el
+++ b/lisp/emacs-lisp/vtable.el
@@ -68,7 +68,8 @@
(row-colors :initarg :row-colors :accessor vtable-row-colors)
(-cached-colors :initform nil)
(-cache :initform (make-hash-table :test #'equal))
- (-cached-keymap :initform nil))
+ (-cached-keymap :initform nil)
+ (-has-column-spec :initform nil))
"An object to hold the data for a table.")
(defvar-keymap vtable-map
@@ -106,29 +107,11 @@ be inserted.
See info node `(vtable)Top' for vtable documentation."
(when objects-function
(setq objects (funcall objects-function)))
- ;; Auto-generate the columns.
- (unless columns
- (unless objects
- (error "Can't auto-generate columns; no objects"))
- (setf columns (make-list (length (car objects)) "")))
- (setq columns (mapcar (lambda (column)
- (cond
- ;; We just have the name (as a string).
- ((stringp column)
- (make-vtable-column :name column))
- ;; A plist of keywords/values.
- ((listp column)
- (apply #'make-vtable-column column))
- ;; A full `vtable-column' object.
- (t
- column)))
- columns))
;; We'll be altering the list, so create a copy.
(setq objects (copy-sequence objects))
(let ((table
(make-instance
'vtable
- :columns columns
:objects objects
:objects-function objects-function
:getter getter
@@ -143,6 +126,26 @@ See info node `(vtable)Top' for vtable documentation."
:row-colors row-colors
:column-colors column-colors
:ellipsis ellipsis)))
+ ;; Store whether the user has specified columns or not.
+ (setf (slot-value table '-has-column-spec) (not (not columns)))
+ ;; Auto-generate the columns.
+ (unless columns
+ (unless objects
+ (error "Can't auto-generate columns; no objects"))
+ (setq columns (make-list (length (car objects)) "")))
+ (setf (vtable-columns table)
+ (mapcar (lambda (column)
+ (cond
+ ;; We just have the name (as a string).
+ ((stringp column)
+ (make-vtable-column :name column))
+ ;; A plist of keywords/values.
+ ((listp column)
+ (apply #'make-vtable-column column))
+ ;; A full `vtable-column' object.
+ (t
+ column)))
+ columns))
;; Compute missing column data.
(setf (vtable-columns table) (vtable--compute-columns table))
;; Compute the colors.
@@ -446,17 +449,20 @@ This also updates the displayed table."
;; correctly if Emacs is open on two different screens (or the
;; user resizes the frame).
(widths (nth 1 (vtable--ensure-cache table))))
- (if (vtable-use-header-line table)
- (vtable--set-header-line table widths spacer)
- ;; Insert the header line directly into the buffer, and put a
- ;; keymap to be able to sort the columns there (by clicking on
- ;; them).
- (vtable--insert-header-line table widths spacer)
- (add-text-properties start (point)
- (list 'keymap vtable-header-line-map
- 'rear-nonsticky t
- 'vtable table))
- (setq start (point)))
+ ;; Don't insert any header or header line if the user hasn't
+ ;; specified the columns.
+ (when (slot-value table '-has-column-spec)
+ (if (vtable-use-header-line table)
+ (vtable--set-header-line table widths spacer)
+ ;; Insert the header line directly into the buffer, and put a
+ ;; keymap to be able to sort the columns there (by clicking on
+ ;; them).
+ (vtable--insert-header-line table widths spacer)
+ (add-text-properties start (point)
+ (list 'keymap vtable-header-line-map
+ 'rear-nonsticky t
+ 'vtable table))
+ (setq start (point))))
(vtable--sort table)
;; Insert the data.
(let ((line-number 0))