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: Mon, 5 Jun 2023 00:39:41 -0700 Message-ID: <42DEA948-61CF-48CC-B27E-197E603CA57E@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.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="3856"; 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 Mon Jun 05 09:41:30 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 1q64qH-0000nT-Qn for ged-emacs-devel@m.gmane-mx.org; Mon, 05 Jun 2023 09:41:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q64pO-0007jq-Ip; Mon, 05 Jun 2023 03:40:34 -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 1q64p4-0007in-VF for emacs-devel@gnu.org; Mon, 05 Jun 2023 03:40:20 -0400 Original-Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q64or-0005H6-DT; Mon, 05 Jun 2023 03:40:14 -0400 Original-Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-39a505b901dso3954378b6e.0; Mon, 05 Jun 2023 00:39:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685950793; x=1688542793; 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=Y/b3rUhSq1ExTFCmknpmsIHRp6MdoATJuqAvlQPBy34=; b=B4/3g9gv4V1cch2L0fxawPlqaD1maV+4zHVs8ODVBBSKbGxiUvt34oaCNYeDw3viNl LvoqCMtTBRNaCw2ujcQKWshJi/5CQUubly/PpLu/mrNzTUfTICmNYnmJDKvd2S11rGbE 0TRvnKTYv2H1ZLPjaQtCJ9JXSRxtRs+u3CUI39mh6ncoQWnTRlEVbRLvQv0uz0LpFe98 j8gcE3845lRzpxMZPYnUz2mE+WxinXGaPeyxbL6Xr2yhe1Q0yxgfNSF+kHkMSDTF/H9B GuM4GSfxAikhmJZNlC3Urdlg9Bv7QT3O/xn+106OwIKPREYHMqAbZpVxacVlbq19Y5px 3Jng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685950793; x=1688542793; 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=Y/b3rUhSq1ExTFCmknpmsIHRp6MdoATJuqAvlQPBy34=; b=RkfW1mfeZkl/YSC4/LYzD13VWfX+/hAsFC8N4DR+faNkYbxCwgcaDAvEfce7DDJ1bt BW92BH1jnxqXFtkb4CjGE0k7nJmEoyg7H6eByGzNcyzyptRpHFuv02NfYDWZoKCLA6PF 70Ji3KazCJCFpQyF/TcjSF2Gd5iPCwIdrGn0xz5DYc+FNCO3ygnBuK54EuTp4X8kgj8I 1kEbJxfw1QHd5SlxFKo+jOcVG2rSeBPgIp/rE9Mu2lv5xmVOwlVsYOSKm18DcVv6JNWf 1/w6XHH8mXa53/3M4PsNx/aAFk6uNHoNdh+FCQ/dhwllrmh2x8Ax23EsxO9scCLV8xkn nOQA== X-Gm-Message-State: AC+VfDzXE/U0u+T9gMboppEcz3e9EoJE6rVbAw/3SPGZJkMIWCkaWGXC urq4IO5cGteAtvKRXh7Nn8I= X-Google-Smtp-Source: ACHHUZ7H26Ed9xTEDRFef7/0tP8VAyxCtYj0R3cFT1jhAI2ZONAKm1e/Dw5gaDLlW22ocPvRT1qOKA== X-Received: by 2002:a05:6808:2c9:b0:39a:531b:db6c with SMTP id a9-20020a05680802c900b0039a531bdb6cmr7426844oid.47.1685950793326; Mon, 05 Jun 2023 00:39:53 -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 c15-20020a170902d48f00b001ab12545508sm5913471plg.67.2023.06.05.00.39.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Jun 2023 00:39:52 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3731.600.7) Received-SPF: pass client-ip=2607:f8b0:4864:20::235; envelope-from=casouri@gmail.com; helo=mail-oi1-x235.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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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:306636 Archived-At: > On Jun 2, 2023, at 9:46 AM, 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? >>> 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 > 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). >=20 >>>> How do you setup multiple keymap parents? I thought a keymap can = only have one parent? >>> The single parent can be a composite map (i.e. using = `make-composed-keymap`). >>=20 >> 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 > 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. >=20 > IOW, we can implement XEmacs's multiple inheritance with >=20 > (defun set-keymap-parents (keymap parents) > (set-keymap-parent keymap > ;; Aka (cons 'keymap parents). > (make-composed-map parents))) >=20 > (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))))) Oh great! I didn=E2=80=99t know that. >=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; >>> Sounds hackish. E.g. what would the `xxx-mode` docstring say about >>> which hooks are run? >> xxx-base-mode-hook, >=20 > 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. IIUC you can add functions to a hook regardless whether it=E2=80=99s = defined or not, so it should be fine? BTW, I want to clarify one thing: how are we feeling about base modes? = Are they fine? Are they staying? Yuan=