From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Is it alright to define-derived-mode dynamically?
Date: Thu, 24 Dec 2020 09:44:52 -0500 [thread overview]
Message-ID: <jwv8s9ns22d.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: courier.000000005FE4410C.00005C0B@stw1.rcdrun.com
> I wonder if it is alright to define the derived mode dynamically
> within a function:
For your own personal use, it may work just fine.
For an ELisp package that you expect other people to use, it'll bite
them sooner or later.
> (defun rcd-db-report (title entries &optional tabulated-list-format
> tabulated-list-sort-key mode-map)
[...]
> (define-derived-mode rcd-db-list tabulated-list-mode "Database List" "Database List Report"
> (hl-line-mode)
> (use-local-map mode-map)
[...]
> (rcd-db-list))))
First:
- It should be called `rcd-db-list-mode`.
- Don't use global variables's names for local variables.
- 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.
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))
> I can see that I may define function within a function as well, but I
> wonder if that is alright.
`defun` manipulates the global environment (not just some environment
local to your `rcd-db-report`), and it throws away any previous
definition of the function, which is often not alright.
Stefan
next prev parent reply other threads:[~2020-12-24 14:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-24 7:19 Is it alright to define-derived-mode dynamically? Jean Louis
2020-12-24 14:44 ` Stefan Monnier [this message]
2020-12-25 10:42 ` Jean Louis
2020-12-25 17:34 ` Stefan Monnier
2020-12-25 20:03 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv8s9ns22d.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.