From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Extending define-derived-mode Date: Wed, 31 May 2023 13:48:56 -0700 Message-ID: <88498EC5-0870-45ED-802D-85286FB2E9FC@gmail.com> References: <20F07C52-6B39-4B24-8433-82E2226EADA6@gmail.com> <83zg5mf62s.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.500.231\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7889"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , emacs-devel@gnu.org, mickey@masteringemacs.org, theo@thornhill.no, dgutov@yandex.ru To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 31 22:50: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 1q4Slo-0001lN-3f for ged-emacs-devel@m.gmane-mx.org; Wed, 31 May 2023 22:50:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4Skr-0006fi-LE; Wed, 31 May 2023 16:49:13 -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 1q4Skq-0006Zx-2B for emacs-devel@gnu.org; Wed, 31 May 2023 16:49:12 -0400 Original-Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4Sko-0005qs-D6; Wed, 31 May 2023 16:49:11 -0400 Original-Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6af86627460so173171a34.1; Wed, 31 May 2023 13:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685566148; x=1688158148; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xjGY1zCG8p9TL2gd6q1Dl8Aa/tItPjLWFd/cMW2TE84=; b=eYq1TKh2mqTc4OJJybbIvsfIwyRkv75s6QOLnKy4WQX+RCBXMyClbhN8t/5QuCObpp O1rwLRHTMA9nn9t0nPZts+tJU2C+qGLQ9lkI1+MtMvdPZw87M0vk6B6wwCGBY6rJRR6z iQDPMJYGYy0wA80VMp2KetPyHqkJ3SGHRA+TMyp45Y+WVKHqb4g/md/FCXwC2KkWLfqM t26c+dcspZXjpP1bihnla/OU6b/q9HRIDMH2HmxDZd2XHZMh75qw7ebevJhhdM5ylp8X 21V2xZ3lkGYCy/x6CdrCqIRAA0EMCYSNMZSlgDlcqLONaoN2Zb/CtOViyVGu3PyoMoW5 CDcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685566148; x=1688158148; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xjGY1zCG8p9TL2gd6q1Dl8Aa/tItPjLWFd/cMW2TE84=; b=aNgoAGEZz9CM1er2z0dmaSUBZ8cxxpKKwjXK4dJaVRPPXhqqDpvWMknbtf0edLi+Zq lrYG8hK4KMmJEXEL6drceT6mNhnAqCRkVs7SkLRO89IBzu6E1Bbbu+ZUB+bPVdB7lYYK BbkdZZzXP0HdJy2EGA6QbY/eFras1ATGWiIg4JhsD15l3vLZ7hak7TJPOqOf7fxs9kpt D4jL3d2o4zz7xWuMqryo1CRBsfi8f+IVdLtVn4KnsD6Uu3TJCfkQMbBluJ22Y/URN5XH Nu9l5ZlZKXcFFr1d2fYpaGze1YXvtqMN5elbq+T7tY2NI5fcGb+SWfEDgQRcy40dOj+G aliw== X-Gm-Message-State: AC+VfDzxHkVHa6rBqUR4yUL3HpF106npdZ57XWYq7D+y826c1CoLJWBs r9OLV/VCAHh0L2YfYDLaVmAlTDjNN40= X-Google-Smtp-Source: ACHHUZ7ligTXEgrqOvLP/8YMqIZUq1t68BOX8XXhx7diHbndpnCByJONzSmgMR9Eg5F9qkVgjzGR9g== X-Received: by 2002:a9d:7cd2:0:b0:6b0:c62e:7941 with SMTP id r18-20020a9d7cd2000000b006b0c62e7941mr3375414otn.17.1685566148263; Wed, 31 May 2023 13:49:08 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id p18-20020aa78612000000b0064d3bccca8bsm3744519pfn.9.2023.05.31.13.49.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2023 13:49:07 -0700 (PDT) In-Reply-To: <83zg5mf62s.fsf@gnu.org> X-Mailer: Apple Mail (2.3731.500.231) Received-SPF: pass client-ip=2607:f8b0:4864:20::334; envelope-from=casouri@gmail.com; helo=mail-ot1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:306464 Archived-At: >=20 >> 2. Inheritance: >>=20 >> 2.1 For xxx-mode and xxx-ts-mode, there should be shared hook. More >> generally, we want to be able to have a shared hook for similar >> modes (same language, similar language, etc). >>=20 >> 2.2 For xxx-mode and xxx-ts-mode, they should be able to share some >> setup, and diverge on some other. >>=20 >> 2.3 Right now we have a little inconsistency regarding hook >> inheritance. js-json-mode inherits from js-mode, json-ts-mode >> inherits from js-ts-mode. So there isn=E2=80=99t a shared hook = that runs >> in both js-json-mode and json-ts-mode. >>=20 >> More generally, if there is a language X and a derived language Y, >> and we have x-mode, x-ts-mode, y-mode, y-ts-mode, how should >> inheritance of code and hooks works among them? y-mode probably >> wants to inherit from x-mode, and y-ts-mode probably wants to >> inherit hook (but not necessarily code [1]) from x-ts-mode. >=20 > 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. >=20 > 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=E2=80=99t 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=E2=80=99m gonna run = into? Couldn=E2=80=99t you just use the base-mode=E2=80=99s keymap? Yuan=