[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is it alright to define-derived-mode dynamically?
From: |
Jean Louis |
Subject: |
Re: Is it alright to define-derived-mode dynamically? |
Date: |
Fri, 25 Dec 2020 13:42:12 +0300 |
User-agent: |
Mutt/2.0 (3d08634) (2020-11-07) |
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