From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Extending define-derived-mode Date: Thu, 01 Jun 2023 08:47:19 +0300 Message-ID: <83edmventk.fsf@gnu.org> References: <20F07C52-6B39-4B24-8433-82E2226EADA6@gmail.com> <83zg5mf62s.fsf@gnu.org> <88498EC5-0870-45ED-802D-85286FB2E9FC@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34528"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org, mickey@masteringemacs.org, theo@thornhill.no, dgutov@yandex.ru To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jun 01 07:47:13 2023 Return-path: Envelope-to: ged-emacs-devel@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 1q4b9U-0008pQ-Bq for ged-emacs-devel@m.gmane-mx.org; Thu, 01 Jun 2023 07:47:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4b92-0008Mo-Dt; Thu, 01 Jun 2023 01:46:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4b8x-0008ML-Lf for emacs-devel@gnu.org; Thu, 01 Jun 2023 01:46:41 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4b8w-0007lL-1d; Thu, 01 Jun 2023 01:46:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=CEvlmSdqRQIjC1c+T4aADT4lU3Cqok/NTKCyFXd0iSU=; b=m6TzGx+dxabJbx92V11A 6deZ6ZBpRUeOfCd8Kt8bYFRE0cDXh+A1iFpRIuCilwYKneMUya4jwtqz6r/YbUIiV2vIIOnjIyBQZ FfMgZ2feBVAz9zDu+CI4FLdDA4cTczGqHALzfhEAygBApoDOPvfFgIROzNbuqAB1LfHzBZNYGV3vM UY+B5+LEWlUo0zRjxwKqmwijsmyCmZkvyjUcfhU2/eXanRi9UW8VkuwVeAq2w3/VpDZ+e1zow7WAy glnSM7yYJMFxSUt2/3kVpMrQXmOpedidXRctvvq5Cihv4DDJN0NMaN5tHEYI3WpWa1lKIrI7loWia TagCO4urqqAGbw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4b8t-0004e2-48; Thu, 01 Jun 2023 01:46:37 -0400 In-Reply-To: <88498EC5-0870-45ED-802D-85286FB2E9FC@gmail.com> (message from Yuan Fu on Wed, 31 May 2023 13:48:56 -0700) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:306477 Archived-At: > From: Yuan Fu > Date: Wed, 31 May 2023 13:48:56 -0700 > Cc: Stefan Monnier , > 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.