unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel@gnu.org, mickey@masteringemacs.org,
	theo@thornhill.no, dgutov@yandex.ru
Subject: Re: Extending define-derived-mode
Date: Fri, 2 Jun 2023 00:45:31 -0700	[thread overview]
Message-ID: <C4869441-7F23-41EE-9E0E-30FAF6676CD0@gmail.com> (raw)
In-Reply-To: <83edmventk.fsf@gnu.org>



> On May 31, 2023, at 10:47 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Wed, 31 May 2023 13:48:56 -0700
>> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
>> emacs-devel@gnu.org,
>> mickey@masteringemacs.org,
>> theo@thornhill.no,
>> dgutov@yandex.ru
>> 
>>> This is not simple in practice.  Ask yourself why don't the
>>> FOO-ts-mode's simply run the (existing) hooks of FOO-mode?  Look at
>>> the code, and you will understand: the stuff people put in these hooks
>>> usually customizes aspects that are very different in each of the
>>> modes: font-lock, indentation, syntax tables, supporting "electric"
>>> sub-modes, styles of comments and other things, etc.  The few places
>>> where the new TS modes tried to run the same hooks and share most of
>>> the initialization code (for example, bash-ts-mode and sh-mode,
>>> python-ts-mode and python-mode) introduced subtle bugs which were only
>>> recently fixed.  One problem with inheriting from the same base mode
>>> is that doing initialization there could be problematic because the
>>> mode stuff that gets automatically instantiated and initialized by
>>> define-derived-mode, such as the mode's map and variable, is not yet
>>> set up when the base mode's initialization runs, so you cannot do some
>>> of the things we are used to do there, like setting up the menu-bar
>>> menus.
>>> 
>>> So it would seem that, for efficient and convenient facilities of this
>>> kind, we need some way of defining stuff in the base mode, which will
>>> be actually run later, when the child mode is set up.
>> 
>> I don’t entirely understand the example. Say I have a xxx-base-mode, and I want to setup menu-bar menus in it to be shared by xxx-mode and xxx-ts-mode. What is the problem that I’m gonna run into? Couldn’t you just use the base-mode’s keymap?
> 
> A base mode usually doesn't have a map, only the actually used derived
> modes do.

We can create a map for the base mode, and the child mode’s map will inherit from it.

Yuan




  reply	other threads:[~2023-06-02  7:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  5:16 Extending define-derived-mode Yuan Fu
2023-05-30  5:51 ` Theodor Thornhill
2023-05-31 20:35   ` Yuan Fu
2023-06-01  5:43     ` Theodor Thornhill
2023-05-30 10:48 ` Eli Zaretskii
2023-05-30 14:16   ` Stefan Monnier
2023-05-31 21:31     ` Yuan Fu
2023-06-01  4:06       ` Stefan Monnier
2023-06-01  6:39         ` Eli Zaretskii
2023-06-02  7:50           ` Yuan Fu
2023-06-02 11:54             ` Eli Zaretskii
2023-06-05  7:31               ` Yuan Fu
2023-06-05 11:33                 ` Eli Zaretskii
2023-06-08  7:25                   ` Yuan Fu
2023-06-02  7:44         ` Yuan Fu
2023-06-02 16:46           ` Stefan Monnier
2023-06-05  7:39             ` Yuan Fu
2023-06-05 15:17               ` Stefan Monnier
2023-05-31 20:48   ` Yuan Fu
2023-06-01  5:47     ` Eli Zaretskii
2023-06-02  7:45       ` Yuan Fu [this message]
2023-06-02 11:51         ` Eli Zaretskii
2023-05-30 17:24 ` Juri Linkov
2023-06-05  8:30 ` Philip Kaludercic

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=C4869441-7F23-41EE-9E0E-30FAF6676CD0@gmail.com \
    --to=casouri@gmail.com \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mickey@masteringemacs.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=theo@thornhill.no \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).