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: Is it alright to define-derived-mode dynamically? Date: Fri, 25 Dec 2020 13:42:12 +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="20525"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0 (3d08634) (2020-11-07) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 25 11:45:24 2020 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 1kskb5-0005FW-Fs for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 25 Dec 2020 11:45:23 +0100 Original-Received: from localhost ([::1]:42328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kskb4-0006Ld-IZ for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 25 Dec 2020 05:45:22 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kskaX-0006LE-WE for help-gnu-emacs@gnu.org; Fri, 25 Dec 2020 05:44:50 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:39625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kskaR-0003O4-HL for help-gnu-emacs@gnu.org; Fri, 25 Dec 2020 05:44:49 -0500 Original-Received: from localhost ([::ffff:41.210.146.133]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000002DFDE.000000005FE5C298.00000A94; Fri, 25 Dec 2020 03:44:40 -0700 Mail-Followup-To: 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.23 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:126759 Archived-At: Thank you Stefan, I followed your advise and disintegrated functions. But it as tedious until I got it working. (defun rcd-db-report (title entries tabulated-list-format table tabulated-list-sort-key) (let* ((title (generate-new-buffer-name (concat "RCD Database: " title)))) (let* ((buffer title) (buffer (get-buffer-create buffer)) (mode-map (rcd-db-table-mode-map table))) ;; (message "Keymap: %s" table) (switch-to-buffer-other-window buffer) (delete-other-windows) (rcd-db-list-mode) ;; TODO if I move it from this line, weird things happen (use-local-map mode-map) ;; TODO if I move it from this line, weird things happen (tabulated-list-init-header) (setq tabulated-list-padding 1)) (setq tabulated-list-format tabulated-list-format) (setq tabulated-list-entries entries) (setq tabulated-list-sort-key tabulated-list-sort-key) ;;(tabulated-list-init-header) (tabulated-list-print t))) I have noticed that I could not just place `use-local-map' anywhere I wanted and by apparent random attempts I got it working. I do not know where the problem was. Problem was invoking another derived mode from tabulated-list-mode where the other mode did appear and it was populated but it was not visible. The text I could not see but entries were there and the lines in existence, just everything white. > First: > - It should be called `rcd-db-list-mode`. Done. > - Don't use global variables's names for local variables. Did you mean: (defvar-local rcd-tabulated-marked-items nil "Collects IDs for tabulated list modes") Now I use `defvar-local', so no need to to make it local additionally. I use that variable to mark items in the list so that I may make mass actions on various items. I was first thinking that function `tabulated-list-put-tag' does that. But it just places the tag. I cannot track the tag or process items by using the tag. It seem to be just visual tool. > - I doubt the mode needs `hl-line-mode`. If *you* like it, then use > something like (add-hook 'tabulated-list-mode-mode #'hl-line-mode) > in your init file. Done. I am using it that way now. Cursor is harder visible, I have made some quick delete functions without confirmation, so highlightin lines helps not to make mistake. > And you can do: > > (define-derived-mode rcd-db-list-mode tabulated-list-mode "Database List" > "Major mode to manipulate Database List reports." > [...]) > > (defun rcd-db-report ( title entries &optional list-format > list-sort-key mode-map) > [...] > (rcd-db-list-mode) > (use-local-map mode-map)) Done. I am doing that now, and you have noticed I guess so, that all that was to invoke different keymaps for different SQL tables. Thank you, Jean