From: Jean Louis <bugs@gnu.support>
To: John Haman <mail@johnhaman.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: variable tabulated-list-format
Date: Mon, 17 Oct 2022 07:17:18 +0300 [thread overview]
Message-ID: <Y0zXTjeBmS8ZO7u6@protected.localdomain> (raw)
In-Reply-To: <tii1bs$tln$1@ciao.gmane.io>
* John Haman <mail@johnhaman.org> [2022-10-17 01:43]:
> Hi everyone,
>
> I'm working on a mode that derives from tabulated-list-mode. My idea is to
> display small data.frames from ESS-R-mode using tabulated-list. As I may
> have several data.frames at a time, I need the header (column names) to vary
> with each call.
>
> Looking at the docs for tabulated-list-mode (https://www.gnu.org/software/emacs/manual/html_node/elisp/Tabulated-List-Mode.html),
> it looks like usage requires that my derived-mode specify the column names
> and meta-data (tabulated-lis-format) in my definition of the derived mode.
>
> Is there is way to do make `tabulated-list-format' variable? (that is, pass
> data to the macro define-derived-mode ?)
Of course.
Here is how similar mode is defined:
(define-derived-mode rcd-db-list-mode
tabulated-list-mode "About mode" "Description")
;; BTW, I need to highlight line in tabulatd list mode to avoid errors:
(add-hook 'tabulated-list-mode-hook #'hl-line-mode)
(defvar rcd-db-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map tabulated-list-mode-map)
(keymap-set map "g" #'goto-line)
(keymap-set map "u" #'rcd-tabulated-remove-marks)
(keymap-set map "v" #'rcd-tabulated-id-to-register)
(keymap-set map "\\" #'rcd-tabulated-filter-reset)
(keymap-set map "a" #'rcd-db-insert-new-row)
(keymap-set map "d" #'rcd-db-delete-tab-database-entry)
(keymap-set map "e" #'rcd-db-tabulated-edit-database-entry)
(keymap-set map "g" #'rcd-tabulated-refresh)
(keymap-set map "j" #'next-line)
(keymap-set map "k" #'previous-line)
(keymap-set map "m" #'rcd-tabulated-mark-id)
(keymap-set map "q" #'rcd-db-quit-window)
(keymap-set map "u" #'rcd-tabulated-unmark-id)
map)
"The basic RCD database keymap.")
Then I use generic function to report database entries, you need to adapt it, watch variables beginning with tabulated-list-
(defun rcd-db-report (title entries format database-type db-handle table sort-key &optional refresh highlight-list place id return-function)
"Main database report."
(setq rcd-db-current-database-type database-type)
(let* ((buffer (generate-new-buffer-name "My buffer")))
(let* ((buffer (get-buffer-create buffer))
(mode-map (rcd-db-table-mode-map table)))
(setq tabulated-list-format format)
(setq tabulated-list-entries entries)
(setq rcd-db-edited-table table)
(setq rcd-db-current-database-type database-type)
(setq rcd-tabulated-refresh-function refresh)
(setq rcd-current-return-function return-function)
(rcd-db-list-mode)
(use-local-map mode-map)
(setq rcd-db-current-database-handle db-handle)
(setq rcd-db-current-table (or (alist-get "table" place nil nil 'equal) table))
(setq rcd-db-current-table-id id)
(setq tabulated-list-padding 1)
(tabulated-list-init-header))
(setq tabulated-list-sort-key sort-key)
(tabulated-list-print t)
(when highlight-list
(rcd-highlight-list highlight-list))))
You need variables:
(setq tabulated-list-format format)
(setq tabulated-list-entries entries)
(setq tabulated-list-padding 1) ;; not necessary
(tabulated-list-init-header)
(setq tabulated-list-sort-key sort-key)
(tabulated-list-print t)
in my case, depending of the table or other factor, the report function automatically chooses key binding:
(defun rcd-db-table-mode-map (table)
"Generate mode map for table.
Use `rcd-db-current-database-type'."
(let ((symbol (format "rcd-db-%s-%s-mode-map" rcd-db-current-database-type table)))
(if (intern-soft symbol)
(symbol-value (intern symbol))
rcd-db-mode-map)))
(rcd-db-report "Title" '((1 ["Something" ("Button" action (lambda (b) (message "Hello")) font-lock-face link follow-link t)])) [("Column" 12 t) ("Links" 20 t)] "pg" nil "people" nil)
Functions in email will work, so if you evaluate the last one,
buffer will switch to tabulated list mode, it will be read only,
beware.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2022-10-17 4:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-16 22:42 variable tabulated-list-format John Haman
2022-10-17 4:17 ` Jean Louis [this message]
2022-10-17 18:42 ` John Haman
2022-10-18 1:01 ` John Haman
2022-10-17 4:24 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y0zXTjeBmS8ZO7u6@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
--cc=mail@johnhaman.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).