使用 tabulated-list-print 打印任意数量的列

问题描述 投票:0回答:1

我有以下函数可以在缓冲区中显示表格。

但这只能处理两列。我怎样才能扩展它来处理 任意数量的列?

(defun tlprint-alist (alist &optional outbufr keytl valtl)
  "Print an associated list via `tabulated-list-print'."

  (let*
      ( (bufr (or outbufr (get-buffer-create "*Alist2*")))
        (keytl (or keytl "Key Title"))
        (valtl (or valtl "Value Title")) )

    (with-current-buffer bufr
      (tabulated-list-mode)
      (setq buffer-read-only nil)
      (setq tabulated-list-format
             (vector (list keytl 20 t) (list valtl 20 t)))
      (setq tabulated-list-sort-key (cons keytl nil))
      (setq tabulated-list-entries
            (mapcar (lambda (dyad)
                      (list (car dyad) (cdr dyad)))
                    alist))
      (tabulated-list-init-header)
      (tabulated-list-print) )))
elisp tabulate
1个回答
0
投票

对我来说似乎是这样:

(setq tabulated-list-format
         (vector (list keytl 20 t) (list valtl 20 t)))

必须扩展,或者以不同的方式写。

© www.soinside.com 2019 - 2024. All rights reserved.