From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Extending define-derived-mode Date: Fri, 02 Jun 2023 12:46:07 -0400 Message-ID: References: <20F07C52-6B39-4B24-8433-82E2226EADA6@gmail.com> <83zg5mf62s.fsf@gnu.org> Mime-Version: 1.0 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="26186"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , emacs-devel , Mickey Petersen , Theodor Thornhill , dgutov@yandex.ru To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jun 02 18:47:25 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 1q57vw-0006a2-O5 for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Jun 2023 18:47:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q57v3-00019Z-Pg; Fri, 02 Jun 2023 12:46:29 -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 1q57v0-00019H-7t for emacs-devel@gnu.org; Fri, 02 Jun 2023 12:46:26 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q57ux-0008VJ-4M; Fri, 02 Jun 2023 12:46:25 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id F34B6100097; Fri, 2 Jun 2023 12:46:09 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 775A310001C; Fri, 2 Jun 2023 12:46:08 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1685724368; bh=yY78lhd9RrVONFg6cIRAD5s8579mfJckSTwc9+eyg+g=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=VL6/dNocV1FQA78Jvajf1XTUzExzNIipiNd6kOSPwlY+Lqfcxjhxg3u0KTe2eG36f AzS84rjZ2xA4wdcuinQPMtidb0tl0H4dV/SbXUklHz7Qs39wFPl++Oh0XQ5PdaT+04 A7+765nKfauYh9XLj303e6x79bjnvRdcs/HUGrjqDY1QykbdIJijk48XkyDDjq8PwJ h/RO3faGsNzpTTKnd5td8uZ0C0hGa9ig38FgFzzttSwNJueUpSp+erSEXkRIFS3Uv9 ziTtiMBOiEk5o7hHLiCL+ulDiYZVE9Nmu8LScJ35PGTk1wGAIJpvT6IX0CU46Zz64I EwNqPBaTHeAng== Original-Received: from alfajor (unknown [184.148.243.248]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 643DB1201DD; Fri, 2 Jun 2023 12:46:08 -0400 (EDT) In-Reply-To: (Yuan Fu's message of "Fri, 2 Jun 2023 00:44:15 -0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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:306562 Archived-At: >>>> 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? >> 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 j= ust a nicer > auto-mode-alist without needing to fiddle with regular expression. It's "one mode at a time", whereas I'd expect some users might be looking for a more "global" setting such as one that causes TS modes to be used whenever possible (i.e. when there's a TS-using mode and the corresponding grammar is installed). >>> How do you setup multiple keymap parents? I thought a keymap can only h= ave one parent? >> The single parent can be a composite map (i.e. using `make-composed-keym= ap`). > > 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. It creates a new map but it doesn't *copy* anything, it just keeps references to the maps included in the composite map, so changes to the parent maps *are* reflected. IOW, we can implement XEmacs's multiple inheritance with (defun set-keymap-parents (keymap parents) (set-keymap-parent keymap ;; Aka (cons 'keymap parents). (make-composed-map parents))) (defun keymap-parents (keymap) (let ((parent (keymap-parent keymap))) (if (and (eq 'keymap (car-safe parent)) (proper-list-p parent) (seq-every-p #'keymapp (cdr parent))) (cdr parent) (if parent (list parent))))) >>> 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 pos= sible >>> language; >> Sounds hackish. E.g. what would the `xxx-mode` docstring say about >> which hooks are run? > xxx-base-mode-hook, But IIUC you're suggesting that this hook would only exist "when someone defines a major mode with xxx-base-mode as parent", so it's dynamic/conditional. Stefan