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: Fri, 2 Jun 2023 00:44:15 -0700 Message-ID: References: <20F07C52-6B39-4B24-8433-82E2226EADA6@gmail.com> <83zg5mf62s.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) 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="35833"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , emacs-devel , Mickey Petersen , Theodor Thornhill , dgutov@yandex.ru To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jun 02 09:45:23 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 1q4zTP-00096z-Kz for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Jun 2023 09:45:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4zSa-0005e4-Rg; Fri, 02 Jun 2023 03:44:32 -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 1q4zSZ-0005dr-Kt for emacs-devel@gnu.org; Fri, 02 Jun 2023 03:44:31 -0400 Original-Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4zSX-00012q-Pd; Fri, 02 Jun 2023 03:44:31 -0400 Original-Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64d44b198baso1427255b3a.0; Fri, 02 Jun 2023 00:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685691868; x=1688283868; 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=mTVKMRc6NZXOrafbkzk/a/Umeh8JqpmQ95aX5iU+lvI=; b=B/1UTBqSq2/7qt1nMZxjGXi9MXy489XEQwRKixp+ZlJfDq+Osgi6dY3Ns2DPbF3/BM V8DcdFgPYUUDdk8xTAfnNgKTwMCMFgLXH6NRaIPSbFrhcQfoleqKT8tU54shkFzuiojA e5+6at0Lb3z2w8OWyhyUG1cDv3q+CQ/XKrWtGRKDzJ/xk53yRxevZOKBTvwszJOHM1aB VX1CRH+nMwVDl79+XmlGF693aiU4pg9UvwoKLC1Pngq1vLdITsvG6NI5rf4xZQaD3etJ cMWZYsXoU1YRqOVXxcjJW0XIrc4/zgupA0zKjWxDMQe8AOD699mOhuT0fKH+7by9jUAj xdKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685691868; x=1688283868; 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=mTVKMRc6NZXOrafbkzk/a/Umeh8JqpmQ95aX5iU+lvI=; b=C8wSAmzZP9hiJcFXNbxUs5DJQt9+zM22h0EcQjBw9eesyBzkfYJuGIGm/GqiUBdRLx zJRluzSeWoKOfx5EzuycQs5YXJwozoZJbwwqW0Nplw5dFCvbMjC1bfwHAFUC3Vv5AZBu SVBEXeWeqau8q10OEWOzYdHfeVISkHyTtAD3V6FjXRpML0BNj3X+nY+OMSYZVytxXpDz Tj31f/CKEYUEBkHf66RojWkb7TZ9gZazmyq0H2TvA393/8onNsMbzO8yuR6YOQCh31zI VZkXIQpn2rNS3CL0kSE0yBCHs3Ruvtxxhw5VEM1zrN9a+zylWlYLJINKaeJGLyO8wM/I ksDw== X-Gm-Message-State: AC+VfDzF8VIdXWMWzvvrgFMt++szEca2lYaBomGBf7RR5iGjxzL5sZOU b9HIYbCouISQY98QEaxIpos= X-Google-Smtp-Source: ACHHUZ5H8B7iTyllRN+l1CTmoel0SRAtGVIv71AxHchZBj85IKQ8TG9ywTujNOWJ0k1Gn4sEKUjHzw== X-Received: by 2002:a05:6a20:12c1:b0:100:c3fe:a653 with SMTP id v1-20020a056a2012c100b00100c3fea653mr4722691pzg.29.1685691867502; Fri, 02 Jun 2023 00:44:27 -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 c2-20020aa78802000000b0063d46ec5777sm423134pfo.158.2023.06.02.00.44.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2023 00:44:27 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3731.600.7) Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=casouri@gmail.com; helo=mail-pf1-x42a.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:306545 Archived-At: > On May 31, 2023, at 9:06 PM, Stefan Monnier = wrote: >=20 >>> I don't see this as a big problem, actually (there are already = several >>> mechanisms that can do that). The question of how "user enables >>> xxx-ts-mode" is probably harder. >> Couldn=E2=80=99t they use major-mode-remap-alist? >=20 > Yes, that's one way. With its pros and cons. What do you consider it=E2=80=99s cons? To me it=E2=80=99s more-or-less = just a nicer auto-mode-alist without needing to fiddle with regular = expression. >=20 >> For sure, those that aren=E2=80=99t sharable should go into the = not-shared >> hooks. I=E2=80=99m mainly saying that there should be a shared hook, = so users >> _can_ share some of the configs. >=20 > Ideally, I agree, tho it's not terribly hard for the user to share = code > between hooks, so it's not absolutely indispensable. Right, a nice-to-have. >=20 >>> Most users use only one of the alternatives, tho, so it's usually = not >>> a big problem (other than introducing incompatibilities when Emacs's >>> defaults change from one alternative to another). >>=20 >> Keep in mind that when people try out tree-sitter modes, they are = unlikely >> to just throw away their config for the old mode; also since = tree-sitter and >> grammars aren=E2=80=99t the easiest to install, people working on = multiple machines >> probably want both tree-sitter and no-tree-sitter modes configured = and ready >> to go. So I think we=E2=80=99ll see a lot of people having config for = both modes (me >> included). >=20 > Good point. >=20 >> And in general, any configuration that takes a major-mode symbol as >> the key. There are quite a few of them in Emacs. I think this is >> a big motivation for having multiple inheritance for derived-mode-p, >> and sharing a base mode. >=20 > I think the case for support of multiple inheritance in = `derived-mode-p` > is fairly compelling, indeed. >=20 >> I agree that we don=E2=80=99t want multiple-inheritance for = activation code. >> Also, as Juri pointed out, we can encapsulate code into functions and >> call functions in major mode body. Multiple-inheritance for hooks = and >> maps has the potential disadvantage of being confusing. Right now >> it=E2=80=99s clear what hooks are run when a major mode turns on, but = with >> multiple-inheritance it may not be. >=20 > Normally, `define-derived-mode makes sure that the docstring states = it. Makes sense, normally there won=E2=80=99t be more than 3 levels of = inheritance anyway so it should be fine. >=20 >> How do you setup multiple keymap parents? I thought a keymap can only = have one parent? >=20 > The single parent can be a composite map (i.e. using = `make-composed-keymap`). But IIUC that creates a new map instead of pointing to the parent maps, = so any change in the parent map are not reflected in the child map, = which is kind of the point of inheriting maps. >=20 >> Here=E2=80=99s another wild idea: we keep single-inheritance for >> define-derived-mode; major modes for the same language inherits from >> the same base mode; add a feature where xxx-base-mode is = automatically >> defined when someone defines a major mode with xxx-base-mode as >> parent, so we don=E2=80=99t need to pre-define base-modes for every = possible >> language; >=20 > Sounds hackish. E.g. what would the `xxx-mode` docstring say about > which hooks are run? xxx-base-mode-hook, and=E2=80=A6uh, right, we need to specify which mode = xxx-base-mode inherits, hmm. Yuan=