From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: variable tabulated-list-format Date: Mon, 17 Oct 2022 07:17:18 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38241"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.7+37 (a90f69b) (2022-09-02) Cc: help-gnu-emacs@gnu.org To: John Haman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 17 06:25:20 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okHgm-0009mg-Bs for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 17 Oct 2022 06:25:20 +0200 Original-Received: from localhost ([::1]:38090 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okHgk-0005UP-Sb for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 17 Oct 2022 00:25:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okHg9-0005TS-50 for help-gnu-emacs@gnu.org; Mon, 17 Oct 2022 00:24:41 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:40405) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okHg3-00072s-AO for help-gnu-emacs@gnu.org; Mon, 17 Oct 2022 00:24:40 -0400 Original-Received: from localhost ([::ffff:102.87.19.13]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000561CD.00000000634CD8FE.00007089; Sun, 16 Oct 2022 21:24:29 -0700 Mail-Followup-To: John Haman , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:140061 Archived-At: * John Haman [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/